From ea1efdf32faf2cf35f6db1ec426c277bfa8f0461 Mon Sep 17 00:00:00 2001 From: Alexander Momchilov Date: Fri, 22 Jul 2022 16:09:13 -0400 Subject: [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 --- test/psych/test_hash.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb index 0efa21160f..6c45da53b7 100644 --- a/test/psych/test_hash.rb +++ b/test/psych/test_hash.rb @@ -112,6 +112,17 @@ eoyml assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash) 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 h = { } h["recursive_reference"] = h -- cgit v1.2.3