1require 'psych/helper'
2
3module Psych
4  class TestSerializeSubclasses < TestCase
5    class SomeObject
6      def initialize one, two
7        @one = one
8        @two = two
9      end
10
11      def == other
12        @one == other.instance_eval { @one } &&
13          @two == other.instance_eval { @two }
14      end
15    end
16
17    def test_some_object
18      so = SomeObject.new('foo', [1,2,3])
19      assert_equal so, Psych.load(Psych.dump(so))
20    end
21
22    class StructSubclass < Struct.new(:foo)
23      def initialize foo, bar
24        super(foo)
25        @bar = bar
26      end
27
28      def == other
29        super(other) && @bar == other.instance_eval{ @bar }
30      end
31    end
32
33    def test_struct_subclass
34      so = StructSubclass.new('foo', [1,2,3])
35      assert_equal so, Psych.load(Psych.dump(so))
36    end
37  end
38end
39