mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/psych] Don't hardcode expected alias names
https://github.com/ruby/psych/commit/b9ab19094f
This commit is contained in:
parent
0b7cfdca09
commit
71f89c2874
3 changed files with 28 additions and 22 deletions
|
@ -57,17 +57,20 @@ module Psych
|
|||
assert_cycle(@list)
|
||||
end
|
||||
|
||||
def test_recursive_array
|
||||
@list << @list
|
||||
|
||||
loaded = Psych.load(Psych.dump(@list), aliases: true)
|
||||
|
||||
assert_same loaded, loaded.last
|
||||
end
|
||||
|
||||
def test_recursive_array_uses_alias
|
||||
@list << @list
|
||||
|
||||
expected = <<~eoyaml
|
||||
--- &1
|
||||
- :a: b
|
||||
- foo
|
||||
- *1
|
||||
eoyaml
|
||||
|
||||
assert_equal expected, Psych.dump(@list)
|
||||
assert_raise(BadAlias) do
|
||||
Psych.load(Psych.dump(@list), aliases: false)
|
||||
end
|
||||
end
|
||||
|
||||
def test_cycle
|
||||
|
|
|
@ -112,16 +112,22 @@ eoyml
|
|||
assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
|
||||
end
|
||||
|
||||
def test_recursive_hash
|
||||
h = { }
|
||||
h["recursive_reference"] = h
|
||||
|
||||
loaded = Psych.load(Psych.dump(h), aliases: true)
|
||||
|
||||
assert_same loaded, loaded.fetch("recursive_reference")
|
||||
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))
|
||||
assert_raise(BadAlias) do
|
||||
Psych.load(Psych.dump(h), aliases: false)
|
||||
end
|
||||
end
|
||||
|
||||
def test_key_deduplication
|
||||
|
|
|
@ -36,22 +36,19 @@ module Psych
|
|||
def test_cyclic_references
|
||||
foo = Foo.new(nil)
|
||||
foo.parent = foo
|
||||
loaded = Psych.unsafe_load Psych.dump foo
|
||||
loaded = Psych.load(Psych.dump(foo), permitted_classes: [Foo], aliases: true)
|
||||
|
||||
assert_instance_of(Foo, loaded)
|
||||
assert_equal loaded, loaded.parent
|
||||
assert_same 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)
|
||||
assert_raise(BadAlias) do
|
||||
Psych.load(Psych.dump(foo), permitted_classes: [Foo], aliases: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue