summaryrefslogtreecommitdiff
path: root/jni/ruby/test/psych/test_set.rb
blob: 921fe2284f4022effeeb9aaac3c56601e91a5294 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require_relative 'helper'

module Psych
  class TestSet < TestCase
    def setup
      super
      @set = Psych::Set.new
      @set['foo'] = 'bar'
      @set['bar'] = 'baz'
    end

    def test_dump
      assert_match(/!set/, Psych.dump(@set))
    end

    def test_roundtrip
      assert_cycle(@set)
    end

    ###
    # FIXME: Syck should also support !!set as shorthand
    def test_load_from_yaml
      loaded = Psych.load(<<-eoyml)
--- !set
foo: bar
bar: baz
      eoyml
      assert_equal(@set, loaded)
    end

    def test_loaded_class
      assert_instance_of(Psych::Set, Psych.load(Psych.dump(@set)))
    end

    def test_set_shorthand
      loaded = Psych.load(<<-eoyml)
--- !!set
foo: bar
bar: baz
      eoyml
      assert_instance_of(Psych::Set, loaded)
    end

    def test_set_self_reference
      @set['self'] = @set
      assert_cycle(@set)
    end
  end
end