diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2009-12-17 09:48:38 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2009-12-17 09:48:38 -0800 |
commit | cb8c3eb5a62c792d657eb7318d033ef52d2127a3 (patch) | |
tree | 428d6067f4a475d8ae97ec09bcf21f53f49ea5c5 /test | |
parent | 31126b53bbe0d88f0c1050f81ce88f847c13b5d3 (diff) | |
download | psych-cb8c3eb5a62c792d657eb7318d033ef52d2127a3.zip |
testing self referential structs
Diffstat (limited to 'test')
-rw-r--r-- | test/psych/test_struct.rb | 24 | ||||
-rw-r--r-- | test/yaml/test_array.rb | 5 | ||||
-rw-r--r-- | test/yaml/test_hash.rb | 5 |
3 files changed, 34 insertions, 0 deletions
diff --git a/test/psych/test_struct.rb b/test/psych/test_struct.rb new file mode 100644 index 0000000..1fb8149 --- /dev/null +++ b/test/psych/test_struct.rb @@ -0,0 +1,24 @@ +require 'helper' + +module Psych + class TestStruct < Test::Unit::TestCase + class StructSubclass < Struct.new(:foo) + def initialize foo, bar + super(foo) + @bar = bar + end + end + + def test_self_referential_struct + ss = StructSubclass.new(nil, 'foo') + ss.foo = ss + + loaded = Psych.load(Psych.dump(ss)) + assert_instance_of(StructSubclass, loaded.foo) + + # FIXME: This seems to cause an infinite loop. wtf. Must report a bug + # in ruby. + # assert_equal(ss, loaded) + end + end +end diff --git a/test/yaml/test_array.rb b/test/yaml/test_array.rb index 208c996..7e7318e 100644 --- a/test/yaml/test_array.rb +++ b/test/yaml/test_array.rb @@ -6,6 +6,11 @@ module YAML @list = [{ :a => 'b' }, 'foo'] end + def test_self_referential + @list << @list + assert_equal @list, YAML.load(@list.to_yaml) + end + def test_to_yaml assert_equal @list, YAML.load(@list.to_yaml) end diff --git a/test/yaml/test_hash.rb b/test/yaml/test_hash.rb index e8869ae..16a9ee3 100644 --- a/test/yaml/test_hash.rb +++ b/test/yaml/test_hash.rb @@ -6,6 +6,11 @@ module YAML @hash = { :a => 'b' } end + def test_self_referential + @hash['self'] = @hash + assert_equal @hash, YAML.load(YAML.dump(@hash)) + end + def test_to_yaml assert_equal @hash, YAML.load(@hash.to_yaml) end |