1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/psych] Add test for anchor reuse

The spec calls this a "reuse" of an anchor
https://yaml.org/spec/1.2.2/#71-alias-nodes

https://github.com/ruby/psych/commit/57e3b70a56
This commit is contained in:
Alexander Momchilov 2022-07-22 16:09:13 -04:00 committed by git
parent 54219ae8c4
commit ea1efdf32f

View file

@ -112,6 +112,17 @@ eoyml
assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash) assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
end end
def test_anchor_reuse
hash = Psych.unsafe_load(<<~eoyml)
---
foo: &foo
hello: world
bar: *foo
eoyml
assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
assert_same(hash.fetch("foo"), hash.fetch("bar"))
end
def test_recursive_hash def test_recursive_hash
h = { } h = { }
h["recursive_reference"] = h h["recursive_reference"] = h