Skip to content

Commit 57e3b70

Browse files
committed
Add test for anchor reuse
The spec calls this a "reuse" of an anchor https://yaml.org/spec/1.2.2/#71-alias-nodes
1 parent 0c11ddc commit 57e3b70

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/psych/test_hash.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ def test_ref_append
112112
assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
113113
end
114114

115+
def test_anchor_reuse
116+
hash = Psych.unsafe_load(<<~eoyml)
117+
---
118+
foo: &foo
119+
hello: world
120+
bar: *foo
121+
eoyml
122+
assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
123+
assert_same(hash.fetch("foo"), hash.fetch("bar"))
124+
end
125+
115126
def test_recursive_hash
116127
h = { }
117128
h["recursive_reference"] = h

0 commit comments

Comments
 (0)