km-psych 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/README.rdoc +129 -0
  2. data/ext/psych/emitter.c +488 -0
  3. data/ext/psych/emitter.h +8 -0
  4. data/ext/psych/extconf.rb +22 -0
  5. data/ext/psych/parser.c +349 -0
  6. data/ext/psych/parser.h +6 -0
  7. data/ext/psych/psych.c +34 -0
  8. data/ext/psych/psych.h +20 -0
  9. data/ext/psych/to_ruby.c +41 -0
  10. data/ext/psych/to_ruby.h +8 -0
  11. data/ext/psych/yaml_tree.c +24 -0
  12. data/ext/psych/yaml_tree.h +8 -0
  13. data/lib/km-psych.rb +244 -0
  14. data/lib/psych/coder.rb +86 -0
  15. data/lib/psych/core_ext.rb +38 -0
  16. data/lib/psych/deprecated.rb +82 -0
  17. data/lib/psych/handler.rb +221 -0
  18. data/lib/psych/json.rb +6 -0
  19. data/lib/psych/json/stream.rb +32 -0
  20. data/lib/psych/json/tree_builder.rb +32 -0
  21. data/lib/psych/nodes.rb +77 -0
  22. data/lib/psych/nodes/alias.rb +18 -0
  23. data/lib/psych/nodes/document.rb +60 -0
  24. data/lib/psych/nodes/mapping.rb +56 -0
  25. data/lib/psych/nodes/node.rb +42 -0
  26. data/lib/psych/nodes/scalar.rb +67 -0
  27. data/lib/psych/nodes/sequence.rb +81 -0
  28. data/lib/psych/nodes/stream.rb +37 -0
  29. data/lib/psych/omap.rb +4 -0
  30. data/lib/psych/parser.rb +44 -0
  31. data/lib/psych/scalar_scanner.rb +105 -0
  32. data/lib/psych/set.rb +4 -0
  33. data/lib/psych/stream.rb +53 -0
  34. data/lib/psych/tree_builder.rb +94 -0
  35. data/lib/psych/visitors.rb +5 -0
  36. data/lib/psych/visitors/emitter.rb +41 -0
  37. data/lib/psych/visitors/json_tree.rb +14 -0
  38. data/lib/psych/visitors/to_ruby.rb +263 -0
  39. data/lib/psych/visitors/visitor.rb +27 -0
  40. data/lib/psych/visitors/yaml_tree.rb +342 -0
  41. data/test/psych/helper.rb +63 -0
  42. data/test/psych/json/test_stream.rb +75 -0
  43. data/test/psych/test_alias_and_anchor.rb +26 -0
  44. data/test/psych/test_array.rb +19 -0
  45. data/test/psych/test_boolean.rb +36 -0
  46. data/test/psych/test_class.rb +17 -0
  47. data/test/psych/test_coder.rb +169 -0
  48. data/test/psych/test_date_time.rb +17 -0
  49. data/test/psych/test_deprecated.rb +210 -0
  50. data/test/psych/test_document.rb +46 -0
  51. data/test/psych/test_emitter.rb +88 -0
  52. data/test/psych/test_encoding.rb +179 -0
  53. data/test/psych/test_engine_manager.rb +57 -0
  54. data/test/psych/test_exception.rb +39 -0
  55. data/test/psych/test_hash.rb +30 -0
  56. data/test/psych/test_json_tree.rb +43 -0
  57. data/test/psych/test_null.rb +19 -0
  58. data/test/psych/test_object.rb +27 -0
  59. data/test/psych/test_omap.rb +68 -0
  60. data/test/psych/test_parser.rb +216 -0
  61. data/test/psych/test_psych.rb +133 -0
  62. data/test/psych/test_scalar.rb +11 -0
  63. data/test/psych/test_scalar_scanner.rb +70 -0
  64. data/test/psych/test_serialize_subclasses.rb +38 -0
  65. data/test/psych/test_set.rb +49 -0
  66. data/test/psych/test_stream.rb +49 -0
  67. data/test/psych/test_string.rb +49 -0
  68. data/test/psych/test_struct.rb +51 -0
  69. data/test/psych/test_symbol.rb +17 -0
  70. data/test/psych/test_to_yaml_properties.rb +63 -0
  71. data/test/psych/test_tree_builder.rb +79 -0
  72. data/test/psych/test_yaml.rb +1251 -0
  73. data/test/psych/visitors/test_emitter.rb +124 -0
  74. data/test/psych/visitors/test_to_ruby.rb +325 -0
  75. data/test/psych/visitors/test_yaml_tree.rb +149 -0
  76. metadata +187 -0
@@ -0,0 +1,124 @@
1
+ require_relative '../helper'
2
+
3
+ module Psych
4
+ module Visitors
5
+ class TestEmitter < TestCase
6
+ def setup
7
+ super
8
+ @io = StringIO.new
9
+ @visitor = Visitors::Emitter.new @io
10
+ end
11
+
12
+ def test_stream
13
+ s = Nodes::Stream.new
14
+ @visitor.accept s
15
+ assert_equal '', @io.string
16
+ end
17
+
18
+ def test_document
19
+ s = Nodes::Stream.new
20
+ doc = Nodes::Document.new [1,1]
21
+ scalar = Nodes::Scalar.new 'hello world'
22
+
23
+ doc.children << scalar
24
+ s.children << doc
25
+
26
+ @visitor.accept s
27
+
28
+ assert_match(/1.1/, @io.string)
29
+ assert_equal @io.string, s.to_yaml
30
+ end
31
+
32
+ def test_document_implicit_end
33
+ s = Nodes::Stream.new
34
+ doc = Nodes::Document.new
35
+ mapping = Nodes::Mapping.new
36
+ mapping.children << Nodes::Scalar.new('key')
37
+ mapping.children << Nodes::Scalar.new('value')
38
+ doc.children << mapping
39
+ s.children << doc
40
+
41
+ @visitor.accept s
42
+
43
+ assert_match(/key: value/, @io.string)
44
+ assert_equal @io.string, s.to_yaml
45
+ assert(/\.\.\./ !~ s.to_yaml)
46
+ end
47
+
48
+ def test_scalar
49
+ s = Nodes::Stream.new
50
+ doc = Nodes::Document.new
51
+ scalar = Nodes::Scalar.new 'hello world'
52
+
53
+ doc.children << scalar
54
+ s.children << doc
55
+
56
+ @visitor.accept s
57
+
58
+ assert_match(/hello/, @io.string)
59
+ assert_equal @io.string, s.to_yaml
60
+ end
61
+
62
+ def test_scalar_with_tag
63
+ s = Nodes::Stream.new
64
+ doc = Nodes::Document.new
65
+ scalar = Nodes::Scalar.new 'hello world', nil, '!str', false, false, 5
66
+
67
+ doc.children << scalar
68
+ s.children << doc
69
+
70
+ @visitor.accept s
71
+
72
+ assert_match(/str/, @io.string)
73
+ assert_match(/hello/, @io.string)
74
+ assert_equal @io.string, s.to_yaml
75
+ end
76
+
77
+ def test_sequence
78
+ s = Nodes::Stream.new
79
+ doc = Nodes::Document.new
80
+ scalar = Nodes::Scalar.new 'hello world'
81
+ seq = Nodes::Sequence.new
82
+
83
+ seq.children << scalar
84
+ doc.children << seq
85
+ s.children << doc
86
+
87
+ @visitor.accept s
88
+
89
+ assert_match(/- hello/, @io.string)
90
+ assert_equal @io.string, s.to_yaml
91
+ end
92
+
93
+ def test_mapping
94
+ s = Nodes::Stream.new
95
+ doc = Nodes::Document.new
96
+ mapping = Nodes::Mapping.new
97
+ mapping.children << Nodes::Scalar.new('key')
98
+ mapping.children << Nodes::Scalar.new('value')
99
+ doc.children << mapping
100
+ s.children << doc
101
+
102
+ @visitor.accept s
103
+
104
+ assert_match(/key: value/, @io.string)
105
+ assert_equal @io.string, s.to_yaml
106
+ end
107
+
108
+ def test_alias
109
+ s = Nodes::Stream.new
110
+ doc = Nodes::Document.new
111
+ mapping = Nodes::Mapping.new
112
+ mapping.children << Nodes::Scalar.new('key', 'A')
113
+ mapping.children << Nodes::Alias.new('A')
114
+ doc.children << mapping
115
+ s.children << doc
116
+
117
+ @visitor.accept s
118
+
119
+ assert_match(/&A key: \*A/, @io.string)
120
+ assert_equal @io.string, s.to_yaml
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,325 @@
1
+ require_relative '../helper'
2
+
3
+ module Psych
4
+ module Visitors
5
+ class TestToRuby < TestCase
6
+ def setup
7
+ super
8
+ @visitor = ToRuby.new
9
+ end
10
+
11
+ def test_object
12
+ mapping = Nodes::Mapping.new nil, "!ruby/object"
13
+ mapping.children << Nodes::Scalar.new('foo')
14
+ mapping.children << Nodes::Scalar.new('bar')
15
+
16
+ o = mapping.to_ruby
17
+ assert_equal 'bar', o.instance_variable_get(:@foo)
18
+ end
19
+
20
+ def test_awesome
21
+ Psych.load('1900-01-01T00:00:00+00:00')
22
+ end
23
+
24
+ def test_legacy_struct
25
+ foo = Struct.new('AWESOME', :bar)
26
+ assert_equal foo.new('baz'), Psych.load(<<-eoyml)
27
+ !ruby/struct:AWESOME
28
+ bar: baz
29
+ eoyml
30
+ end
31
+
32
+ def test_binary
33
+ 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;"
34
+
35
+ hash = Psych.load(<<-'eoyaml')
36
+ canonical: !!binary "\
37
+ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5\
38
+ OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+\
39
+ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC\
40
+ AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs="
41
+ generic: !binary |
42
+ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
43
+ OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
44
+ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
45
+ AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
46
+ description:
47
+ The binary value above is a tiny arrow encoded as a gif image.
48
+ eoyaml
49
+ assert_equal gif, hash['canonical']
50
+ assert_equal gif, hash['generic']
51
+ end
52
+
53
+ A = Struct.new(:foo)
54
+
55
+ def test_struct
56
+ s = A.new('bar')
57
+
58
+ mapping = Nodes::Mapping.new nil, "!ruby/struct:#{s.class}"
59
+ mapping.children << Nodes::Scalar.new('foo')
60
+ mapping.children << Nodes::Scalar.new('bar')
61
+
62
+ ruby = mapping.to_ruby
63
+
64
+ assert_equal s.class, ruby.class
65
+ assert_equal s.foo, ruby.foo
66
+ assert_equal s, ruby
67
+ end
68
+
69
+ def test_anon_struct_legacy
70
+ s = Struct.new(:foo).new('bar')
71
+
72
+ mapping = Nodes::Mapping.new nil, '!ruby/struct:'
73
+ mapping.children << Nodes::Scalar.new('foo')
74
+ mapping.children << Nodes::Scalar.new('bar')
75
+
76
+ assert_equal s.foo, mapping.to_ruby.foo
77
+ end
78
+
79
+ def test_anon_struct
80
+ s = Struct.new(:foo).new('bar')
81
+
82
+ mapping = Nodes::Mapping.new nil, '!ruby/struct'
83
+ mapping.children << Nodes::Scalar.new('foo')
84
+ mapping.children << Nodes::Scalar.new('bar')
85
+
86
+ assert_equal s.foo, mapping.to_ruby.foo
87
+ end
88
+
89
+ def test_exception
90
+ exc = Exception.new 'hello'
91
+
92
+ mapping = Nodes::Mapping.new nil, '!ruby/exception'
93
+ mapping.children << Nodes::Scalar.new('message')
94
+ mapping.children << Nodes::Scalar.new('hello')
95
+
96
+ ruby = mapping.to_ruby
97
+
98
+ assert_equal exc.class, ruby.class
99
+ assert_equal exc.message, ruby.message
100
+ end
101
+
102
+ def test_regexp
103
+ node = Nodes::Scalar.new('/foo/', nil, '!ruby/regexp')
104
+ assert_equal(/foo/, node.to_ruby)
105
+
106
+ node = Nodes::Scalar.new('/foo/m', nil, '!ruby/regexp')
107
+ assert_equal(/foo/m, node.to_ruby)
108
+
109
+ node = Nodes::Scalar.new('/foo/ix', nil, '!ruby/regexp')
110
+ assert_equal(/foo/ix, node.to_ruby)
111
+ end
112
+
113
+ def test_time
114
+ now = Time.now
115
+ zone = now.strftime('%z')
116
+ zone = " #{zone[0,3]}:#{zone[3,5]}"
117
+
118
+ formatted = now.strftime("%Y-%m-%d %H:%M:%S.%9N") + zone
119
+
120
+ assert_equal now, Nodes::Scalar.new(formatted).to_ruby
121
+ end
122
+
123
+ def test_time_utc
124
+ now = Time.now.utc
125
+ formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
126
+ ".%09dZ" % [now.nsec]
127
+
128
+ assert_equal now, Nodes::Scalar.new(formatted).to_ruby
129
+ end
130
+
131
+ def test_time_utc_no_z
132
+ now = Time.now.utc
133
+ formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
134
+ ".%09d" % [now.nsec]
135
+
136
+ assert_equal now, Nodes::Scalar.new(formatted).to_ruby
137
+ end
138
+
139
+ def test_date
140
+ d = '1980-12-16'
141
+ actual = Date.strptime(d, '%Y-%m-%d')
142
+
143
+ date = Nodes::Scalar.new(d, nil, 'tag:yaml.org,2002:timestamp', false)
144
+
145
+ assert_equal actual, date.to_ruby
146
+ end
147
+
148
+ def test_rational
149
+ mapping = Nodes::Mapping.new nil, '!ruby/object:Rational'
150
+ mapping.children << Nodes::Scalar.new('denominator')
151
+ mapping.children << Nodes::Scalar.new('2')
152
+ mapping.children << Nodes::Scalar.new('numerator')
153
+ mapping.children << Nodes::Scalar.new('1')
154
+
155
+ assert_equal Rational(1,2), mapping.to_ruby
156
+ end
157
+
158
+ def test_complex
159
+ mapping = Nodes::Mapping.new nil, '!ruby/object:Complex'
160
+ mapping.children << Nodes::Scalar.new('image')
161
+ mapping.children << Nodes::Scalar.new('2')
162
+ mapping.children << Nodes::Scalar.new('real')
163
+ mapping.children << Nodes::Scalar.new('1')
164
+
165
+ assert_equal Complex(1,2), mapping.to_ruby
166
+ end
167
+
168
+ if RUBY_VERSION >= '1.9'
169
+ def test_complex_string
170
+ node = Nodes::Scalar.new '3+4i', nil, "!ruby/object:Complex"
171
+ assert_equal Complex(3, 4), node.to_ruby
172
+ end
173
+
174
+ def test_rational_string
175
+ node = Nodes::Scalar.new '1/2', nil, "!ruby/object:Rational"
176
+ assert_equal Rational(1, 2), node.to_ruby
177
+ end
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
+ end
324
+ end
325
+ end
@@ -0,0 +1,149 @@
1
+ require_relative '../helper'
2
+
3
+ module Psych
4
+ module Visitors
5
+ class TestYAMLTree < TestCase
6
+ def setup
7
+ super
8
+ @v = Visitors::YAMLTree.new
9
+ end
10
+
11
+ def test_binary_formatting
12
+ 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;"
13
+ @v << gif
14
+ scalar = @v.tree.children.first.children.first
15
+ assert_equal Psych::Nodes::Scalar::LITERAL, scalar.style
16
+ end
17
+
18
+ def test_object_has_no_class
19
+ yaml = Psych.dump(Object.new)
20
+ assert(Psych.dump(Object.new) !~ /Object/, yaml)
21
+ end
22
+
23
+ def test_struct_const
24
+ foo = Struct.new("Foo", :bar)
25
+ assert_cycle foo.new('bar')
26
+ Struct.instance_eval { remove_const(:Foo) }
27
+ end
28
+
29
+ A = Struct.new(:foo)
30
+
31
+ def test_struct
32
+ assert_cycle A.new('bar')
33
+ end
34
+
35
+ def test_struct_anon
36
+ s = Struct.new(:foo).new('bar')
37
+ obj = Psych.load(Psych.dump(s))
38
+ assert_equal s.foo, obj.foo
39
+ end
40
+
41
+ def test_exception
42
+ ex = Exception.new 'foo'
43
+ loaded = Psych.load(Psych.dump(ex))
44
+
45
+ assert_equal ex.message, loaded.message
46
+ assert_equal ex.class, loaded.class
47
+ end
48
+
49
+ def test_regexp
50
+ assert_cycle(/foo/)
51
+ assert_cycle(/foo/i)
52
+ assert_cycle(/foo/mx)
53
+ end
54
+
55
+ def test_time
56
+ t = Time.now
57
+ assert_equal t, Psych.load(Psych.dump(t))
58
+ end
59
+
60
+ def test_date
61
+ date = Date.strptime('2002-12-14', '%Y-%m-%d')
62
+ assert_cycle date
63
+ end
64
+
65
+ def test_rational
66
+ assert_cycle Rational(1,2)
67
+ end
68
+
69
+ def test_complex
70
+ assert_cycle Complex(1,2)
71
+ end
72
+
73
+ def test_scalar
74
+ assert_cycle 'foo'
75
+ assert_cycle ':foo'
76
+ assert_cycle ''
77
+ assert_cycle ':'
78
+ end
79
+
80
+ def test_boolean
81
+ assert_cycle true
82
+ assert_cycle 'true'
83
+ assert_cycle false
84
+ assert_cycle 'false'
85
+ end
86
+
87
+ def test_range_inclusive
88
+ assert_cycle 1..2
89
+ end
90
+
91
+ def test_range_exclusive
92
+ assert_cycle 1...2
93
+ end
94
+
95
+ def test_anon_class
96
+ assert_raises(TypeError) do
97
+ @v.accept Class.new
98
+ end
99
+
100
+ assert_raises(TypeError) do
101
+ Psych.dump(Class.new)
102
+ end
103
+ end
104
+
105
+ def test_hash
106
+ assert_cycle('a' => 'b')
107
+ end
108
+
109
+ def test_list
110
+ assert_cycle(%w{ a b })
111
+ assert_cycle([1, 2.2])
112
+ end
113
+
114
+ def test_symbol
115
+ assert_cycle :foo
116
+ end
117
+
118
+ def test_int
119
+ assert_cycle 1
120
+ assert_cycle(-1)
121
+ assert_cycle '1'
122
+ assert_cycle '-1'
123
+ end
124
+
125
+ def test_float
126
+ assert_cycle 1.2
127
+ assert_cycle '1.2'
128
+
129
+ assert Psych.load(Psych.dump(0.0 / 0.0)).nan?
130
+ assert_equal 1, Psych.load(Psych.dump(1 / 0.0)).infinite?
131
+ assert_equal(-1, Psych.load(Psych.dump(-1 / 0.0)).infinite?)
132
+ end
133
+
134
+ # http://yaml.org/type/null.html
135
+ def test_nil
136
+ assert_cycle nil
137
+ assert_equal nil, Psych.load('null')
138
+ assert_equal nil, Psych.load('Null')
139
+ assert_equal nil, Psych.load('NULL')
140
+ assert_equal nil, Psych.load('~')
141
+ assert_equal({'foo' => nil}, Psych.load('foo: '))
142
+
143
+ assert_cycle 'null'
144
+ assert_cycle 'nUll'
145
+ assert_cycle '~'
146
+ end
147
+ end
148
+ end
149
+ end