summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornick evans <[email protected]>2024-10-28 15:41:01 -0400
committergit <[email protected]>2025-05-01 17:52:13 +0000
commita397e4d4b0a0e7e8499a33ec760dba97ce494c63 ()
tree5781fd294aede7309847dbfd90c217c0067cfc63
parentbd1d6e8cd725e84addfac8583634458a624929ae (diff)
[ruby/psych] Add support for ruby 3.2 Data objects
https://.com/ruby/psych/commit/788b844c83
-rw-r--r--ext/psych/lib/psych/class_loader.rb1
-rw-r--r--ext/psych/lib/psych/visitors/to_ruby.rb22
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb10
-rw-r--r--test/psych/test_object_references.rb5
-rw-r--r--test/psych/test_safe_load.rb32
-rw-r--r--test/psych/test_yaml.rb39
-rw-r--r--test/psych/visitors/test_yaml_tree.rb21
7 files changed, 130 insertions, 0 deletions
@@ -6,6 +6,7 @@ module Psych
class ClassLoader # :nodoc:
BIG_DECIMAL = 'BigDecimal'
COMPLEX = 'Complex'
DATE = 'Date'
DATE_TIME = 'DateTime'
EXCEPTION = 'Exception'
@@ -197,6 +197,14 @@ module Psych
s
end
when /^!ruby\/object:?(.*)?$/
name = $1 || 'Object'
@@ -340,6 +348,20 @@ module Psych
list
end
def revive_hash hash, o, tagged= false
o.children.each_slice(2) { |k,v|
key = accept(k)
@@ -162,6 +162,16 @@ module Psych
alias :visit_Delegator :visit_Object
def visit_Struct o
tag = ['!ruby/struct', o.class.name].compact.join(':')
@@ -31,6 +31,11 @@ module Psych
assert_reference_trip Struct.new(:foo).new(1)
end
def assert_reference_trip obj
yml = Psych.dump([obj, obj])
assert_match(/\*-?\d+/, yml)
@@ -114,6 +114,38 @@ module Psych
end
end
def test_safe_load_default_fallback
assert_nil Psych.safe_load("")
end
@@ -6,6 +6,7 @@ require_relative 'helper'
# [ruby-core:01946]
module Psych_Tests
StructTest = Struct::new( :c )
end
class Psych_Unit_Tests < Psych::TestCase
@@ -1075,6 +1076,44 @@ EOY
end
def test_ruby_rational
assert_to_yaml( Rational(1, 2), <<EOY )
--- !ruby/object:Rational
@@ -73,6 +73,27 @@ module Psych
assert_equal s.method, obj.method
end
def test_exception
ex = Exception.new 'foo'
loaded = Psych.unsafe_load(Psych.dump(ex))