psych 2.0.14-java

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