From 8c08c8298a03a01629a478b74abfd57d7f35cb05 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Thu, 8 Jan 2015 22:00:54 +0000 Subject: * ext/psych/lib/psych/visitors/to_ruby.rb: revive hashes with ivars * ext/psych/lib/psych/visitors/yaml_tree.rb: dump hashes with ivars. Fixes github.com/psych/issues/43 * test/psych/test_hash.rb: test for change git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49188 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/psych/test_hash.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'test/psych') diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb index 264a4719e2..8d7ba1b1e0 100644 --- a/test/psych/test_hash.rb +++ b/test/psych/test_hash.rb @@ -10,6 +10,22 @@ module Psych @hash = { :a => 'b' } end + def test_hash_with_ivars + @hash.instance_variable_set :@foo, 'bar' + dup = Psych.load Psych.dump @hash + assert_equal 'bar', dup.instance_variable_get(:@foo) + end + + def test_hash_subclass_with_ivars + x = X.new + x[:a] = 'b' + x.instance_variable_set :@foo, 'bar' + dup = Psych.load Psych.dump x + assert_cycle x + assert_equal 'bar', dup.instance_variable_get(:@foo) + assert_equal X, dup.class + end + def test_load_with_class_syck_compatibility hash = Psych.load "--- !ruby/object:Hash\n:user_id: 7\n:username: Lucas\n" assert_equal({ user_id: 7, username: 'Lucas'}, hash) -- cgit v1.2.3