psych 2.1.0-java → 2.1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/Gemfile +3 -0
- data/Mavenfile +7 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/ext/java/PsychEmitter.java +345 -0
- data/ext/java/PsychLibrary.java +93 -0
- data/ext/java/PsychParser.java +399 -0
- data/ext/java/PsychToRuby.java +79 -0
- data/ext/java/PsychYamlTree.java +55 -0
- data/ext/psych/.gitignore +11 -0
- data/lib/psych.rb +2 -2
- data/lib/psych/visitors/to_ruby.rb +2 -2
- data/psych.gemspec +39 -0
- metadata +19 -53
- data/test/psych/handlers/test_recorder.rb +0 -26
- data/test/psych/helper.rb +0 -122
- data/test/psych/json/test_stream.rb +0 -110
- data/test/psych/nodes/test_enumerable.rb +0 -44
- data/test/psych/test_alias_and_anchor.rb +0 -97
- data/test/psych/test_array.rb +0 -58
- data/test/psych/test_boolean.rb +0 -37
- data/test/psych/test_class.rb +0 -37
- data/test/psych/test_coder.rb +0 -207
- data/test/psych/test_date_time.rb +0 -39
- data/test/psych/test_deprecated.rb +0 -215
- data/test/psych/test_document.rb +0 -47
- data/test/psych/test_emitter.rb +0 -112
- data/test/psych/test_encoding.rb +0 -269
- data/test/psych/test_exception.rb +0 -158
- data/test/psych/test_hash.rb +0 -95
- data/test/psych/test_json_tree.rb +0 -66
- data/test/psych/test_merge_keys.rb +0 -181
- data/test/psych/test_nil.rb +0 -19
- data/test/psych/test_null.rb +0 -20
- data/test/psych/test_numeric.rb +0 -46
- data/test/psych/test_object.rb +0 -45
- data/test/psych/test_object_references.rb +0 -72
- data/test/psych/test_omap.rb +0 -76
- data/test/psych/test_parser.rb +0 -340
- data/test/psych/test_psych.rb +0 -184
- data/test/psych/test_safe_load.rb +0 -98
- data/test/psych/test_scalar.rb +0 -12
- data/test/psych/test_scalar_scanner.rb +0 -111
- data/test/psych/test_serialize_subclasses.rb +0 -39
- data/test/psych/test_set.rb +0 -50
- data/test/psych/test_stream.rb +0 -94
- data/test/psych/test_string.rb +0 -231
- data/test/psych/test_struct.rb +0 -50
- data/test/psych/test_symbol.rb +0 -26
- data/test/psych/test_tainted.rb +0 -131
- data/test/psych/test_to_yaml_properties.rb +0 -64
- data/test/psych/test_tree_builder.rb +0 -80
- data/test/psych/test_yaml.rb +0 -1293
- data/test/psych/test_yamldbm.rb +0 -193
- data/test/psych/test_yamlstore.rb +0 -86
- data/test/psych/visitors/test_depth_first.rb +0 -50
- data/test/psych/visitors/test_emitter.rb +0 -145
- data/test/psych/visitors/test_to_ruby.rb +0 -332
- data/test/psych/visitors/test_yaml_tree.rb +0 -180
@@ -1,332 +0,0 @@
|
|
1
|
-
# coding: US-ASCII
|
2
|
-
# frozen_string_literal: false
|
3
|
-
require 'psych/helper'
|
4
|
-
|
5
|
-
module Psych
|
6
|
-
module Visitors
|
7
|
-
class TestToRuby < TestCase
|
8
|
-
def setup
|
9
|
-
super
|
10
|
-
@visitor = ToRuby.create
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_object
|
14
|
-
mapping = Nodes::Mapping.new nil, "!ruby/object"
|
15
|
-
mapping.children << Nodes::Scalar.new('foo')
|
16
|
-
mapping.children << Nodes::Scalar.new('bar')
|
17
|
-
|
18
|
-
o = mapping.to_ruby
|
19
|
-
assert_equal 'bar', o.instance_variable_get(:@foo)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_tz_00_00_loads_without_error
|
23
|
-
assert Psych.load('1900-01-01T00:00:00+00:00')
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_legacy_struct
|
27
|
-
foo = Struct.new('AWESOME', :bar)
|
28
|
-
assert_equal foo.new('baz'), Psych.load(<<-eoyml)
|
29
|
-
!ruby/struct:AWESOME
|
30
|
-
bar: baz
|
31
|
-
eoyml
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_binary
|
35
|
-
gif = "GIF89a\f\x00\f\x00\x84\x00\x00\xFF\xFF\xF7\xF5\xF5\xEE\xE9\xE9\xE5fff\x00\x00\x00\xE7\xE7\xE7^^^\xF3\xF3\xED\x8E\x8E\x8E\xE0\xE0\xE0\x9F\x9F\x9F\x93\x93\x93\xA7\xA7\xA7\x9E\x9E\x9Eiiiccc\xA3\xA3\xA3\x84\x84\x84\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9!\xFE\x0EMade with GIMP\x00,\x00\x00\x00\x00\f\x00\f\x00\x00\x05, \x8E\x810\x9E\xE3@\x14\xE8i\x10\xC4\xD1\x8A\b\x1C\xCF\x80M$z\xEF\xFF0\x85p\xB8\xB01f\r\e\xCE\x01\xC3\x01\x1E\x10' \x82\n\x01\x00;"
|
36
|
-
|
37
|
-
hash = Psych.load(<<-'eoyaml')
|
38
|
-
canonical: !!binary "\
|
39
|
-
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\
|
40
|
-
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\
|
41
|
-
+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\
|
42
|
-
AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs="
|
43
|
-
generic: !binary |
|
44
|
-
R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
|
45
|
-
OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
|
46
|
-
+f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
|
47
|
-
AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
|
48
|
-
description:
|
49
|
-
The binary value above is a tiny arrow encoded as a gif image.
|
50
|
-
eoyaml
|
51
|
-
assert_equal gif, hash['canonical']
|
52
|
-
assert_equal gif, hash['generic']
|
53
|
-
end
|
54
|
-
|
55
|
-
A = Struct.new(:foo)
|
56
|
-
|
57
|
-
def test_struct
|
58
|
-
s = A.new('bar')
|
59
|
-
|
60
|
-
mapping = Nodes::Mapping.new nil, "!ruby/struct:#{s.class}"
|
61
|
-
mapping.children << Nodes::Scalar.new('foo')
|
62
|
-
mapping.children << Nodes::Scalar.new('bar')
|
63
|
-
|
64
|
-
ruby = mapping.to_ruby
|
65
|
-
|
66
|
-
assert_equal s.class, ruby.class
|
67
|
-
assert_equal s.foo, ruby.foo
|
68
|
-
assert_equal s, ruby
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_anon_struct_legacy
|
72
|
-
s = Struct.new(:foo).new('bar')
|
73
|
-
|
74
|
-
mapping = Nodes::Mapping.new nil, '!ruby/struct:'
|
75
|
-
mapping.children << Nodes::Scalar.new('foo')
|
76
|
-
mapping.children << Nodes::Scalar.new('bar')
|
77
|
-
|
78
|
-
assert_equal s.foo, mapping.to_ruby.foo
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_anon_struct
|
82
|
-
s = Struct.new(:foo).new('bar')
|
83
|
-
|
84
|
-
mapping = Nodes::Mapping.new nil, '!ruby/struct'
|
85
|
-
mapping.children << Nodes::Scalar.new('foo')
|
86
|
-
mapping.children << Nodes::Scalar.new('bar')
|
87
|
-
|
88
|
-
assert_equal s.foo, mapping.to_ruby.foo
|
89
|
-
end
|
90
|
-
|
91
|
-
def test_exception
|
92
|
-
exc = ::Exception.new 'hello'
|
93
|
-
|
94
|
-
mapping = Nodes::Mapping.new nil, '!ruby/exception'
|
95
|
-
mapping.children << Nodes::Scalar.new('message')
|
96
|
-
mapping.children << Nodes::Scalar.new('hello')
|
97
|
-
|
98
|
-
ruby = mapping.to_ruby
|
99
|
-
|
100
|
-
assert_equal exc.class, ruby.class
|
101
|
-
assert_equal exc.message, ruby.message
|
102
|
-
end
|
103
|
-
|
104
|
-
def test_regexp
|
105
|
-
node = Nodes::Scalar.new('/foo/', nil, '!ruby/regexp')
|
106
|
-
assert_equal(/foo/, node.to_ruby)
|
107
|
-
|
108
|
-
node = Nodes::Scalar.new('/foo/m', nil, '!ruby/regexp')
|
109
|
-
assert_equal(/foo/m, node.to_ruby)
|
110
|
-
|
111
|
-
node = Nodes::Scalar.new('/foo/ix', nil, '!ruby/regexp')
|
112
|
-
assert_equal(/foo/ix, node.to_ruby)
|
113
|
-
end
|
114
|
-
|
115
|
-
def test_time
|
116
|
-
now = Time.now
|
117
|
-
zone = now.strftime('%z')
|
118
|
-
zone = " #{zone[0,3]}:#{zone[3,5]}"
|
119
|
-
|
120
|
-
formatted = now.strftime("%Y-%m-%d %H:%M:%S.%9N") + zone
|
121
|
-
|
122
|
-
assert_equal now, Nodes::Scalar.new(formatted).to_ruby
|
123
|
-
end
|
124
|
-
|
125
|
-
def test_time_utc
|
126
|
-
now = Time.now.utc
|
127
|
-
formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
|
128
|
-
".%09dZ" % [now.nsec]
|
129
|
-
|
130
|
-
assert_equal now, Nodes::Scalar.new(formatted).to_ruby
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_time_utc_no_z
|
134
|
-
now = Time.now.utc
|
135
|
-
formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
|
136
|
-
".%09d" % [now.nsec]
|
137
|
-
|
138
|
-
assert_equal now, Nodes::Scalar.new(formatted).to_ruby
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_date
|
142
|
-
d = '1980-12-16'
|
143
|
-
actual = Date.strptime(d, '%Y-%m-%d')
|
144
|
-
|
145
|
-
date = Nodes::Scalar.new(d, nil, 'tag:yaml.org,2002:timestamp', false)
|
146
|
-
|
147
|
-
assert_equal actual, date.to_ruby
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_rational
|
151
|
-
mapping = Nodes::Mapping.new nil, '!ruby/object:Rational'
|
152
|
-
mapping.children << Nodes::Scalar.new('denominator')
|
153
|
-
mapping.children << Nodes::Scalar.new('2')
|
154
|
-
mapping.children << Nodes::Scalar.new('numerator')
|
155
|
-
mapping.children << Nodes::Scalar.new('1')
|
156
|
-
|
157
|
-
assert_equal Rational(1,2), mapping.to_ruby
|
158
|
-
end
|
159
|
-
|
160
|
-
def test_complex
|
161
|
-
mapping = Nodes::Mapping.new nil, '!ruby/object:Complex'
|
162
|
-
mapping.children << Nodes::Scalar.new('image')
|
163
|
-
mapping.children << Nodes::Scalar.new('2')
|
164
|
-
mapping.children << Nodes::Scalar.new('real')
|
165
|
-
mapping.children << Nodes::Scalar.new('1')
|
166
|
-
|
167
|
-
assert_equal Complex(1,2), mapping.to_ruby
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_complex_string
|
171
|
-
node = Nodes::Scalar.new '3+4i', nil, "!ruby/object:Complex"
|
172
|
-
assert_equal Complex(3, 4), node.to_ruby
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_rational_string
|
176
|
-
node = Nodes::Scalar.new '1/2', nil, "!ruby/object:Rational"
|
177
|
-
assert_equal Rational(1, 2), node.to_ruby
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_range_string
|
181
|
-
node = Nodes::Scalar.new '1..2', nil, "!ruby/range"
|
182
|
-
assert_equal 1..2, node.to_ruby
|
183
|
-
end
|
184
|
-
|
185
|
-
def test_range_string_triple
|
186
|
-
node = Nodes::Scalar.new '1...3', nil, "!ruby/range"
|
187
|
-
assert_equal 1...3, node.to_ruby
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_integer
|
191
|
-
i = Nodes::Scalar.new('1', nil, 'tag:yaml.org,2002:int')
|
192
|
-
assert_equal 1, i.to_ruby
|
193
|
-
|
194
|
-
assert_equal 1, Nodes::Scalar.new('1').to_ruby
|
195
|
-
|
196
|
-
i = Nodes::Scalar.new('-1', nil, 'tag:yaml.org,2002:int')
|
197
|
-
assert_equal(-1, i.to_ruby)
|
198
|
-
|
199
|
-
assert_equal(-1, Nodes::Scalar.new('-1').to_ruby)
|
200
|
-
assert_equal 1, Nodes::Scalar.new('+1').to_ruby
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_int_ignore
|
204
|
-
['1,000', '1_000'].each do |num|
|
205
|
-
i = Nodes::Scalar.new(num, nil, 'tag:yaml.org,2002:int')
|
206
|
-
assert_equal 1000, i.to_ruby
|
207
|
-
|
208
|
-
assert_equal 1000, Nodes::Scalar.new(num).to_ruby
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
def test_float_ignore
|
213
|
-
['1,000.3', '1_000.3'].each do |num|
|
214
|
-
i = Nodes::Scalar.new(num, nil, 'tag:yaml.org,2002:float')
|
215
|
-
assert_equal 1000.3, i.to_ruby
|
216
|
-
|
217
|
-
i = Nodes::Scalar.new(num, nil, '!float')
|
218
|
-
assert_equal 1000.3, i.to_ruby
|
219
|
-
|
220
|
-
assert_equal 1000.3, Nodes::Scalar.new(num).to_ruby
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
# http://yaml.org/type/bool.html
|
225
|
-
def test_boolean_true
|
226
|
-
%w{ yes Yes YES true True TRUE on On ON }.each do |t|
|
227
|
-
i = Nodes::Scalar.new(t, nil, 'tag:yaml.org,2002:bool')
|
228
|
-
assert_equal true, i.to_ruby
|
229
|
-
assert_equal true, Nodes::Scalar.new(t).to_ruby
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
# http://yaml.org/type/bool.html
|
234
|
-
def test_boolean_false
|
235
|
-
%w{ no No NO false False FALSE off Off OFF }.each do |t|
|
236
|
-
i = Nodes::Scalar.new(t, nil, 'tag:yaml.org,2002:bool')
|
237
|
-
assert_equal false, i.to_ruby
|
238
|
-
assert_equal false, Nodes::Scalar.new(t).to_ruby
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
def test_float
|
243
|
-
i = Nodes::Scalar.new('12', nil, 'tag:yaml.org,2002:float')
|
244
|
-
assert_equal 12.0, i.to_ruby
|
245
|
-
|
246
|
-
i = Nodes::Scalar.new('1.2', nil, 'tag:yaml.org,2002:float')
|
247
|
-
assert_equal 1.2, i.to_ruby
|
248
|
-
|
249
|
-
i = Nodes::Scalar.new('1.2')
|
250
|
-
assert_equal 1.2, i.to_ruby
|
251
|
-
|
252
|
-
assert_equal 1, Nodes::Scalar.new('.Inf').to_ruby.infinite?
|
253
|
-
assert_equal 1, Nodes::Scalar.new('.inf').to_ruby.infinite?
|
254
|
-
assert_equal 1, Nodes::Scalar.new('.Inf', nil, 'tag:yaml.org,2002:float').to_ruby.infinite?
|
255
|
-
|
256
|
-
assert_equal(-1, Nodes::Scalar.new('-.inf').to_ruby.infinite?)
|
257
|
-
assert_equal(-1, Nodes::Scalar.new('-.Inf').to_ruby.infinite?)
|
258
|
-
assert_equal(-1, Nodes::Scalar.new('-.Inf', nil, 'tag:yaml.org,2002:float').to_ruby.infinite?)
|
259
|
-
|
260
|
-
assert Nodes::Scalar.new('.NaN').to_ruby.nan?
|
261
|
-
assert Nodes::Scalar.new('.NaN', nil, 'tag:yaml.org,2002:float').to_ruby.nan?
|
262
|
-
end
|
263
|
-
|
264
|
-
def test_exp_float
|
265
|
-
exp = 1.2e+30
|
266
|
-
|
267
|
-
i = Nodes::Scalar.new(exp.to_s, nil, 'tag:yaml.org,2002:float')
|
268
|
-
assert_equal exp, i.to_ruby
|
269
|
-
|
270
|
-
assert_equal exp, Nodes::Scalar.new(exp.to_s).to_ruby
|
271
|
-
end
|
272
|
-
|
273
|
-
def test_scalar
|
274
|
-
scalar = Nodes::Scalar.new('foo')
|
275
|
-
assert_equal 'foo', @visitor.accept(scalar)
|
276
|
-
assert_equal 'foo', scalar.to_ruby
|
277
|
-
end
|
278
|
-
|
279
|
-
def test_sequence
|
280
|
-
seq = Nodes::Sequence.new
|
281
|
-
seq.children << Nodes::Scalar.new('foo')
|
282
|
-
seq.children << Nodes::Scalar.new('bar')
|
283
|
-
|
284
|
-
assert_equal %w{ foo bar }, seq.to_ruby
|
285
|
-
end
|
286
|
-
|
287
|
-
def test_mapping
|
288
|
-
mapping = Nodes::Mapping.new
|
289
|
-
mapping.children << Nodes::Scalar.new('foo')
|
290
|
-
mapping.children << Nodes::Scalar.new('bar')
|
291
|
-
assert_equal({'foo' => 'bar'}, mapping.to_ruby)
|
292
|
-
end
|
293
|
-
|
294
|
-
def test_document
|
295
|
-
doc = Nodes::Document.new
|
296
|
-
doc.children << Nodes::Scalar.new('foo')
|
297
|
-
assert_equal 'foo', doc.to_ruby
|
298
|
-
end
|
299
|
-
|
300
|
-
def test_stream
|
301
|
-
a = Nodes::Document.new
|
302
|
-
a.children << Nodes::Scalar.new('foo')
|
303
|
-
|
304
|
-
b = Nodes::Document.new
|
305
|
-
b.children << Nodes::Scalar.new('bar')
|
306
|
-
|
307
|
-
stream = Nodes::Stream.new
|
308
|
-
stream.children << a
|
309
|
-
stream.children << b
|
310
|
-
|
311
|
-
assert_equal %w{ foo bar }, stream.to_ruby
|
312
|
-
end
|
313
|
-
|
314
|
-
def test_alias
|
315
|
-
seq = Nodes::Sequence.new
|
316
|
-
seq.children << Nodes::Scalar.new('foo', 'A')
|
317
|
-
seq.children << Nodes::Alias.new('A')
|
318
|
-
|
319
|
-
list = seq.to_ruby
|
320
|
-
assert_equal %w{ foo foo }, list
|
321
|
-
assert_equal list[0].object_id, list[1].object_id
|
322
|
-
end
|
323
|
-
|
324
|
-
def test_mapping_with_str_tag
|
325
|
-
mapping = Nodes::Mapping.new(nil, '!strawberry')
|
326
|
-
mapping.children << Nodes::Scalar.new('foo')
|
327
|
-
mapping.children << Nodes::Scalar.new('bar')
|
328
|
-
assert_equal({'foo' => 'bar'}, mapping.to_ruby)
|
329
|
-
end
|
330
|
-
end
|
331
|
-
end
|
332
|
-
end
|
@@ -1,180 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require 'psych/helper'
|
3
|
-
|
4
|
-
module Psych
|
5
|
-
module Visitors
|
6
|
-
class TestYAMLTree < TestCase
|
7
|
-
def setup
|
8
|
-
super
|
9
|
-
@v = Visitors::YAMLTree.create
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_tree_can_be_called_twice
|
13
|
-
@v.start
|
14
|
-
@v << Object.new
|
15
|
-
t = @v.tree
|
16
|
-
assert_equal t, @v.tree
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_yaml_tree_can_take_an_emitter
|
20
|
-
io = StringIO.new
|
21
|
-
e = Psych::Emitter.new io
|
22
|
-
v = Visitors::YAMLTree.create({}, e)
|
23
|
-
v.start
|
24
|
-
v << "hello world"
|
25
|
-
v.finish
|
26
|
-
|
27
|
-
assert_match "hello world", io.string
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_binary_formatting
|
31
|
-
gif = "GIF89a\f\x00\f\x00\x84\x00\x00\xFF\xFF\xF7\xF5\xF5\xEE\xE9\xE9\xE5fff\x00\x00\x00\xE7\xE7\xE7^^^\xF3\xF3\xED\x8E\x8E\x8E\xE0\xE0\xE0\x9F\x9F\x9F\x93\x93\x93\xA7\xA7\xA7\x9E\x9E\x9Eiiiccc\xA3\xA3\xA3\x84\x84\x84\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9\xFF\xFE\xF9!\xFE\x0EMade with GIMP\x00,\x00\x00\x00\x00\f\x00\f\x00\x00\x05, \x8E\x810\x9E\xE3@\x14\xE8i\x10\xC4\xD1\x8A\b\x1C\xCF\x80M$z\xEF\xFF0\x85p\xB8\xB01f\r\e\xCE\x01\xC3\x01\x1E\x10' \x82\n\x01\x00;"
|
32
|
-
@v << gif
|
33
|
-
scalar = @v.tree.children.first.children.first
|
34
|
-
assert_equal Psych::Nodes::Scalar::LITERAL, scalar.style
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_object_has_no_class
|
38
|
-
yaml = Psych.dump(Object.new)
|
39
|
-
assert(Psych.dump(Object.new) !~ /Object/, yaml)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_struct_const
|
43
|
-
foo = Struct.new("Foo", :bar)
|
44
|
-
assert_cycle foo.new('bar')
|
45
|
-
Struct.instance_eval { remove_const(:Foo) }
|
46
|
-
end
|
47
|
-
|
48
|
-
A = Struct.new(:foo)
|
49
|
-
|
50
|
-
def test_struct
|
51
|
-
assert_cycle A.new('bar')
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_struct_anon
|
55
|
-
s = Struct.new(:foo).new('bar')
|
56
|
-
obj = Psych.load(Psych.dump(s))
|
57
|
-
assert_equal s.foo, obj.foo
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_override_method
|
61
|
-
s = Struct.new(:method).new('override')
|
62
|
-
obj = Psych.load(Psych.dump(s))
|
63
|
-
assert_equal s.method, obj.method
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_exception
|
67
|
-
ex = Exception.new 'foo'
|
68
|
-
loaded = Psych.load(Psych.dump(ex))
|
69
|
-
|
70
|
-
assert_equal ex.message, loaded.message
|
71
|
-
assert_equal ex.class, loaded.class
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_regexp
|
75
|
-
assert_cycle(/foo/)
|
76
|
-
assert_cycle(/foo/i)
|
77
|
-
assert_cycle(/foo/mx)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_time
|
81
|
-
t = Time.now
|
82
|
-
assert_equal t, Psych.load(Psych.dump(t))
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_date
|
86
|
-
date = Date.strptime('2002-12-14', '%Y-%m-%d')
|
87
|
-
assert_cycle date
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_rational
|
91
|
-
assert_cycle Rational(1,2)
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_complex
|
95
|
-
assert_cycle Complex(1,2)
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_scalar
|
99
|
-
assert_cycle 'foo'
|
100
|
-
assert_cycle ':foo'
|
101
|
-
assert_cycle ''
|
102
|
-
assert_cycle ':'
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_boolean
|
106
|
-
assert_cycle true
|
107
|
-
assert_cycle 'true'
|
108
|
-
assert_cycle false
|
109
|
-
assert_cycle 'false'
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_range_inclusive
|
113
|
-
assert_cycle 1..2
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_range_exclusive
|
117
|
-
assert_cycle 1...2
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_anon_class
|
121
|
-
assert_raises(TypeError) do
|
122
|
-
@v.accept Class.new
|
123
|
-
end
|
124
|
-
|
125
|
-
assert_raises(TypeError) do
|
126
|
-
Psych.dump(Class.new)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_hash
|
131
|
-
assert_cycle('a' => 'b')
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_list
|
135
|
-
assert_cycle(%w{ a b })
|
136
|
-
assert_cycle([1, 2.2])
|
137
|
-
end
|
138
|
-
|
139
|
-
def test_symbol
|
140
|
-
assert_cycle :foo
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_int
|
144
|
-
assert_cycle 1
|
145
|
-
assert_cycle(-1)
|
146
|
-
assert_cycle '1'
|
147
|
-
assert_cycle '-1'
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_float
|
151
|
-
assert_cycle 1.2
|
152
|
-
assert_cycle '1.2'
|
153
|
-
|
154
|
-
assert Psych.load(Psych.dump(0.0 / 0.0)).nan?
|
155
|
-
assert_equal 1, Psych.load(Psych.dump(1 / 0.0)).infinite?
|
156
|
-
assert_equal(-1, Psych.load(Psych.dump(-1 / 0.0)).infinite?)
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_string
|
160
|
-
assert_match(/'017'/, Psych.dump({'a' => '017'}))
|
161
|
-
assert_match(/'019'/, Psych.dump({'a' => '019'}))
|
162
|
-
assert_match(/'01818'/, Psych.dump({'a' => '01818'}))
|
163
|
-
end
|
164
|
-
|
165
|
-
# http://yaml.org/type/null.html
|
166
|
-
def test_nil
|
167
|
-
assert_cycle nil
|
168
|
-
assert_equal nil, Psych.load('null')
|
169
|
-
assert_equal nil, Psych.load('Null')
|
170
|
-
assert_equal nil, Psych.load('NULL')
|
171
|
-
assert_equal nil, Psych.load('~')
|
172
|
-
assert_equal({'foo' => nil}, Psych.load('foo: '))
|
173
|
-
|
174
|
-
assert_cycle 'null'
|
175
|
-
assert_cycle 'nUll'
|
176
|
-
assert_cycle '~'
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
end
|