Merge pull request #184 from lmello/fix_bug_20681_delete_undef_values
delete_undef_values function fix bug #20681
This commit is contained in:
commit
7ccf8cf09b
2 changed files with 18 additions and 6 deletions
|
@ -19,15 +19,15 @@ Would return: ['A','',false]
|
|||
"delete_undef_values(): Wrong number of arguments given " +
|
||||
"(#{args.size})") if args.size < 1
|
||||
|
||||
result = args[0]
|
||||
unless args[0].is_a? Array or args[0].is_a? Hash
|
||||
raise(Puppet::ParseError,
|
||||
"delete_undef_values(): expected an array or hash, got #{args[0]} type #{args[0].class} ")
|
||||
end
|
||||
result = args[0].dup
|
||||
if result.is_a?(Hash)
|
||||
result.delete_if {|key, val| val.equal? :undef}
|
||||
elsif result.is_a?(Array)
|
||||
result.delete :undef
|
||||
else
|
||||
raise(Puppet::ParseError,
|
||||
"delete_undef_values(): Wrong argument type #{args[0].class} " +
|
||||
"for first argument")
|
||||
end
|
||||
result
|
||||
end
|
||||
|
|
|
@ -26,4 +26,16 @@ describe "the delete_undef_values function" do
|
|||
result = scope.function_delete_undef_values([{'a'=>'A','b'=>:undef,'c'=>'C','d'=>'undef'}])
|
||||
result.should(eq({'a'=>'A','c'=>'C','d'=>'undef'}))
|
||||
end
|
||||
|
||||
it "should not change origin array passed as argument" do
|
||||
origin_array = ['a',:undef,'c','undef']
|
||||
result = scope.function_delete_undef_values([origin_array])
|
||||
origin_array.should(eq(['a',:undef,'c','undef']))
|
||||
end
|
||||
|
||||
it "should not change origin hash passed as argument" do
|
||||
origin_hash = { 'a' => 1, 'b' => :undef, 'c' => 'undef' }
|
||||
result = scope.function_delete_undef_values([origin_hash])
|
||||
origin_hash.should(eq({ 'a' => 1, 'b' => :undef, 'c' => 'undef' }))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue