1require 'psych/helper'
2
3module Psych
4  class TestArray < TestCase
5    class X < Array
6    end
7
8    class Y < Array
9      attr_accessor :val
10    end
11
12    def setup
13      super
14      @list = [{ :a => 'b' }, 'foo']
15    end
16
17    def test_another_subclass_with_attributes
18      y = Y.new.tap {|y| y.val = 1}
19      y << "foo" << "bar"
20      y = Psych.load Psych.dump y
21
22      assert_equal %w{foo bar}, y
23      assert_equal Y, y.class
24      assert_equal 1, y.val
25    end
26
27    def test_subclass
28      yaml = Psych.dump X.new
29      assert_match X.name, yaml
30
31      list = X.new
32      list << 1
33      assert_equal X, list.class
34      assert_equal 1, list.first
35    end
36
37    def test_subclass_with_attributes
38      y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
39      assert_equal Y, y.class
40      assert_equal 1, y.val
41    end
42
43    def test_backwards_with_syck
44      x = Psych.load "--- !seq:#{X.name} []\n\n"
45      assert_equal X, x.class
46    end
47
48    def test_self_referential
49      @list << @list
50      assert_cycle(@list)
51    end
52
53    def test_cycle
54      assert_cycle(@list)
55    end
56  end
57end
58