1require 'psych/helper' 2 3module Psych 4 class TestHash < TestCase 5 class X < Hash 6 end 7 8 def setup 9 super 10 @hash = { :a => 'b' } 11 end 12 13 def test_empty_subclass 14 assert_match "!ruby/hash:#{X}", Psych.dump(X.new) 15 x = Psych.load Psych.dump X.new 16 assert_equal X, x.class 17 end 18 19 def test_map 20 x = Psych.load "--- !map:#{X} { }\n" 21 assert_equal X, x.class 22 end 23 24 def test_self_referential 25 @hash['self'] = @hash 26 assert_cycle(@hash) 27 end 28 29 def test_cycles 30 assert_cycle(@hash) 31 end 32 33 def test_ref_append 34 hash = Psych.load(<<-eoyml) 35--- 36foo: &foo 37 hello: world 38bar: 39 <<: *foo 40eoyml 41 assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash) 42 end 43 end 44end 45