summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlexander Momchilov <alexander.momchilov@shopify.com>2022-07-22 16:45:03 -0400
committerAlexander Momchilov <alexander.momchilov@shopify.com>2022-07-22 16:57:54 -0400
commitd9f7289190d424981555dec9f2c019f6a270f205 (patch)
tree98503a87db510bc0139a7dfefb2870485f4c1d54 /test
parent0bc30cb4cb03164fb60cab7f0d2eb27fd6e78193 (diff)
downloadpsych-d9f7289190d424981555dec9f2c019f6a270f205.tar.gz
Test that recursive refs dump as aliases
Diffstat (limited to 'test')
-rw-r--r--test/psych/test_array.rb13
-rw-r--r--test/psych/test_hash.rb12
-rw-r--r--test/psych/test_object.rb12
3 files changed, 37 insertions, 0 deletions
diff --git a/test/psych/test_array.rb b/test/psych/test_array.rb
index 28b76da..a6be0ba 100644
--- a/test/psych/test_array.rb
+++ b/test/psych/test_array.rb
@@ -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
diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb
index 5374781..43e4b8b 100644
--- a/test/psych/test_hash.rb
+++ b/test/psych/test_hash.rb
@@ -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"
diff --git a/test/psych/test_object.rb b/test/psych/test_object.rb
index 0faf6b2..648a3ca 100644
--- a/test/psych/test_object.rb
+++ b/test/psych/test_object.rb
@@ -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