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

ruby-changes:72865

From: Alexander <ko1@a...>
Date: Tue, 9 Aug 2022 01:31:40 +0900 (JST)
Subject: [ruby-changes:72865] 71f89c2874 (master): [ruby/psych] Don't hardcode expected alias names

https://git.ruby-lang.org/ruby.git/commit/?id=71f89c2874

From 71f89c287459d5ca313d0b1a16b7a743e0d71b8b Mon Sep 17 00:00:00 2001
From: Alexander Momchilov <alexander.momchilov@s...>
Date: Wed, 27 Jul 2022 10:19:37 -0400
Subject: [ruby/psych] Don't hardcode expected alias names

https://github.com/ruby/psych/commit/b9ab19094f
---
 test/psych/test_array.rb  | 19 +++++++++++--------
 test/psych/test_hash.rb   | 18 ++++++++++++------
 test/psych/test_object.rb | 13 +++++--------
 3 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/test/psych/test_array.rb b/test/psych/test_array.rb
index a6be0baf2f..6a9931ab2f 100644
--- a/test/psych/test_array.rb
+++ b/test/psych/test_array.rb
@@ -57,17 +57,20 @@ 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
+    def test_recursive_array
       @list << @list
 
-      expected = <<~eoyaml
-        --- &1
-        - :a: b
-        - foo
-        - *1
-      eoyaml
+      loaded = Psych.load(Psych.dump(@list), aliases: true)
+
+      assert_same loaded, loaded.last
+    end
+
+    def test_recursive_array_uses_alias
+      @list << @list
 
-      assert_equal expected, Psych.dump(@list)
+      assert_raise(BadAlias) do
+        Psych.load(Psych.dump(@list), aliases: false)
+      end
     end
 
     def test_cycle
diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb
index 43e4b8bf14..0555f6e034 100644
--- a/test/psych/test_hash.rb
+++ b/test/psych/test_hash.rb
@@ -112,16 +112,22 @@ 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
+    def test_recursive_hash
       h = { }
       h["recursive_reference"] = h
 
-      expected = <<~eoyaml
-        --- &1
-        recursive_reference: *1
-      eoyaml
+      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
 
-      assert_equal(expected, Psych.dump(h))
+      assert_raise(BadAlias) do
+        Psych.load(Psych.dump(h), aliases: false)
+      end
     end
 
     def test_key_deduplication
diff --git a/test/psych/test_object.rb b/test/psych/test_object.rb
index 648a3ca6a5..227a1d1d53 100644
--- a/test/psych/test_object.rb
+++ b/test/psych/test_object.rb
@@ -36,22 +36,19 @@ module Psych https://github.com/ruby/ruby/blob/trunk/test/psych/test_object.rb#L36
     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
-- 
cgit v1.2.1


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

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