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

[ruby/psych] Test that recursive refs dump as aliases

https://github.com/ruby/psych/commit/d9f7289190
This commit is contained in:
Alexander Momchilov 2022-07-22 16:45:03 -04:00 committed by git
parent c851bced39
commit 0b7cfdca09
3 changed files with 37 additions and 0 deletions

View file

@ -57,6 +57,19 @@ module Psych
assert_cycle(@list)
end
def test_recursive_array_uses_alias
@list << @list
expected = <<~eoyaml
--- &1
- :a: b
- foo
- *1
eoyaml
assert_equal expected, Psych.dump(@list)
end
def test_cycle
assert_cycle(@list)
end

View file

@ -112,6 +112,18 @@ eoyml
assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
end
def test_recursive_hash_uses_alias
h = { }
h["recursive_reference"] = h
expected = <<~eoyaml
--- &1
recursive_reference: *1
eoyaml
assert_equal(expected, Psych.dump(h))
end
def test_key_deduplication
unless String.method_defined?(:-@) && (-("a" * 20)).equal?((-("a" * 20)))
pend "This Ruby implementation doesn't support string deduplication"

View file

@ -41,5 +41,17 @@ module Psych
assert_instance_of(Foo, loaded)
assert_equal loaded, loaded.parent
end
def test_cyclic_reference_uses_alias
foo = Foo.new(nil)
foo.parent = foo
expected = <<~eoyaml
--- &1 !ruby/object:Psych::Foo
parent: *1
eoyaml
assert_equal expected, Psych.dump(foo)
end
end
end