[前][次][番号順一覧][スレッド一覧]

ruby-changes:72866

From: Alexander <ko1@a...>
Date: Tue, 9 Aug 2022 01:31:40 +0900 (JST)
Subject: [ruby-changes:72866] 0b7cfdca09 (master): [ruby/psych] Test that recursive refs dump as aliases

https://git.ruby-lang.org/ruby.git/commit/?id=0b7cfdca09

From 0b7cfdca09651f2eae5cd0e8ae4efed5033493f2 Mon Sep 17 00:00:00 2001
From: Alexander Momchilov <alexander.momchilov@s...>
Date: Fri, 22 Jul 2022 16:45:03 -0400
Subject: [ruby/psych] Test that recursive refs dump as aliases

https://github.com/ruby/psych/commit/d9f7289190
---
 test/psych/test_array.rb  | 13 +++++++++++++
 test/psych/test_hash.rb   | 12 ++++++++++++
 test/psych/test_object.rb | 12 ++++++++++++
 3 files changed, 37 insertions(+)

diff --git a/test/psych/test_array.rb b/test/psych/test_array.rb
index 28b76da785..a6be0baf2f 100644
--- a/test/psych/test_array.rb
+++ b/test/psych/test_array.rb
@@ -57,6 +57,19 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_array.rb#L57
       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 5374781339..43e4b8bf14 100644
--- a/test/psych/test_hash.rb
+++ b/test/psych/test_hash.rb
@@ -112,6 +112,18 @@ eoyml https://github.com/ruby/ruby/blob/trunk/test/psych/test_hash.rb#L112
       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 0faf6b244d..648a3ca6a5 100644
--- a/test/psych/test_object.rb
+++ b/test/psych/test_object.rb
@@ -41,5 +41,17 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_object.rb#L41
       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
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]