1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string

subclass dumping and loading.

* test/psych/test_array.rb: pertinent tests

* test/psych/test_string.rb: ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tenderlove 2012-05-15 20:13:21 +00:00
parent 5341e3ccc4
commit b4bdb2f2eb
4 changed files with 27 additions and 2 deletions

View file

@ -1,3 +1,12 @@
Wed May 16 05:11:29 2012 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/visitors/to_ruby.rb: fix a bug with string
subclass dumping and loading.
* test/psych/test_array.rb: pertinent tests
* test/psych/test_string.rb: ditto
Wed May 16 01:31:21 2012 Aaron Patterson <aaron@tenderlovemaking.com> Wed May 16 01:31:21 2012 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to * ext/psych/lib/psych/visitors/to_ruby.rb: convert omap tagged maps to

View file

@ -147,8 +147,7 @@ module Psych
string = members.delete 'str' string = members.delete 'str'
if klass if klass
string = klass.allocate string = klass.allocate.replace string
string.replace string
end end
init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o) init_with(string, members.map { |k,v| [k.to_s.sub(/^@/, ''),v] }, o)

View file

@ -14,6 +14,16 @@ module Psych
@list = [{ :a => 'b' }, 'foo'] @list = [{ :a => 'b' }, 'foo']
end end
def test_another_subclass_with_attributes
y = Y.new.tap {|y| y.val = 1}
y << "foo" << "bar"
y = Psych.load Psych.dump y
assert_equal %w{foo bar}, y
assert_equal Y, y.class
assert_equal 1, y.val
end
def test_subclass def test_subclass
yaml = Psych.dump X.new yaml = Psych.dump X.new
assert_match X.name, yaml assert_match X.name, yaml

View file

@ -9,6 +9,13 @@ module Psych
attr_accessor :val attr_accessor :val
end end
def test_another_subclass_with_attributes
y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1}
assert_equal "foo", y
assert_equal Y, y.class
assert_equal 1, y.val
end
def test_backwards_with_syck def test_backwards_with_syck
x = Psych.load "--- !str:#{X.name} foo\n\n" x = Psych.load "--- !str:#{X.name} foo\n\n"
assert_equal X, x.class assert_equal X, x.class