summaryrefslogtreecommitdiff
path: root/test/psych/test_merge_keys.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-02-06 17:13:27 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-06 17:13:27 -0800
commit8c60e9fa2a5e4932d8762469000b232d57c696b5 (patch)
tree29ba5ec4de61ecb966f68e11146de6cb6ca266f3 /test/psych/test_merge_keys.rb
parente008a513f5e33031c5e9341cb4da09a225693840 (diff)
downloadpsych-8c60e9fa2a5e4932d8762469000b232d57c696b5.tar.gz
merging from ruby
Diffstat (limited to 'test/psych/test_merge_keys.rb')
-rw-r--r--test/psych/test_merge_keys.rb72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/psych/test_merge_keys.rb b/test/psych/test_merge_keys.rb
new file mode 100644
index 0000000..fef8892
--- /dev/null
+++ b/test/psych/test_merge_keys.rb
@@ -0,0 +1,72 @@
+require_relative 'helper'
+
+module Psych
+ class TestMergeKeys < TestCase
+ # [ruby-core:34679]
+ def test_merge_key
+ yaml = <<-eoyml
+foo: &foo
+ hello: world
+bar:
+ << : *foo
+ baz: boo
+ eoyml
+
+ hash = {
+ "foo" => { "hello" => "world"},
+ "bar" => { "hello" => "world", "baz" => "boo" } }
+ assert_equal hash, Psych.load(yaml)
+ end
+
+ def test_multiple_maps
+ yaml = <<-eoyaml
+---
+- &CENTER { x: 1, y: 2 }
+- &LEFT { x: 0, y: 2 }
+- &BIG { r: 10 }
+- &SMALL { r: 1 }
+
+# All the following maps are equal:
+
+- # Merge multiple maps
+ << : [ *CENTER, *BIG ]
+ label: center/big
+ eoyaml
+
+ hash = {
+ 'x' => 1,
+ 'y' => 2,
+ 'r' => 10,
+ 'label' => 'center/big'
+ }
+
+ assert_equal hash, Psych.load(yaml)[4]
+ end
+
+ def test_override
+ yaml = <<-eoyaml
+---
+- &CENTER { x: 1, y: 2 }
+- &LEFT { x: 0, y: 2 }
+- &BIG { r: 10 }
+- &SMALL { r: 1 }
+
+# All the following maps are equal:
+
+- # Override
+ << : [ *BIG, *LEFT, *SMALL ]
+ x: 1
+ label: center/big
+ eoyaml
+
+ hash = {
+ 'x' => 1,
+ 'y' => 2,
+ 'r' => 10,
+ 'label' => 'center/big'
+ }
+
+ assert_equal hash, Psych.load(yaml)[4]
+ end
+ end
+end