* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / test / psych / test_serialize_subclasses.rb
blob344c79b3eff969cc27c18b334a589d353340fc6c
1 # frozen_string_literal: true
2 require_relative 'helper'
4 module Psych
5   class TestSerializeSubclasses < TestCase
6     class SomeObject
7       def initialize one, two
8         @one = one
9         @two = two
10       end
12       def == other
13         @one == other.instance_eval { @one } &&
14           @two == other.instance_eval { @two }
15       end
16     end
18     def test_some_object
19       so = SomeObject.new('foo', [1,2,3])
20       assert_equal so, Psych.unsafe_load(Psych.dump(so))
21     end
23     class StructSubclass < Struct.new(:foo)
24       def initialize foo, bar
25         super(foo)
26         @bar = bar
27       end
29       def == other
30         super(other) && @bar == other.instance_eval{ @bar }
31       end
32     end
34     def test_struct_subclass
35       so = StructSubclass.new('foo', [1,2,3])
36       assert_equal so, Psych.unsafe_load(Psych.dump(so))
37     end
38   end
39 end