psych 2.0.14-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +18 -0
- data/.gemtest +0 -0
- data/.travis.yml +16 -0
- data/CHANGELOG.rdoc +576 -0
- data/Manifest.txt +114 -0
- data/README.rdoc +71 -0
- data/Rakefile +123 -0
- data/ext/psych/depend +3 -0
- data/ext/psych/extconf.rb +38 -0
- data/ext/psych/psych.c +34 -0
- data/ext/psych/psych.h +20 -0
- data/ext/psych/psych_emitter.c +555 -0
- data/ext/psych/psych_emitter.h +8 -0
- data/ext/psych/psych_parser.c +597 -0
- data/ext/psych/psych_parser.h +6 -0
- data/ext/psych/psych_to_ruby.c +43 -0
- data/ext/psych/psych_to_ruby.h +8 -0
- data/ext/psych/psych_yaml_tree.c +24 -0
- data/ext/psych/psych_yaml_tree.h +8 -0
- data/ext/psych/yaml/LICENSE +19 -0
- data/ext/psych/yaml/api.c +1415 -0
- data/ext/psych/yaml/config.h +10 -0
- data/ext/psych/yaml/dumper.c +394 -0
- data/ext/psych/yaml/emitter.c +2329 -0
- data/ext/psych/yaml/loader.c +459 -0
- data/ext/psych/yaml/parser.c +1370 -0
- data/ext/psych/yaml/reader.c +469 -0
- data/ext/psych/yaml/scanner.c +3576 -0
- data/ext/psych/yaml/writer.c +141 -0
- data/ext/psych/yaml/yaml.h +1971 -0
- data/ext/psych/yaml/yaml_private.h +664 -0
- data/lib/psych.jar +0 -0
- data/lib/psych.rb +504 -0
- data/lib/psych/class_loader.rb +101 -0
- data/lib/psych/coder.rb +94 -0
- data/lib/psych/core_ext.rb +35 -0
- data/lib/psych/deprecated.rb +85 -0
- data/lib/psych/exception.rb +13 -0
- data/lib/psych/handler.rb +249 -0
- data/lib/psych/handlers/document_stream.rb +22 -0
- data/lib/psych/handlers/recorder.rb +39 -0
- data/lib/psych/json/ruby_events.rb +19 -0
- data/lib/psych/json/stream.rb +16 -0
- data/lib/psych/json/tree_builder.rb +12 -0
- data/lib/psych/json/yaml_events.rb +29 -0
- data/lib/psych/nodes.rb +77 -0
- data/lib/psych/nodes/alias.rb +18 -0
- data/lib/psych/nodes/document.rb +60 -0
- data/lib/psych/nodes/mapping.rb +56 -0
- data/lib/psych/nodes/node.rb +55 -0
- data/lib/psych/nodes/scalar.rb +67 -0
- data/lib/psych/nodes/sequence.rb +81 -0
- data/lib/psych/nodes/stream.rb +37 -0
- data/lib/psych/omap.rb +4 -0
- data/lib/psych/parser.rb +51 -0
- data/lib/psych/scalar_scanner.rb +149 -0
- data/lib/psych/set.rb +4 -0
- data/lib/psych/stream.rb +37 -0
- data/lib/psych/streaming.rb +27 -0
- data/lib/psych/syntax_error.rb +21 -0
- data/lib/psych/tree_builder.rb +96 -0
- data/lib/psych/versions.rb +3 -0
- data/lib/psych/visitors.rb +6 -0
- data/lib/psych/visitors/depth_first.rb +26 -0
- data/lib/psych/visitors/emitter.rb +51 -0
- data/lib/psych/visitors/json_tree.rb +24 -0
- data/lib/psych/visitors/to_ruby.rb +404 -0
- data/lib/psych/visitors/visitor.rb +19 -0
- data/lib/psych/visitors/yaml_tree.rb +605 -0
- data/lib/psych/y.rb +9 -0
- data/lib/psych_jars.rb +5 -0
- data/test/psych/handlers/test_recorder.rb +25 -0
- data/test/psych/helper.rb +121 -0
- data/test/psych/json/test_stream.rb +109 -0
- data/test/psych/nodes/test_enumerable.rb +43 -0
- data/test/psych/test_alias_and_anchor.rb +96 -0
- data/test/psych/test_array.rb +57 -0
- data/test/psych/test_boolean.rb +36 -0
- data/test/psych/test_class.rb +36 -0
- data/test/psych/test_coder.rb +206 -0
- data/test/psych/test_date_time.rb +38 -0
- data/test/psych/test_deprecated.rb +214 -0
- data/test/psych/test_document.rb +46 -0
- data/test/psych/test_emitter.rb +93 -0
- data/test/psych/test_encoding.rb +259 -0
- data/test/psych/test_exception.rb +157 -0
- data/test/psych/test_hash.rb +94 -0
- data/test/psych/test_json_tree.rb +65 -0
- data/test/psych/test_merge_keys.rb +180 -0
- data/test/psych/test_nil.rb +18 -0
- data/test/psych/test_null.rb +19 -0
- data/test/psych/test_numeric.rb +45 -0
- data/test/psych/test_object.rb +44 -0
- data/test/psych/test_object_references.rb +71 -0
- data/test/psych/test_omap.rb +75 -0
- data/test/psych/test_parser.rb +339 -0
- data/test/psych/test_psych.rb +168 -0
- data/test/psych/test_safe_load.rb +97 -0
- data/test/psych/test_scalar.rb +11 -0
- data/test/psych/test_scalar_scanner.rb +106 -0
- data/test/psych/test_serialize_subclasses.rb +38 -0
- data/test/psych/test_set.rb +49 -0
- data/test/psych/test_stream.rb +93 -0
- data/test/psych/test_string.rb +226 -0
- data/test/psych/test_struct.rb +49 -0
- data/test/psych/test_symbol.rb +25 -0
- data/test/psych/test_tainted.rb +130 -0
- data/test/psych/test_to_yaml_properties.rb +63 -0
- data/test/psych/test_tree_builder.rb +79 -0
- data/test/psych/test_yaml.rb +1292 -0
- data/test/psych/test_yamldbm.rb +193 -0
- data/test/psych/test_yamlstore.rb +85 -0
- data/test/psych/visitors/test_depth_first.rb +49 -0
- data/test/psych/visitors/test_emitter.rb +144 -0
- data/test/psych/visitors/test_to_ruby.rb +333 -0
- data/test/psych/visitors/test_yaml_tree.rb +173 -0
- metadata +240 -0
@@ -0,0 +1,168 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
class TestPsych < Psych::TestCase
|
7
|
+
def teardown
|
8
|
+
Psych.domain_types.clear
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_line_width
|
12
|
+
yml = Psych.dump('123456 7', { :line_width => 5 })
|
13
|
+
assert_match(/^\s*7/, yml)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_indent
|
17
|
+
yml = Psych.dump({:a => {'b' => 'c'}}, {:indentation => 5})
|
18
|
+
assert_match(/^[ ]{5}b/, yml)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_canonical
|
22
|
+
yml = Psych.dump({:a => {'b' => 'c'}}, {:canonical => true})
|
23
|
+
assert_match(/\? "b/, yml)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_header
|
27
|
+
yml = Psych.dump({:a => {'b' => 'c'}}, {:header => true})
|
28
|
+
assert_match(/YAML/, yml)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_version_array
|
32
|
+
yml = Psych.dump({:a => {'b' => 'c'}}, {:version => [1,1]})
|
33
|
+
assert_match(/1.1/, yml)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_version_string
|
37
|
+
yml = Psych.dump({:a => {'b' => 'c'}}, {:version => '1.1'})
|
38
|
+
assert_match(/1.1/, yml)
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_version_bool
|
42
|
+
yml = Psych.dump({:a => {'b' => 'c'}}, {:version => true})
|
43
|
+
assert_match(/1.1/, yml)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_load_argument_error
|
47
|
+
assert_raises(TypeError) do
|
48
|
+
Psych.load nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_non_existing_class_on_deserialize
|
53
|
+
e = assert_raises(ArgumentError) do
|
54
|
+
Psych.load("--- !ruby/object:NonExistent\nfoo: 1")
|
55
|
+
end
|
56
|
+
assert_equal 'undefined class/module NonExistent', e.message
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_dump_stream
|
60
|
+
things = [22, "foo \n", {}]
|
61
|
+
stream = Psych.dump_stream(*things)
|
62
|
+
assert_equal things, Psych.load_stream(stream)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_dump_file
|
66
|
+
hash = {'hello' => 'TGIF!'}
|
67
|
+
Tempfile.create('fun.yml') do |io|
|
68
|
+
assert_equal io, Psych.dump(hash, io)
|
69
|
+
io.rewind
|
70
|
+
assert_equal Psych.dump(hash), io.read
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_dump_io
|
75
|
+
hash = {'hello' => 'TGIF!'}
|
76
|
+
stringio = StringIO.new ''
|
77
|
+
assert_equal stringio, Psych.dump(hash, stringio)
|
78
|
+
assert_equal Psych.dump(hash), stringio.string
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_simple
|
82
|
+
assert_equal 'foo', Psych.load("--- foo\n")
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_libyaml_version
|
86
|
+
assert Psych.libyaml_version
|
87
|
+
assert_equal Psych.libyaml_version.join('.'), Psych::LIBYAML_VERSION
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_load_documents
|
91
|
+
docs = Psych.load_documents("--- foo\n...\n--- bar\n...")
|
92
|
+
assert_equal %w{ foo bar }, docs
|
93
|
+
end
|
94
|
+
|
95
|
+
def test_parse_stream
|
96
|
+
docs = Psych.parse_stream("--- foo\n...\n--- bar\n...")
|
97
|
+
assert_equal %w{ foo bar }, docs.children.map { |x| x.transform }
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_add_builtin_type
|
101
|
+
got = nil
|
102
|
+
Psych.add_builtin_type 'omap' do |type, val|
|
103
|
+
got = val
|
104
|
+
end
|
105
|
+
Psych.load('--- !!omap hello')
|
106
|
+
assert_equal 'hello', got
|
107
|
+
ensure
|
108
|
+
Psych.remove_type 'omap'
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_domain_types
|
112
|
+
got = nil
|
113
|
+
Psych.add_domain_type 'foo.bar,2002', 'foo' do |type, val|
|
114
|
+
got = val
|
115
|
+
end
|
116
|
+
|
117
|
+
Psych.load('--- !foo.bar,2002/foo hello')
|
118
|
+
assert_equal 'hello', got
|
119
|
+
|
120
|
+
Psych.load("--- !foo.bar,2002/foo\n- hello\n- world")
|
121
|
+
assert_equal %w{ hello world }, got
|
122
|
+
|
123
|
+
Psych.load("--- !foo.bar,2002/foo\nhello: world")
|
124
|
+
assert_equal({ 'hello' => 'world' }, got)
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_load_file
|
128
|
+
Tempfile.create(['yikes', 'yml']) {|t|
|
129
|
+
t.binmode
|
130
|
+
t.write('--- hello world')
|
131
|
+
t.close
|
132
|
+
assert_equal 'hello world', Psych.load_file(t.path)
|
133
|
+
}
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_parse_file
|
137
|
+
Tempfile.create(['yikes', 'yml']) {|t|
|
138
|
+
t.binmode
|
139
|
+
t.write('--- hello world')
|
140
|
+
t.close
|
141
|
+
assert_equal 'hello world', Psych.parse_file(t.path).transform
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_degenerate_strings
|
146
|
+
assert_equal false, Psych.load(' ')
|
147
|
+
assert_equal false, Psych.parse(' ')
|
148
|
+
assert_equal false, Psych.load('')
|
149
|
+
assert_equal false, Psych.parse('')
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_callbacks
|
153
|
+
types = []
|
154
|
+
appender = lambda { |*args| types << args }
|
155
|
+
|
156
|
+
Psych.add_builtin_type('foo', &appender)
|
157
|
+
Psych.add_domain_type('example.com,2002', 'foo', &appender)
|
158
|
+
Psych.load <<-eoyml
|
159
|
+
- !tag:yaml.org,2002:foo bar
|
160
|
+
- !tag:example.com,2002:foo bar
|
161
|
+
eoyml
|
162
|
+
|
163
|
+
assert_equal [
|
164
|
+
["tag:yaml.org,2002:foo", "bar"],
|
165
|
+
["tag:example.com,2002:foo", "bar"]
|
166
|
+
], types
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'psych/helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
class TestSafeLoad < TestCase
|
5
|
+
class Foo; end
|
6
|
+
|
7
|
+
[1, 2.2, {}, [], "foo"].each do |obj|
|
8
|
+
define_method(:"test_basic_#{obj.class}") do
|
9
|
+
assert_safe_cycle obj
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_no_recursion
|
14
|
+
x = []
|
15
|
+
x << x
|
16
|
+
assert_raises(Psych::BadAlias) do
|
17
|
+
Psych.safe_load Psych.dump(x)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_explicit_recursion
|
22
|
+
x = []
|
23
|
+
x << x
|
24
|
+
assert_equal(x, Psych.safe_load(Psych.dump(x), [], [], true))
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_symbol_whitelist
|
28
|
+
yml = Psych.dump :foo
|
29
|
+
assert_raises(Psych::DisallowedClass) do
|
30
|
+
Psych.safe_load yml
|
31
|
+
end
|
32
|
+
assert_equal(:foo, Psych.safe_load(yml, [Symbol], [:foo]))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_symbol
|
36
|
+
assert_raises(Psych::DisallowedClass) do
|
37
|
+
assert_safe_cycle :foo
|
38
|
+
end
|
39
|
+
assert_raises(Psych::DisallowedClass) do
|
40
|
+
Psych.safe_load '--- !ruby/symbol foo', []
|
41
|
+
end
|
42
|
+
assert_safe_cycle :foo, [Symbol]
|
43
|
+
assert_safe_cycle :foo, %w{ Symbol }
|
44
|
+
assert_equal :foo, Psych.safe_load('--- !ruby/symbol foo', [Symbol])
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_foo
|
48
|
+
assert_raises(Psych::DisallowedClass) do
|
49
|
+
Psych.safe_load '--- !ruby/object:Foo {}', [Foo]
|
50
|
+
end
|
51
|
+
assert_raises(Psych::DisallowedClass) do
|
52
|
+
assert_safe_cycle Foo.new
|
53
|
+
end
|
54
|
+
assert_kind_of(Foo, Psych.safe_load(Psych.dump(Foo.new), [Foo]))
|
55
|
+
end
|
56
|
+
|
57
|
+
X = Struct.new(:x)
|
58
|
+
def test_struct_depends_on_sym
|
59
|
+
assert_safe_cycle(X.new, [X, Symbol])
|
60
|
+
assert_raises(Psych::DisallowedClass) do
|
61
|
+
cycle X.new, [X]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_anon_struct
|
66
|
+
assert Psych.safe_load(<<-eoyml, [Struct, Symbol])
|
67
|
+
--- !ruby/struct
|
68
|
+
foo: bar
|
69
|
+
eoyml
|
70
|
+
|
71
|
+
assert_raises(Psych::DisallowedClass) do
|
72
|
+
Psych.safe_load(<<-eoyml, [Struct])
|
73
|
+
--- !ruby/struct
|
74
|
+
foo: bar
|
75
|
+
eoyml
|
76
|
+
end
|
77
|
+
|
78
|
+
assert_raises(Psych::DisallowedClass) do
|
79
|
+
Psych.safe_load(<<-eoyml, [Symbol])
|
80
|
+
--- !ruby/struct
|
81
|
+
foo: bar
|
82
|
+
eoyml
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def cycle object, whitelist = []
|
89
|
+
Psych.safe_load(Psych.dump(object), whitelist)
|
90
|
+
end
|
91
|
+
|
92
|
+
def assert_safe_cycle object, whitelist = []
|
93
|
+
other = cycle object, whitelist
|
94
|
+
assert_equal object, other
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'date'
|
3
|
+
|
4
|
+
module Psych
|
5
|
+
class TestScalarScanner < TestCase
|
6
|
+
attr_reader :ss
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
@ss = Psych::ScalarScanner.new ClassLoader.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_scan_time
|
14
|
+
{ '2001-12-15T02:59:43.1Z' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
|
15
|
+
'2001-12-14t21:59:43.10-05:00' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
|
16
|
+
'2001-12-14 21:59:43.10 -5' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
|
17
|
+
'2001-12-15 2:59:43.10' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
|
18
|
+
'2011-02-24 11:17:06 -0800' => Time.utc(2011, 02, 24, 19, 17, 06)
|
19
|
+
}.each do |time_str, time|
|
20
|
+
assert_equal time, @ss.tokenize(time_str)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_scan_bad_time
|
25
|
+
[ '2001-12-15T02:59:73.1Z',
|
26
|
+
'2001-12-14t90:59:43.10-05:00',
|
27
|
+
'2001-92-14 21:59:43.10 -5',
|
28
|
+
'2001-12-15 92:59:43.10',
|
29
|
+
'2011-02-24 81:17:06 -0800',
|
30
|
+
].each do |time_str|
|
31
|
+
assert_equal time_str, @ss.tokenize(time_str)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_scan_bad_dates
|
36
|
+
x = '2000-15-01'
|
37
|
+
assert_equal x, @ss.tokenize(x)
|
38
|
+
|
39
|
+
x = '2000-10-51'
|
40
|
+
assert_equal x, @ss.tokenize(x)
|
41
|
+
|
42
|
+
x = '2000-10-32'
|
43
|
+
assert_equal x, @ss.tokenize(x)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_scan_good_edge_date
|
47
|
+
x = '2000-1-31'
|
48
|
+
assert_equal Date.strptime(x, '%Y-%m-%d'), @ss.tokenize(x)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_scan_bad_edge_date
|
52
|
+
x = '2000-11-31'
|
53
|
+
assert_equal x, @ss.tokenize(x)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_scan_date
|
57
|
+
date = '1980-12-16'
|
58
|
+
token = @ss.tokenize date
|
59
|
+
assert_equal 1980, token.year
|
60
|
+
assert_equal 12, token.month
|
61
|
+
assert_equal 16, token.day
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_scan_inf
|
65
|
+
assert_equal(1 / 0.0, ss.tokenize('.inf'))
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_scan_minus_inf
|
69
|
+
assert_equal(-1 / 0.0, ss.tokenize('-.inf'))
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_scan_nan
|
73
|
+
assert ss.tokenize('.nan').nan?
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_scan_null
|
77
|
+
assert_equal nil, ss.tokenize('null')
|
78
|
+
assert_equal nil, ss.tokenize('~')
|
79
|
+
assert_equal nil, ss.tokenize('')
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_scan_symbol
|
83
|
+
assert_equal :foo, ss.tokenize(':foo')
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_scan_sexagesimal_float
|
87
|
+
assert_equal 685230.15, ss.tokenize('190:20:30.15')
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_scan_sexagesimal_int
|
91
|
+
assert_equal 685230, ss.tokenize('190:20:30')
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_scan_float
|
95
|
+
assert_equal 1.2, ss.tokenize('1.2')
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_scan_true
|
99
|
+
assert_equal true, ss.tokenize('true')
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_scan_strings_starting_with_underscores
|
103
|
+
assert_equal "_100", ss.tokenize('_100')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module 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
|
38
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
class TestSet < TestCase
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@set = Psych::Set.new
|
8
|
+
@set['foo'] = 'bar'
|
9
|
+
@set['bar'] = 'baz'
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_dump
|
13
|
+
assert_match(/!set/, Psych.dump(@set))
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_roundtrip
|
17
|
+
assert_cycle(@set)
|
18
|
+
end
|
19
|
+
|
20
|
+
###
|
21
|
+
# FIXME: Syck should also support !!set as shorthand
|
22
|
+
def test_load_from_yaml
|
23
|
+
loaded = Psych.load(<<-eoyml)
|
24
|
+
--- !set
|
25
|
+
foo: bar
|
26
|
+
bar: baz
|
27
|
+
eoyml
|
28
|
+
assert_equal(@set, loaded)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_loaded_class
|
32
|
+
assert_instance_of(Psych::Set, Psych.load(Psych.dump(@set)))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_set_shorthand
|
36
|
+
loaded = Psych.load(<<-eoyml)
|
37
|
+
--- !!set
|
38
|
+
foo: bar
|
39
|
+
bar: baz
|
40
|
+
eoyml
|
41
|
+
assert_instance_of(Psych::Set, loaded)
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_set_self_reference
|
45
|
+
@set['self'] = @set
|
46
|
+
assert_cycle(@set)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|