aboutsummaryrefslogtreecommitdiffstats
path: root/test/psych
diff options
context:
space:
mode:
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