summaryrefslogtreecommitdiff
path: root/test/psych
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-08 22:15:20 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-08 22:15:20 +0000
commit5dabead1871ed0100674e3eeb4a9f549b1997a85 (patch)
tree224befd9530cbddacc71900bd29c71718506e70d /test/psych
parent8c08c8298a03a01629a478b74abfd57d7f35cb05 (diff)
downloadruby-5dabead1871ed0100674e3eeb4a9f549b1997a85.tar.gz
* ext/psych/lib/psych/visitors/to_ruby.rb: call `allocate` on hash
subclasses. Fixes github.com/tenderlove/psych/issues/196 * test/psych/test_hash.rb: test for change git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/psych')
-rw-r--r--test/psych/test_hash.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/psych/test_hash.rb b/test/psych/test_hash.rb
index 8d7ba1b1e0..066df6612e 100644
--- a/test/psych/test_hash.rb
+++ b/test/psych/test_hash.rb
@@ -5,11 +5,39 @@ module Psych
class X < Hash
end
+ class HashWithCustomInit < Hash
+ attr_reader :obj
+ def initialize(obj)
+ @obj = obj
+ end
+ end
+
+ class HashWithCustomInitNoIvar < Hash
+ def initialize(obj)
+ # *shrug*
+ end
+ end
+
def setup
super
@hash = { :a => 'b' }
end
+ def test_custom_initialized
+ a = [1,2,3,4,5]
+ t1 = HashWithCustomInit.new(a)
+ t2 = Psych.load(Psych.dump(t1))
+ assert_equal t1, t2
+ assert_cycle t1
+ end
+
+ def test_custom_initialize_no_ivar
+ t1 = HashWithCustomInitNoIvar.new(nil)
+ t2 = Psych.load(Psych.dump(t1))
+ assert_equal t1, t2
+ assert_cycle t1
+ end
+
def test_hash_with_ivars
@hash.instance_variable_set :@foo, 'bar'
dup = Psych.load Psych.dump @hash