mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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/trunk@30630 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5b1c06c74b
commit
6e5aa6311a
3 changed files with 69 additions and 2 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
Sat Jan 22 11:49:55 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* 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
|
||||||
|
|
||||||
Sat Jan 22 11:33:04 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
Sat Jan 22 11:33:04 2011 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
* ext/psych/lib/psych/visitors/to_ruby.rb: merge keys are actually
|
* ext/psych/lib/psych/visitors/to_ruby.rb: merge keys are actually
|
||||||
|
|
|
@ -187,8 +187,17 @@ module Psych
|
||||||
o.children.each_slice(2) { |k,v|
|
o.children.each_slice(2) { |k,v|
|
||||||
key = accept(k)
|
key = accept(k)
|
||||||
|
|
||||||
if key == '<<' && Nodes::Alias === v
|
if key == '<<'
|
||||||
hash.merge! accept(v)
|
case v
|
||||||
|
when Nodes::Alias
|
||||||
|
hash.merge! accept(v)
|
||||||
|
when Nodes::Sequence
|
||||||
|
accept(v).reverse_each do |value|
|
||||||
|
hash.merge! value
|
||||||
|
end
|
||||||
|
else
|
||||||
|
hash[key] = accept(v)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
hash[key] = accept(v)
|
hash[key] = accept(v)
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,5 +17,56 @@ bar:
|
||||||
"bar" => { "hello" => "world", "baz" => "boo" } }
|
"bar" => { "hello" => "world", "baz" => "boo" } }
|
||||||
assert_equal hash, Psych.load(yaml)
|
assert_equal hash, Psych.load(yaml)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue