Skip to content

Modules 707 #262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 1 addition & 24 deletions lib/puppet/parser/functions/bool2num.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,7 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

# We can have either true or false, or string which resembles boolean ...
unless [FalseClass, TrueClass, String].include?(klass)
raise(Puppet::ParseError, 'bool2num(): Requires either ' +
'boolean or string to work with')
end

if value.is_a?(String)
# We consider all the yes, no, y, n and so on too ...
value = case value
#
# This is how undef looks like in Puppet ...
# We yield 0 (or false if you wish) in this case.
#
when /^$/, '' then false # Empty string will be false ...
when /^(1|t|y|true|yes)$/ then true
when /^(0|f|n|false|no)$/ then false
when /^(undef|undefined)$/ then false # This is not likely to happen ...
else
raise(Puppet::ParseError, 'bool2num(): Unknown type of boolean given')
end
end
value = function_str2bool([arguments[0]])

# We have real boolean values as well ...
result = value ? 1 : 0
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/capitalize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'capitalize(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/chomp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'chomp(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/chop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'chop(): Requires either an ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/downcase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'downcase(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/empty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, Hash, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String)
raise(Puppet::ParseError, 'empty(): Requires either ' +
'array, hash or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/fqdn_rotate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class
require 'digest/md5'

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'fqdn_rotate(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/lstrip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'lstrip(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/reverse.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'reverse(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/rstrip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'rstrip(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/shuffle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'shuffle(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/strip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'strip(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/swapcase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'swapcase(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/unique.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'unique(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/upcase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'upcase(): Requires either ' +
'array or string to work with')
end
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/uriescape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ module Puppet::Parser::Functions
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

unless [Array, String].include?(klass)
unless value.is_a?(Array) || value.is_a?(String)
raise(Puppet::ParseError, 'uriescape(): Requires either ' +
'array or string to work with')
end
Expand Down
28 changes: 1 addition & 27 deletions lib/puppet/parser/functions/zip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,7 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, 'zip(): Requires array to work with')
end

flatten = arguments[2] if arguments[2]

if flatten
klass = flatten.class

# We can have either true or false, or string which resembles boolean ...
unless [FalseClass, TrueClass, String].include?(klass)
raise(Puppet::ParseError, 'zip(): Requires either ' +
'boolean or string to work with')
end

if flatten.is_a?(String)
# We consider all the yes, no, y, n and so on too ...
flatten = case flatten
#
# This is how undef looks like in Puppet ...
# We yield false in this case.
#
when /^$/, '' then false # Empty string will be false ...
when /^(1|t|y|true|yes)$/ then true
when /^(0|f|n|false|no)$/ then false
when /^(undef|undefined)$/ then false # This is not likely to happen ...
else
raise(Puppet::ParseError, 'zip(): Unknown type of boolean given')
end
end
end
flatten = function_str2bool([arguments[2]]) if arguments[2]

result = a.zip(b)
result = flatten ? result.flatten : result
Expand Down
18 changes: 16 additions & 2 deletions spec/functions/bool2num_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,22 @@
expect(result).to(eq(1))
end

it "should convert false to 0" do
result = scope.function_bool2num([false])
it "should convert 'true' to 1" do
result = scope.function_bool2num(['true'])
result.should(eq(1))
end

it "should convert 'false' to 0" do
result = scope.function_bool2num(['false'])
expect(result).to(eq(0))
end

it "should accept objects which extend String" do
class AlsoString < String
end

value = AlsoString.new('true')
result = scope.function_bool2num([value])
result.should(eq(1))
end
end
9 changes: 9 additions & 0 deletions spec/functions/capitalize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@
result = scope.function_capitalize(["abc"])
expect(result).to(eq("Abc"))
end

it "should accept objects which extend String" do
class AlsoString < String
end

value = AlsoString.new('abc')
result = scope.function_capitalize([value])
result.should(eq('Abc'))
end
end
9 changes: 9 additions & 0 deletions spec/functions/chomp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@
result = scope.function_chomp(["abc\n"])
expect(result).to(eq("abc"))
end

it "should accept objects which extend String" do
class AlsoString < String
end

value = AlsoString.new("abc\n")
result = scope.function_chomp([value])
result.should(eq("abc"))
end
end
9 changes: 9 additions & 0 deletions spec/functions/chop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@
result = scope.function_chop(["asdf\n"])
expect(result).to(eq("asdf"))
end

it "should accept objects which extend String" do
class AlsoString < String
end

value = AlsoString.new("abc\n")
result = scope.function_chop([value])
result.should(eq('abc'))
end
end
9 changes: 9 additions & 0 deletions spec/functions/downcase_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@
result = scope.function_downcase(["asdf asdf"])
expect(result).to(eq("asdf asdf"))
end

it "should accept objects which extend String" do
class AlsoString < String
end

value = AlsoString.new("ASFD")
result = scope.function_downcase([value])
result.should(eq('asfd'))
end
end
9 changes: 9 additions & 0 deletions spec/functions/empty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@
result = scope.function_empty(['asdf'])
expect(result).to(eq(false))
end

it "should accept objects which extend String" do
class AlsoString < String
end

value = AlsoString.new()
result = scope.function_empty([value])
result.should(eq(true))
end
end
10 changes: 10 additions & 0 deletions spec/functions/fqdn_rotate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,14 @@
val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"])
expect(val1).not_to eql(val2)
end

it "should accept objects which extend String" do
class AlsoString < String
end

scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1")
value = AlsoString.new("asdf")
result = scope.function_fqdn_rotate([value])
result.size.should(eq(4))
end
end
9 changes: 9 additions & 0 deletions spec/functions/lstrip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@
result = scope.function_lstrip([" asdf"])
expect(result).to(eq('asdf'))
end

it "should accept objects which extend String" do
class AlsoString < String
end

value = AlsoString.new(" asdf")
result = scope.function_lstrip([value])
result.should(eq("asdf"))
end
end
9 changes: 9 additions & 0 deletions spec/functions/reverse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@
result = scope.function_reverse(["asdfghijkl"])
expect(result).to(eq('lkjihgfdsa'))
end

it "should accept objects which extend String" do
class AlsoString < String
end

value = AlsoString.new('asdfghjkl')
result = scope.function_reverse([value])
result.should(eq('lkjhgfdsa'))
end
end
9 changes: 9 additions & 0 deletions spec/functions/rstrip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@
result = scope.function_rstrip([["a ","b ", "c "]])
expect(result).to(eq(['a','b','c']))
end

it "should accept objects which extend String" do
class AlsoString < String
end

value = AlsoString.new('asdf ')
result = scope.function_rstrip([value])
result.should(eq('asdf'))
end
end
9 changes: 9 additions & 0 deletions spec/functions/shuffle_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,13 @@
result = scope.function_shuffle(["adfs"])
expect(result.split("").sort.join("")).to(eq("adfs"))
end

it "should accept objects which extend String" do
class AlsoString < String
end

value = AlsoString.new('asdf')
result = scope.function_shuffle([value])
result.size.should(eq(4))
end
end
Loading