diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-05-31 03:46:21 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-05-31 03:46:21 +0000 |
commit | dd0f22f9cbf592d3ae17b03708ab66b4be7e6640 (patch) | |
tree | 1ec4cb95489c40d8dd4794a3598cc221ea6a6ed3 /test | |
parent | e9faf5ffabbb5addd1ac298fe8cdcb0e068ea59d (diff) |
merges r30629 and r30630 from trunk into ruby_1_9_2.
--
* ext/psych/lib/psych/visitors/to_ruby.rb: merge keys are actually
part of YAML 1.1, so they should be supported. Remove warning and
merge keys to parent. [ruby-core:34679]
* test/psych/test_merge_keys.rb: test for merge keys
--
* ext/psych/lib/psych/visitors/to_ruby.rb: fixing merge key support
when multiple merge keys are specified.
* test/psych/test_merge_keys.rb: tests for multi-merge key support
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@31856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/psych/test_merge_keys.rb | 72 |
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 0000000000..fef8892727 --- /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 |