diff options
author | Ashley Penney <ashley.penney@puppetlabs.com> | 2014-03-11 09:31:23 -0700 |
---|---|---|
committer | Ashley Penney <ashley.penney@puppetlabs.com> | 2014-03-11 09:31:23 -0700 |
commit | e467d8f0847bb85fc8b0789d2eb44dcca862c5d7 (patch) | |
tree | 01831aa1dfe61389429566c0758d0a9267c20f33 /spec | |
parent | 6a89e1cee4be5c413b354f8facd677ba2fe637d7 (diff) | |
parent | c12e9afc97f4356bc20554d32861889680c5fdc1 (diff) |
Merge pull request #220 from mediatemple/fix/master/deep_merge_fix
PUP-1724 Don't modify the paramaters to deep_merge
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/puppet/parser/functions/deep_merge_spec.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/unit/puppet/parser/functions/deep_merge_spec.rb b/spec/unit/puppet/parser/functions/deep_merge_spec.rb index 1d2c183..f134701 100644 --- a/spec/unit/puppet/parser/functions/deep_merge_spec.rb +++ b/spec/unit/puppet/parser/functions/deep_merge_spec.rb @@ -73,5 +73,33 @@ describe Puppet::Parser::Functions.function(:deep_merge) do hash['key1'].should == { 'a' => 1, 'b' => 99 } hash['key2'].should == { 'c' => 3 } end + + it 'should not change the original hashes' do + hash1 = {'one' => { 'two' => 2 } } + hash2 = { 'one' => { 'three' => 3 } } + hash = scope.function_deep_merge([hash1, hash2]) + hash1.should == {'one' => { 'two' => 2 } } + hash2.should == { 'one' => { 'three' => 3 } } + hash['one'].should == { 'two' => 2, 'three' => 3 } + end + + it 'should not change the original hashes 2' do + hash1 = {'one' => { 'two' => [1,2] } } + hash2 = { 'one' => { 'three' => 3 } } + hash = scope.function_deep_merge([hash1, hash2]) + hash1.should == {'one' => { 'two' => [1,2] } } + hash2.should == { 'one' => { 'three' => 3 } } + hash['one'].should == { 'two' => [1,2], 'three' => 3 } + end + + it 'should not change the original hashes 3' do + hash1 = {'one' => { 'two' => [1,2, {'two' => 2} ] } } + hash2 = { 'one' => { 'three' => 3 } } + hash = scope.function_deep_merge([hash1, hash2]) + hash1.should == {'one' => { 'two' => [1,2, {'two' => 2}] } } + hash2.should == { 'one' => { 'three' => 3 } } + hash['one'].should == { 'two' => [1,2, {'two' => 2} ], 'three' => 3 } + hash['one']['two'].should == [1,2, {'two' => 2}] + end end end |