psych 2.0.12 → 5.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +24 -0
  3. data/{ext/psych/yaml/LICENSE → LICENSE} +9 -7
  4. data/README.md +80 -0
  5. data/ext/psych/depend +14 -0
  6. data/ext/psych/extconf.rb +43 -28
  7. data/ext/psych/psych.c +6 -4
  8. data/ext/psych/psych.h +0 -3
  9. data/ext/psych/psych_emitter.c +165 -132
  10. data/ext/psych/psych_parser.c +298 -331
  11. data/ext/psych/psych_to_ruby.c +0 -5
  12. data/ext/psych/psych_yaml_tree.c +0 -13
  13. data/lib/psych/class_loader.rb +11 -8
  14. data/lib/psych/coder.rb +1 -0
  15. data/lib/psych/core_ext.rb +3 -19
  16. data/lib/psych/exception.rb +17 -2
  17. data/lib/psych/handler.rb +8 -2
  18. data/lib/psych/handlers/document_stream.rb +2 -1
  19. data/lib/psych/handlers/recorder.rb +2 -1
  20. data/lib/psych/json/ruby_events.rb +1 -0
  21. data/lib/psych/json/stream.rb +3 -2
  22. data/lib/psych/json/tree_builder.rb +2 -1
  23. data/lib/psych/json/yaml_events.rb +1 -0
  24. data/lib/psych/nodes/alias.rb +3 -0
  25. data/lib/psych/nodes/document.rb +3 -0
  26. data/lib/psych/nodes/mapping.rb +3 -0
  27. data/lib/psych/nodes/node.rb +25 -5
  28. data/lib/psych/nodes/scalar.rb +4 -1
  29. data/lib/psych/nodes/sequence.rb +3 -0
  30. data/lib/psych/nodes/stream.rb +3 -0
  31. data/lib/psych/nodes.rb +8 -7
  32. data/lib/psych/omap.rb +1 -0
  33. data/lib/psych/parser.rb +14 -0
  34. data/lib/psych/scalar_scanner.rb +41 -49
  35. data/lib/psych/set.rb +1 -0
  36. data/lib/psych/stream.rb +1 -0
  37. data/lib/psych/streaming.rb +1 -0
  38. data/lib/psych/syntax_error.rb +2 -1
  39. data/lib/psych/tree_builder.rb +48 -7
  40. data/lib/psych/versions.rb +10 -0
  41. data/lib/psych/visitors/depth_first.rb +1 -0
  42. data/lib/psych/visitors/emitter.rb +1 -0
  43. data/lib/psych/visitors/json_tree.rb +2 -1
  44. data/lib/psych/visitors/to_ruby.rb +64 -33
  45. data/lib/psych/visitors/visitor.rb +18 -3
  46. data/lib/psych/visitors/yaml_tree.rb +128 -149
  47. data/lib/psych/visitors.rb +7 -6
  48. data/lib/psych/y.rb +1 -0
  49. data/lib/psych.rb +360 -95
  50. metadata +36 -169
  51. data/.autotest +0 -18
  52. data/.gemtest +0 -0
  53. data/.travis.yml +0 -11
  54. data/CHANGELOG.rdoc +0 -562
  55. data/Manifest.txt +0 -112
  56. data/README.rdoc +0 -71
  57. data/Rakefile +0 -74
  58. data/ext/psych/yaml/api.c +0 -1415
  59. data/ext/psych/yaml/config.h +0 -10
  60. data/ext/psych/yaml/dumper.c +0 -394
  61. data/ext/psych/yaml/emitter.c +0 -2329
  62. data/ext/psych/yaml/loader.c +0 -459
  63. data/ext/psych/yaml/parser.c +0 -1370
  64. data/ext/psych/yaml/reader.c +0 -469
  65. data/ext/psych/yaml/scanner.c +0 -3583
  66. data/ext/psych/yaml/writer.c +0 -141
  67. data/ext/psych/yaml/yaml.h +0 -1971
  68. data/ext/psych/yaml/yaml_private.h +0 -664
  69. data/lib/psych/deprecated.rb +0 -85
  70. data/test/psych/handlers/test_recorder.rb +0 -25
  71. data/test/psych/helper.rb +0 -114
  72. data/test/psych/json/test_stream.rb +0 -109
  73. data/test/psych/nodes/test_enumerable.rb +0 -43
  74. data/test/psych/test_alias_and_anchor.rb +0 -96
  75. data/test/psych/test_array.rb +0 -57
  76. data/test/psych/test_boolean.rb +0 -36
  77. data/test/psych/test_class.rb +0 -36
  78. data/test/psych/test_coder.rb +0 -184
  79. data/test/psych/test_date_time.rb +0 -38
  80. data/test/psych/test_deprecated.rb +0 -214
  81. data/test/psych/test_document.rb +0 -46
  82. data/test/psych/test_emitter.rb +0 -93
  83. data/test/psych/test_encoding.rb +0 -259
  84. data/test/psych/test_exception.rb +0 -157
  85. data/test/psych/test_hash.rb +0 -94
  86. data/test/psych/test_json_tree.rb +0 -65
  87. data/test/psych/test_marshalable.rb +0 -54
  88. data/test/psych/test_merge_keys.rb +0 -180
  89. data/test/psych/test_nil.rb +0 -18
  90. data/test/psych/test_null.rb +0 -19
  91. data/test/psych/test_numeric.rb +0 -45
  92. data/test/psych/test_object.rb +0 -44
  93. data/test/psych/test_object_references.rb +0 -71
  94. data/test/psych/test_omap.rb +0 -75
  95. data/test/psych/test_parser.rb +0 -339
  96. data/test/psych/test_psych.rb +0 -168
  97. data/test/psych/test_safe_load.rb +0 -97
  98. data/test/psych/test_scalar.rb +0 -11
  99. data/test/psych/test_scalar_scanner.rb +0 -106
  100. data/test/psych/test_serialize_subclasses.rb +0 -38
  101. data/test/psych/test_set.rb +0 -49
  102. data/test/psych/test_stream.rb +0 -93
  103. data/test/psych/test_string.rb +0 -226
  104. data/test/psych/test_struct.rb +0 -49
  105. data/test/psych/test_symbol.rb +0 -25
  106. data/test/psych/test_tainted.rb +0 -130
  107. data/test/psych/test_to_yaml_properties.rb +0 -63
  108. data/test/psych/test_tree_builder.rb +0 -79
  109. data/test/psych/test_yaml.rb +0 -1288
  110. data/test/psych/test_yamldbm.rb +0 -193
  111. data/test/psych/test_yamlstore.rb +0 -85
  112. data/test/psych/visitors/test_depth_first.rb +0 -49
  113. data/test/psych/visitors/test_emitter.rb +0 -144
  114. data/test/psych/visitors/test_to_ruby.rb +0 -326
  115. data/test/psych/visitors/test_yaml_tree.rb +0 -173
@@ -1,1288 +0,0 @@
1
- # -*- coding: us-ascii; mode: ruby; ruby-indent-level: 4; tab-width: 4 -*-
2
- # vim:sw=4:ts=4
3
- # $Id$
4
- #
5
- require_relative 'helper'
6
- require 'ostruct'
7
-
8
- # [ruby-core:01946]
9
- module Psych_Tests
10
- StructTest = Struct::new( :c )
11
- end
12
-
13
- class Psych_Unit_Tests < Psych::TestCase
14
- def teardown
15
- Psych.domain_types.clear
16
- end
17
-
18
- def test_y_method
19
- assert_raises(NoMethodError) do
20
- OpenStruct.new.y 1
21
- end
22
- end
23
-
24
- def test_syck_compat
25
- time = Time.utc(2010, 10, 10)
26
- yaml = Psych.dump time
27
- assert_match "2010-10-10 00:00:00.000000000 Z", yaml
28
- end
29
-
30
- # [ruby-core:34969]
31
- def test_regexp_with_n
32
- assert_cycle(Regexp.new('',0,'n'))
33
- end
34
- #
35
- # Tests modified from 00basic.t in Psych.pm
36
- #
37
- def test_basic_map
38
- # Simple map
39
- assert_parse_only(
40
- { 'one' => 'foo', 'three' => 'baz', 'two' => 'bar' }, <<EOY
41
- one: foo
42
- two: bar
43
- three: baz
44
- EOY
45
- )
46
- end
47
-
48
- def test_basic_strings
49
- # Common string types
50
- assert_cycle("x")
51
- assert_cycle(":x")
52
- assert_cycle(":")
53
- assert_parse_only(
54
- { 1 => 'simple string', 2 => 42, 3 => '1 Single Quoted String',
55
- 4 => 'Psych\'s Double "Quoted" String', 5 => "A block\n with several\n lines.\n",
56
- 6 => "A \"chomped\" block", 7 => "A folded\n string\n", 8 => ": started string" },
57
- <<EOY
58
- 1: simple string
59
- 2: 42
60
- 3: '1 Single Quoted String'
61
- 4: "Psych's Double \\\"Quoted\\\" String"
62
- 5: |
63
- A block
64
- with several
65
- lines.
66
- 6: |-
67
- A "chomped" block
68
- 7: >
69
- A
70
- folded
71
- string
72
- 8: ": started string"
73
- EOY
74
- )
75
- end
76
-
77
- #
78
- # Test the specification examples
79
- # - Many examples have been changes because of whitespace problems that
80
- # caused the two to be inequivalent, or keys to be sorted wrong
81
- #
82
-
83
- def test_spec_simple_implicit_sequence
84
- # Simple implicit sequence
85
- assert_to_yaml(
86
- [ 'Mark McGwire', 'Sammy Sosa', 'Ken Griffey' ], <<EOY
87
- - Mark McGwire
88
- - Sammy Sosa
89
- - Ken Griffey
90
- EOY
91
- )
92
- end
93
-
94
- def test_spec_simple_implicit_map
95
- # Simple implicit map
96
- assert_to_yaml(
97
- { 'hr' => 65, 'avg' => 0.278, 'rbi' => 147 }, <<EOY
98
- avg: 0.278
99
- hr: 65
100
- rbi: 147
101
- EOY
102
- )
103
- end
104
-
105
- def test_spec_simple_map_with_nested_sequences
106
- # Simple mapping with nested sequences
107
- assert_to_yaml(
108
- { 'american' =>
109
- [ 'Boston Red Sox', 'Detroit Tigers', 'New York Yankees' ],
110
- 'national' =>
111
- [ 'New York Mets', 'Chicago Cubs', 'Atlanta Braves' ] }, <<EOY
112
- american:
113
- - Boston Red Sox
114
- - Detroit Tigers
115
- - New York Yankees
116
- national:
117
- - New York Mets
118
- - Chicago Cubs
119
- - Atlanta Braves
120
- EOY
121
- )
122
- end
123
-
124
- def test_spec_simple_sequence_with_nested_map
125
- # Simple sequence with nested map
126
- assert_to_yaml(
127
- [
128
- {'name' => 'Mark McGwire', 'hr' => 65, 'avg' => 0.278},
129
- {'name' => 'Sammy Sosa', 'hr' => 63, 'avg' => 0.288}
130
- ], <<EOY
131
- -
132
- avg: 0.278
133
- hr: 65
134
- name: Mark McGwire
135
- -
136
- avg: 0.288
137
- hr: 63
138
- name: Sammy Sosa
139
- EOY
140
- )
141
- end
142
-
143
- def test_spec_sequence_of_sequences
144
- # Simple sequence with inline sequences
145
- assert_parse_only(
146
- [
147
- [ 'name', 'hr', 'avg' ],
148
- [ 'Mark McGwire', 65, 0.278 ],
149
- [ 'Sammy Sosa', 63, 0.288 ]
150
- ], <<EOY
151
- - [ name , hr , avg ]
152
- - [ Mark McGwire , 65 , 0.278 ]
153
- - [ Sammy Sosa , 63 , 0.288 ]
154
- EOY
155
- )
156
- end
157
-
158
- def test_spec_mapping_of_mappings
159
- # Simple map with inline maps
160
- assert_parse_only(
161
- { 'Mark McGwire' =>
162
- { 'hr' => 65, 'avg' => 0.278 },
163
- 'Sammy Sosa' =>
164
- { 'hr' => 63, 'avg' => 0.288 }
165
- }, <<EOY
166
- Mark McGwire: {hr: 65, avg: 0.278}
167
- Sammy Sosa: {hr: 63,
168
- avg: 0.288}
169
- EOY
170
- )
171
- end
172
-
173
- def test_ambiguous_comments
174
- # [ruby-talk:88012]
175
- assert_to_yaml( "Call the method #dave", <<EOY )
176
- --- "Call the method #dave"
177
- EOY
178
- end
179
-
180
- def test_spec_nested_comments
181
- # Map and sequences with comments
182
- assert_parse_only(
183
- { 'hr' => [ 'Mark McGwire', 'Sammy Sosa' ],
184
- 'rbi' => [ 'Sammy Sosa', 'Ken Griffey' ] }, <<EOY
185
- hr: # 1998 hr ranking
186
- - Mark McGwire
187
- - Sammy Sosa
188
- rbi:
189
- # 1998 rbi ranking
190
- - Sammy Sosa
191
- - Ken Griffey
192
- EOY
193
- )
194
- end
195
-
196
- def test_spec_anchors_and_aliases
197
- # Anchors and aliases
198
- assert_parse_only(
199
- { 'hr' =>
200
- [ 'Mark McGwire', 'Sammy Sosa' ],
201
- 'rbi' =>
202
- [ 'Sammy Sosa', 'Ken Griffey' ] }, <<EOY
203
- hr:
204
- - Mark McGwire
205
- # Name "Sammy Sosa" scalar SS
206
- - &SS Sammy Sosa
207
- rbi:
208
- # So it can be referenced later.
209
- - *SS
210
- - Ken Griffey
211
- EOY
212
- )
213
-
214
- assert_to_yaml(
215
- [{"arrival"=>"EDI", "departure"=>"LAX", "fareref"=>"DOGMA", "currency"=>"GBP"}, {"arrival"=>"MEL", "departure"=>"SYD", "fareref"=>"MADF", "currency"=>"AUD"}, {"arrival"=>"MCO", "departure"=>"JFK", "fareref"=>"DFSF", "currency"=>"USD"}], <<EOY
216
- -
217
- &F fareref: DOGMA
218
- &C currency: GBP
219
- &D departure: LAX
220
- &A arrival: EDI
221
- - { *F: MADF, *C: AUD, *D: SYD, *A: MEL }
222
- - { *F: DFSF, *C: USD, *D: JFK, *A: MCO }
223
- EOY
224
- )
225
-
226
- assert_to_yaml(
227
- {"ALIASES"=>["fareref", "currency", "departure", "arrival"], "FARES"=>[{"arrival"=>"EDI", "departure"=>"LAX", "fareref"=>"DOGMA", "currency"=>"GBP"}, {"arrival"=>"MEL", "departure"=>"SYD", "fareref"=>"MADF", "currency"=>"AUD"}, {"arrival"=>"MCO", "departure"=>"JFK", "fareref"=>"DFSF", "currency"=>"USD"}]}, <<EOY
228
- ---
229
- ALIASES: [&f fareref, &c currency, &d departure, &a arrival]
230
- FARES:
231
- - *f: DOGMA
232
- *c: GBP
233
- *d: LAX
234
- *a: EDI
235
-
236
- - *f: MADF
237
- *c: AUD
238
- *d: SYD
239
- *a: MEL
240
-
241
- - *f: DFSF
242
- *c: USD
243
- *d: JFK
244
- *a: MCO
245
-
246
- EOY
247
- )
248
-
249
- end
250
-
251
- def test_spec_mapping_between_sequences
252
- # Complex key #1
253
- assert_parse_only(
254
- { [ 'Detroit Tigers', 'Chicago Cubs' ] => [ Date.new( 2001, 7, 23 ) ],
255
- [ 'New York Yankees', 'Atlanta Braves' ] => [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ), Date.new( 2001, 8, 14 ) ] }, <<EOY
256
- ? # PLAY SCHEDULE
257
- - Detroit Tigers
258
- - Chicago Cubs
259
- :
260
- - 2001-07-23
261
-
262
- ? [ New York Yankees,
263
- Atlanta Braves ]
264
- : [ 2001-07-02, 2001-08-12,
265
- 2001-08-14 ]
266
- EOY
267
- )
268
-
269
- # Complex key #2
270
- assert_parse_only(
271
- { [ 'New York Yankees', 'Atlanta Braves' ] =>
272
- [ Date.new( 2001, 7, 2 ), Date.new( 2001, 8, 12 ),
273
- Date.new( 2001, 8, 14 ) ],
274
- [ 'Detroit Tigers', 'Chicago Cubs' ] =>
275
- [ Date.new( 2001, 7, 23 ) ]
276
- }, <<EOY
277
- ?
278
- - New York Yankees
279
- - Atlanta Braves
280
- :
281
- - 2001-07-02
282
- - 2001-08-12
283
- - 2001-08-14
284
- ?
285
- - Detroit Tigers
286
- - Chicago Cubs
287
- :
288
- - 2001-07-23
289
- EOY
290
- )
291
- end
292
-
293
- def test_spec_sequence_key_shortcut
294
- # Shortcut sequence map
295
- assert_parse_only(
296
- { 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ),
297
- 'bill-to' => 'Chris Dumars', 'product' =>
298
- [ { 'item' => 'Super Hoop', 'quantity' => 1 },
299
- { 'item' => 'Basketball', 'quantity' => 4 },
300
- { 'item' => 'Big Shoes', 'quantity' => 1 } ] }, <<EOY
301
- invoice: 34843
302
- date : 2001-01-23
303
- bill-to: Chris Dumars
304
- product:
305
- - item : Super Hoop
306
- quantity: 1
307
- - item : Basketball
308
- quantity: 4
309
- - item : Big Shoes
310
- quantity: 1
311
- EOY
312
- )
313
- end
314
-
315
- def test_spec_sequence_in_sequence_shortcut
316
- # Seq-in-seq
317
- assert_parse_only( [ [ [ 'one', 'two', 'three' ] ] ], <<EOY )
318
- - - - one
319
- - two
320
- - three
321
- EOY
322
- end
323
-
324
- def test_spec_sequence_shortcuts
325
- # Sequence shortcuts combined
326
- assert_parse_only(
327
- [
328
- [
329
- [ [ 'one' ] ],
330
- [ 'two', 'three' ],
331
- { 'four' => nil },
332
- [ { 'five' => [ 'six' ] } ],
333
- [ 'seven' ]
334
- ],
335
- [ 'eight', 'nine' ]
336
- ], <<EOY )
337
- - - - - one
338
- - - two
339
- - three
340
- - four:
341
- - - five:
342
- - six
343
- - - seven
344
- - - eight
345
- - nine
346
- EOY
347
- end
348
-
349
- def test_spec_single_literal
350
- # Literal scalar block
351
- assert_parse_only( [ "\\/|\\/|\n/ | |_\n" ], <<EOY )
352
- - |
353
- \\/|\\/|
354
- / | |_
355
- EOY
356
- end
357
-
358
- def test_spec_single_folded
359
- # Folded scalar block
360
- assert_parse_only(
361
- [ "Mark McGwire's year was crippled by a knee injury.\n" ], <<EOY
362
- - >
363
- Mark McGwire\'s
364
- year was crippled
365
- by a knee injury.
366
- EOY
367
- )
368
- end
369
-
370
- def test_spec_preserve_indent
371
- # Preserve indented spaces
372
- assert_parse_only(
373
- "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n", <<EOY
374
- --- >
375
- Sammy Sosa completed another
376
- fine season with great stats.
377
-
378
- 63 Home Runs
379
- 0.288 Batting Average
380
-
381
- What a year!
382
- EOY
383
- )
384
- end
385
-
386
- def test_spec_indentation_determines_scope
387
- assert_parse_only(
388
- { 'name' => 'Mark McGwire', 'accomplishment' => "Mark set a major league home run record in 1998.\n",
389
- 'stats' => "65 Home Runs\n0.278 Batting Average\n" }, <<EOY
390
- name: Mark McGwire
391
- accomplishment: >
392
- Mark set a major league
393
- home run record in 1998.
394
- stats: |
395
- 65 Home Runs
396
- 0.278 Batting Average
397
- EOY
398
- )
399
- end
400
-
401
- def test_spec_multiline_scalars
402
- # Multiline flow scalars
403
- assert_parse_only(
404
- { 'plain' => 'This unquoted scalar spans many lines.',
405
- 'quoted' => "So does this quoted scalar.\n" }, <<EOY
406
- plain: This unquoted
407
- scalar spans
408
- many lines.
409
- quoted: "\\
410
- So does this quoted
411
- scalar.\\n"
412
- EOY
413
- )
414
- end
415
-
416
- def test_spec_type_int
417
- assert_parse_only(
418
- { 'canonical' => 12345, 'decimal' => 12345, 'octal' => '014'.oct, 'hexadecimal' => '0xC'.hex }, <<EOY
419
- canonical: 12345
420
- decimal: +12,345
421
- octal: 014
422
- hexadecimal: 0xC
423
- EOY
424
- )
425
- assert_parse_only(
426
- { 'canonical' => 685230, 'decimal' => 685230, 'octal' => 02472256, 'hexadecimal' => 0x0A74AE, 'sexagesimal' => 685230 }, <<EOY)
427
- canonical: 685230
428
- decimal: +685,230
429
- octal: 02472256
430
- hexadecimal: 0x0A,74,AE
431
- sexagesimal: 190:20:30
432
- EOY
433
- end
434
-
435
- def test_spec_type_float
436
- assert_parse_only(
437
- { 'canonical' => 1230.15, 'exponential' => 1230.15, 'fixed' => 1230.15,
438
- 'negative infinity' => -1.0/0.0 }, <<EOY)
439
- canonical: 1.23015e+3
440
- exponential: 12.3015e+02
441
- fixed: 1,230.15
442
- negative infinity: -.inf
443
- EOY
444
- nan = Psych::load( <<EOY )
445
- not a number: .NaN
446
- EOY
447
- assert( nan['not a number'].nan? )
448
- end
449
-
450
- def test_spec_type_misc
451
- assert_parse_only(
452
- { nil => nil, true => true, false => false, 'string' => '12345' }, <<EOY
453
- null: ~
454
- true: yes
455
- false: no
456
- string: '12345'
457
- EOY
458
- )
459
- end
460
-
461
- def test_spec_complex_invoice
462
- # Complex invoice type
463
- id001 = { 'given' => 'Chris', 'family' => 'Dumars', 'address' =>
464
- { 'lines' => "458 Walkman Dr.\nSuite #292\n", 'city' => 'Royal Oak',
465
- 'state' => 'MI', 'postal' => 48046 } }
466
- assert_parse_only(
467
- { 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ),
468
- 'bill-to' => id001, 'ship-to' => id001, 'product' =>
469
- [ { 'sku' => 'BL394D', 'quantity' => 4,
470
- 'description' => 'Basketball', 'price' => 450.00 },
471
- { 'sku' => 'BL4438H', 'quantity' => 1,
472
- 'description' => 'Super Hoop', 'price' => 2392.00 } ],
473
- 'tax' => 251.42, 'total' => 4443.52,
474
- 'comments' => "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.\n" }, <<EOY
475
- invoice: 34843
476
- date : 2001-01-23
477
- bill-to: &id001
478
- given : Chris
479
- family : !str Dumars
480
- address:
481
- lines: |
482
- 458 Walkman Dr.
483
- Suite #292
484
- city : Royal Oak
485
- state : MI
486
- postal : 48046
487
- ship-to: *id001
488
- product:
489
- - !map
490
- sku : BL394D
491
- quantity : 4
492
- description : Basketball
493
- price : 450.00
494
- - sku : BL4438H
495
- quantity : 1
496
- description : Super Hoop
497
- price : 2392.00
498
- tax : 251.42
499
- total: 4443.52
500
- comments: >
501
- Late afternoon is best.
502
- Backup contact is Nancy
503
- Billsmer @ 338-4338.
504
- EOY
505
- )
506
- end
507
-
508
- def test_spec_log_file
509
- doc_ct = 0
510
- Psych::load_documents( <<EOY
511
- ---
512
- Time: 2001-11-23 15:01:42 -05:00
513
- User: ed
514
- Warning: >
515
- This is an error message
516
- for the log file
517
- ---
518
- Time: 2001-11-23 15:02:31 -05:00
519
- User: ed
520
- Warning: >
521
- A slightly different error
522
- message.
523
- ---
524
- Date: 2001-11-23 15:03:17 -05:00
525
- User: ed
526
- Fatal: >
527
- Unknown variable "bar"
528
- Stack:
529
- - file: TopClass.py
530
- line: 23
531
- code: |
532
- x = MoreObject("345\\n")
533
- - file: MoreClass.py
534
- line: 58
535
- code: |-
536
- foo = bar
537
- EOY
538
- ) { |doc|
539
- case doc_ct
540
- when 0
541
- assert_equal( doc, { 'Time' => mktime( 2001, 11, 23, 15, 01, 42, 00, "-05:00" ),
542
- 'User' => 'ed', 'Warning' => "This is an error message for the log file\n" } )
543
- when 1
544
- assert_equal( doc, { 'Time' => mktime( 2001, 11, 23, 15, 02, 31, 00, "-05:00" ),
545
- 'User' => 'ed', 'Warning' => "A slightly different error message.\n" } )
546
- when 2
547
- assert_equal( doc, { 'Date' => mktime( 2001, 11, 23, 15, 03, 17, 00, "-05:00" ),
548
- 'User' => 'ed', 'Fatal' => "Unknown variable \"bar\"\n",
549
- 'Stack' => [
550
- { 'file' => 'TopClass.py', 'line' => 23, 'code' => "x = MoreObject(\"345\\n\")\n" },
551
- { 'file' => 'MoreClass.py', 'line' => 58, 'code' => "foo = bar" } ] } )
552
- end
553
- doc_ct += 1
554
- }
555
- assert_equal( doc_ct, 3 )
556
- end
557
-
558
- def test_spec_root_fold
559
- y = Psych::load( <<EOY
560
- ---
561
- This Psych stream contains a single text value.
562
- The next stream is a log file - a sequence of
563
- log entries. Adding an entry to the log is a
564
- simple matter of appending it at the end.
565
- EOY
566
- )
567
- assert_equal( y, "This Psych stream contains a single text value. The next stream is a log file - a sequence of log entries. Adding an entry to the log is a simple matter of appending it at the end." )
568
- end
569
-
570
- def test_spec_root_mapping
571
- y = Psych::load( <<EOY
572
- # This stream is an example of a top-level mapping.
573
- invoice : 34843
574
- date : 2001-01-23
575
- total : 4443.52
576
- EOY
577
- )
578
- assert_equal( y, { 'invoice' => 34843, 'date' => Date.new( 2001, 1, 23 ), 'total' => 4443.52 } )
579
- end
580
-
581
- def test_spec_oneline_docs
582
- doc_ct = 0
583
- Psych::load_documents( <<EOY
584
- # The following is a sequence of three documents.
585
- # The first contains an empty mapping, the second
586
- # an empty sequence, and the last an empty string.
587
- --- {}
588
- --- [ ]
589
- --- ''
590
- EOY
591
- ) { |doc|
592
- case doc_ct
593
- when 0
594
- assert_equal( doc, {} )
595
- when 1
596
- assert_equal( doc, [] )
597
- when 2
598
- assert_equal( doc, '' )
599
- end
600
- doc_ct += 1
601
- }
602
- assert_equal( doc_ct, 3 )
603
- end
604
-
605
- def test_spec_domain_prefix
606
- customer_proc = proc { |type, val|
607
- if Hash === val
608
- _, _, type = type.split( ':', 3 )
609
- val['type'] = "domain #{type}"
610
- val
611
- else
612
- raise ArgumentError, "Not a Hash in domain.tld,2002/invoice: " + val.inspect
613
- end
614
- }
615
- Psych.add_domain_type( "domain.tld,2002", 'invoice', &customer_proc )
616
- Psych.add_domain_type( "domain.tld,2002", 'customer', &customer_proc )
617
- assert_parse_only( { "invoice"=> { "customers"=> [ { "given"=>"Chris", "type"=>"domain customer", "family"=>"Dumars" } ], "type"=>"domain invoice" } }, <<EOY
618
- # 'http://domain.tld,2002/invoice' is some type family.
619
- invoice: !domain.tld,2002/invoice
620
- # 'seq' is shorthand for 'http://yaml.org/seq'.
621
- # This does not effect '^customer' below
622
- # because it is does not specify a prefix.
623
- customers: !seq
624
- # '^customer' is shorthand for the full
625
- # notation 'http://domain.tld,2002/customer'.
626
- - !customer
627
- given : Chris
628
- family : Dumars
629
- EOY
630
- )
631
- end
632
-
633
- def test_spec_throwaway
634
- assert_parse_only(
635
- {"this"=>"contains three lines of text.\nThe third one starts with a\n# character. This isn't a comment.\n"}, <<EOY
636
- ### These are four throwaway comment ###
637
-
638
- ### lines (the second line is empty). ###
639
- this: | # Comments may trail lines.
640
- contains three lines of text.
641
- The third one starts with a
642
- # character. This isn't a comment.
643
-
644
- # These are three throwaway comment
645
- # lines (the first line is empty).
646
- EOY
647
- )
648
- end
649
-
650
- def test_spec_force_implicit
651
- # Force implicit
652
- assert_parse_only(
653
- { 'integer' => 12, 'also int' => 12, 'string' => '12' }, <<EOY
654
- integer: 12
655
- also int: ! "12"
656
- string: !str 12
657
- EOY
658
- )
659
- end
660
-
661
- ###
662
- # Commenting out this test. This line:
663
- #
664
- # - !domain.tld,2002/type\\x30 value
665
- #
666
- # Is invalid according to the YAML spec:
667
- #
668
- # http://yaml.org/spec/1.1/#id896876
669
- #
670
- # def test_spec_url_escaping
671
- # Psych.add_domain_type( "domain.tld,2002", "type0" ) { |type, val|
672
- # "ONE: #{val}"
673
- # }
674
- # Psych.add_domain_type( "domain.tld,2002", "type%30" ) { |type, val|
675
- # "TWO: #{val}"
676
- # }
677
- # assert_parse_only(
678
- # { 'same' => [ 'ONE: value', 'ONE: value' ], 'different' => [ 'TWO: value' ] }, <<EOY
679
- #same:
680
- # - !domain.tld,2002/type\\x30 value
681
- # - !domain.tld,2002/type0 value
682
- #different: # As far as the Psych parser is concerned
683
- # - !domain.tld,2002/type%30 value
684
- #EOY
685
- # )
686
- # end
687
-
688
- def test_spec_override_anchor
689
- # Override anchor
690
- a001 = "The alias node below is a repeated use of this value.\n"
691
- assert_parse_only(
692
- { 'anchor' => 'This scalar has an anchor.', 'override' => a001, 'alias' => a001 }, <<EOY
693
- anchor : &A001 This scalar has an anchor.
694
- override : &A001 >
695
- The alias node below is a
696
- repeated use of this value.
697
- alias : *A001
698
- EOY
699
- )
700
- end
701
-
702
- def test_spec_explicit_families
703
- Psych.add_domain_type( "somewhere.com,2002", 'type' ) { |type, val|
704
- "SOMEWHERE: #{val}"
705
- }
706
- assert_parse_only(
707
- { 'not-date' => '2002-04-28', 'picture' => "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236i^\020' \202\n\001\000;", 'hmm' => "SOMEWHERE: family above is short for\nhttp://somewhere.com/type\n" }, <<EOY
708
- not-date: !str 2002-04-28
709
- picture: !binary |
710
- R0lGODlhDAAMAIQAAP//9/X
711
- 17unp5WZmZgAAAOfn515eXv
712
- Pz7Y6OjuDg4J+fn5OTk6enp
713
- 56enmleECcgggoBADs=
714
-
715
- hmm: !somewhere.com,2002/type |
716
- family above is short for
717
- http://somewhere.com/type
718
- EOY
719
- )
720
- end
721
-
722
- def test_spec_application_family
723
- # Testing the clarkevans.com graphs
724
- Psych.add_domain_type( "clarkevans.com,2002", 'graph/shape' ) { |type, val|
725
- if Array === val
726
- val << "Shape Container"
727
- val
728
- else
729
- raise ArgumentError, "Invalid graph of type #{val.class}: " + val.inspect
730
- end
731
- }
732
- one_shape_proc = Proc.new { |type, val|
733
- if Hash === val
734
- type = type.split( /:/ )
735
- val['TYPE'] = "Shape: #{type[2]}"
736
- val
737
- else
738
- raise ArgumentError, "Invalid graph of type #{val.class}: " + val.inspect
739
- end
740
- }
741
- Psych.add_domain_type( "clarkevans.com,2002", 'graph/circle', &one_shape_proc )
742
- Psych.add_domain_type( "clarkevans.com,2002", 'graph/line', &one_shape_proc )
743
- Psych.add_domain_type( "clarkevans.com,2002", 'graph/text', &one_shape_proc )
744
- # MODIFIED to remove invalid Psych
745
- assert_parse_only(
746
- [[{"radius"=>7, "center"=>{"x"=>73, "y"=>129}, "TYPE"=>"Shape: graph/circle"}, {"finish"=>{"x"=>89, "y"=>102}, "TYPE"=>"Shape: graph/line", "start"=>{"x"=>73, "y"=>129}}, {"TYPE"=>"Shape: graph/text", "value"=>"Pretty vector drawing.", "start"=>{"x"=>73, "y"=>129}, "color"=>16772795}, "Shape Container"]], <<EOY
747
- - !clarkevans.com,2002/graph/shape
748
- - !/graph/circle
749
- center: &ORIGIN {x: 73, y: 129}
750
- radius: 7
751
- - !/graph/line # !clarkevans.com,2002/graph/line
752
- start: *ORIGIN
753
- finish: { x: 89, y: 102 }
754
- - !/graph/text
755
- start: *ORIGIN
756
- color: 0xFFEEBB
757
- value: Pretty vector drawing.
758
- EOY
759
- )
760
- end
761
-
762
- def test_spec_float_explicit
763
- assert_parse_only(
764
- [ 10.0, 10.0, 10.0, 10.0 ], <<EOY
765
- # All entries in the sequence
766
- # have the same type and value.
767
- - 10.0
768
- - !float 10
769
- - !yaml.org,2002/float '10'
770
- - !yaml.org,2002/float "\\
771
- 1\\
772
- 0"
773
- EOY
774
- )
775
- end
776
-
777
- def test_spec_builtin_seq
778
- # Assortment of sequences
779
- assert_parse_only(
780
- { 'empty' => [], 'in-line' => [ 'one', 'two', 'three', 'four', 'five' ],
781
- 'nested' => [ 'First item in top sequence', [ 'Subordinate sequence entry' ],
782
- "A multi-line sequence entry\n", 'Sixth item in top sequence' ] }, <<EOY
783
- empty: []
784
- in-line: [ one, two, three # May span lines,
785
- , four, # indentation is
786
- five ] # mostly ignored.
787
- nested:
788
- - First item in top sequence
789
- -
790
- - Subordinate sequence entry
791
- - >
792
- A multi-line
793
- sequence entry
794
- - Sixth item in top sequence
795
- EOY
796
- )
797
- end
798
-
799
- def test_spec_builtin_map
800
- # Assortment of mappings
801
- assert_parse_only(
802
- { 'empty' => {}, 'in-line' => { 'one' => 1, 'two' => 2 },
803
- 'spanning' => { 'one' => 1, 'two' => 2 },
804
- 'nested' => { 'first' => 'First entry', 'second' =>
805
- { 'key' => 'Subordinate mapping' }, 'third' =>
806
- [ 'Subordinate sequence', {}, 'Previous mapping is empty.',
807
- { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' },
808
- 'The previous entry is equal to the following one.',
809
- { 'A key' => 'value pair in a sequence.', 'A second' => 'key:value pair.' } ],
810
- 12.0 => 'This key is a float.', "?\n" => 'This key had to be protected.',
811
- "\a" => 'This key had to be escaped.',
812
- "This is a multi-line folded key\n" => "Whose value is also multi-line.\n",
813
- [ 'This key', 'is a sequence' ] => [ 'With a sequence value.' ] } }, <<EOY
814
-
815
- empty: {}
816
- in-line: { one: 1, two: 2 }
817
- spanning: { one: 1,
818
- two: 2 }
819
- nested:
820
- first : First entry
821
- second:
822
- key: Subordinate mapping
823
- third:
824
- - Subordinate sequence
825
- - { }
826
- - Previous mapping is empty.
827
- - A key: value pair in a sequence.
828
- A second: key:value pair.
829
- - The previous entry is equal to the following one.
830
- -
831
- A key: value pair in a sequence.
832
- A second: key:value pair.
833
- !float 12 : This key is a float.
834
- ? >
835
- ?
836
- : This key had to be protected.
837
- "\\a" : This key had to be escaped.
838
- ? >
839
- This is a
840
- multi-line
841
- folded key
842
- : >
843
- Whose value is
844
- also multi-line.
845
- ?
846
- - This key
847
- - is a sequence
848
- :
849
- - With a sequence value.
850
- # The following parses correctly,
851
- # but Ruby 1.6.* fails the comparison!
852
- # ?
853
- # This: key
854
- # is a: mapping
855
- # :
856
- # with a: mapping value.
857
- EOY
858
- )
859
- end
860
-
861
- def test_spec_builtin_literal_blocks
862
- # Assortment of literal scalar blocks
863
- assert_parse_only(
864
- {"both are equal to"=>" This has no newline.", "is equal to"=>"The \\ ' \" characters may be\nfreely used. Leading white\n space is significant.\n\nLine breaks are significant.\nThus this value contains one\nempty line and ends with a\nsingle line break, but does\nnot start with one.\n", "also written as"=>" This has no newline.", "indented and chomped"=>" This has no newline.", "empty"=>"", "literal"=>"The \\ ' \" characters may be\nfreely used. Leading white\n space is significant.\n\nLine breaks are significant.\nThus this value contains one\nempty line and ends with a\nsingle line break, but does\nnot start with one.\n"}, <<EOY
865
- empty: |
866
-
867
- literal: |
868
- The \\\ ' " characters may be
869
- freely used. Leading white
870
- space is significant.
871
-
872
- Line breaks are significant.
873
- Thus this value contains one
874
- empty line and ends with a
875
- single line break, but does
876
- not start with one.
877
-
878
- is equal to: "The \\\\ ' \\" characters may \\
879
- be\\nfreely used. Leading white\\n space \\
880
- is significant.\\n\\nLine breaks are \\
881
- significant.\\nThus this value contains \\
882
- one\\nempty line and ends with a\\nsingle \\
883
- line break, but does\\nnot start with one.\\n"
884
-
885
- # Comments may follow a nested
886
- # scalar value. They must be
887
- # less indented.
888
-
889
- # Modifiers may be combined in any order.
890
- indented and chomped: |2-
891
- This has no newline.
892
-
893
- also written as: |-2
894
- This has no newline.
895
-
896
- both are equal to: " This has no newline."
897
- EOY
898
- )
899
-
900
- str1 = "This has one newline.\n"
901
- str2 = "This has no newline."
902
- str3 = "This has two newlines.\n\n"
903
- assert_parse_only(
904
- { 'clipped' => str1, 'same as "clipped" above' => str1,
905
- 'stripped' => str2, 'same as "stripped" above' => str2,
906
- 'kept' => str3, 'same as "kept" above' => str3 }, <<EOY
907
- clipped: |
908
- This has one newline.
909
-
910
- same as "clipped" above: "This has one newline.\\n"
911
-
912
- stripped: |-
913
- This has no newline.
914
-
915
- same as "stripped" above: "This has no newline."
916
-
917
- kept: |+
918
- This has two newlines.
919
-
920
- same as "kept" above: "This has two newlines.\\n\\n"
921
-
922
- EOY
923
- )
924
- end
925
-
926
- def test_spec_span_single_quote
927
- assert_parse_only( {"third"=>"a single quote ' must be escaped.", "second"=>"! : \\ etc. can be used freely.", "is same as"=>"this contains six spaces\nand one line break", "empty"=>"", "span"=>"this contains six spaces\nand one line break"}, <<EOY
928
- empty: ''
929
- second: '! : \\ etc. can be used freely.'
930
- third: 'a single quote '' must be escaped.'
931
- span: 'this contains
932
- six spaces
933
-
934
- and one
935
- line break'
936
- is same as: "this contains six spaces\\nand one line break"
937
- EOY
938
- )
939
- end
940
-
941
- def test_spec_span_double_quote
942
- assert_parse_only( {"is equal to"=>"this contains four spaces", "third"=>"a \" or a \\ must be escaped.", "second"=>"! : etc. can be used freely.", "empty"=>"", "fourth"=>"this value ends with an LF.\n", "span"=>"this contains four spaces"}, <<EOY
943
- empty: ""
944
- second: "! : etc. can be used freely."
945
- third: "a \\\" or a \\\\ must be escaped."
946
- fourth: "this value ends with an LF.\\n"
947
- span: "this contains
948
- four \\
949
- spaces"
950
- is equal to: "this contains four spaces"
951
- EOY
952
- )
953
- end
954
-
955
- def test_spec_builtin_time
956
- # Time
957
- assert_parse_only(
958
- { "space separated" => mktime( 2001, 12, 14, 21, 59, 43, ".10", "-05:00" ),
959
- "canonical" => mktime( 2001, 12, 15, 2, 59, 43, ".10" ),
960
- "date (noon UTC)" => Date.new( 2002, 12, 14),
961
- "valid iso8601" => mktime( 2001, 12, 14, 21, 59, 43, ".10", "-05:00" ) }, <<EOY
962
- canonical: 2001-12-15T02:59:43.1Z
963
- valid iso8601: 2001-12-14t21:59:43.10-05:00
964
- space separated: 2001-12-14 21:59:43.10 -05:00
965
- date (noon UTC): 2002-12-14
966
- EOY
967
- )
968
- end
969
-
970
- def test_spec_builtin_binary
971
- arrow_gif = "GIF89a\f\000\f\000\204\000\000\377\377\367\365\365\356\351\351\345fff\000\000\000\347\347\347^^^\363\363\355\216\216\216\340\340\340\237\237\237\223\223\223\247\247\247\236\236\236iiiccc\243\243\243\204\204\204\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371\377\376\371!\376\016Made with GIMP\000,\000\000\000\000\f\000\f\000\000\005, \216\2010\236\343@\024\350i\020\304\321\212\010\034\317\200M$z\357\3770\205p\270\2601f\r\e\316\001\303\001\036\020' \202\n\001\000;"
972
- assert_parse_only(
973
- { 'canonical' => arrow_gif, 'base64' => arrow_gif,
974
- 'description' => "The binary value above is a tiny arrow encoded as a gif image.\n" }, <<EOY
975
- canonical: !binary "\\
976
- R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOf\\
977
- n515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaW\\
978
- NjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++\\
979
- f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUg\\
980
- d2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuN\\
981
- AFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84Bww\\
982
- EeECcgggoBADs="
983
- base64: !binary |
984
- R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOf
985
- n515eXvPz7Y6OjuDg4J+fn5OTk6enp56enmlpaW
986
- NjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++
987
- f/++f/++f/++f/++f/++f/++f/++SH+Dk1hZGUg
988
- d2l0aCBHSU1QACwAAAAADAAMAAAFLCAgjoEwnuN
989
- AFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84Bww
990
- EeECcgggoBADs=
991
- description: >
992
- The binary value above is a tiny arrow
993
- encoded as a gif image.
994
- EOY
995
- )
996
- end
997
- def test_ruby_regexp
998
- # Test Ruby regular expressions
999
- assert_to_yaml(
1000
- { 'simple' => /a.b/, 'complex' => %r'\A"((?:[^"]|\")+)"',
1001
- 'case-insensitive' => /George McFly/i }, <<EOY
1002
- case-insensitive: !ruby/regexp "/George McFly/i"
1003
- complex: !ruby/regexp "/\\\\A\\"((?:[^\\"]|\\\\\\")+)\\"/"
1004
- simple: !ruby/regexp "/a.b/"
1005
- EOY
1006
- )
1007
- end
1008
-
1009
- #
1010
- # Test of Ranges
1011
- #
1012
- def test_ranges
1013
-
1014
- # Simple numeric
1015
- assert_to_yaml( 1..3, <<EOY )
1016
- --- !ruby/range 1..3
1017
- EOY
1018
-
1019
- # Simple alphabetic
1020
- assert_to_yaml( 'a'..'z', <<EOY )
1021
- --- !ruby/range a..z
1022
- EOY
1023
-
1024
- # Float
1025
- assert_to_yaml( 10.5...30.3, <<EOY )
1026
- --- !ruby/range 10.5...30.3
1027
- EOY
1028
-
1029
- end
1030
-
1031
- def test_ruby_struct
1032
- # Ruby structures
1033
- book_struct = Struct::new( "MyBookStruct", :author, :title, :year, :isbn )
1034
- assert_to_yaml(
1035
- [ book_struct.new( "Yukihiro Matsumoto", "Ruby in a Nutshell", 2002, "0-596-00214-9" ),
1036
- book_struct.new( [ 'Dave Thomas', 'Andy Hunt' ], "The Pickaxe", 2002,
1037
- book_struct.new( "This should be the ISBN", "but I have another struct here", 2002, "None" )
1038
- ) ], <<EOY
1039
- - !ruby/struct:MyBookStruct
1040
- author: Yukihiro Matsumoto
1041
- title: Ruby in a Nutshell
1042
- year: 2002
1043
- isbn: 0-596-00214-9
1044
- - !ruby/struct:MyBookStruct
1045
- author:
1046
- - Dave Thomas
1047
- - Andy Hunt
1048
- title: The Pickaxe
1049
- year: 2002
1050
- isbn: !ruby/struct:MyBookStruct
1051
- author: This should be the ISBN
1052
- title: but I have another struct here
1053
- year: 2002
1054
- isbn: None
1055
- EOY
1056
- )
1057
-
1058
- assert_to_yaml( Psych_Tests::StructTest.new( 123 ), <<EOY )
1059
- --- !ruby/struct:Psych_Tests::StructTest
1060
- c: 123
1061
- EOY
1062
-
1063
- end
1064
-
1065
- def test_ruby_rational
1066
- assert_to_yaml( Rational(1, 2), <<EOY )
1067
- --- !ruby/object:Rational
1068
- numerator: 1
1069
- denominator: 2
1070
- EOY
1071
-
1072
- # Read Psych dumped by the ruby 1.8.3.
1073
- assert_to_yaml( Rational(1, 2), "!ruby/object:Rational 1/2\n" )
1074
- assert_raises( ArgumentError ) { Psych.load("!ruby/object:Rational INVALID/RATIONAL\n") }
1075
- end
1076
-
1077
- def test_ruby_complex
1078
- assert_to_yaml( Complex(3, 4), <<EOY )
1079
- --- !ruby/object:Complex
1080
- image: 4
1081
- real: 3
1082
- EOY
1083
-
1084
- # Read Psych dumped by the ruby 1.8.3.
1085
- assert_to_yaml( Complex(3, 4), "!ruby/object:Complex 3+4i\n" )
1086
- assert_raises( ArgumentError ) { Psych.load("!ruby/object:Complex INVALID+COMPLEXi\n") }
1087
- end
1088
-
1089
- def test_emitting_indicators
1090
- assert_to_yaml( "Hi, from Object 1. You passed: please, pretty please", <<EOY
1091
- --- "Hi, from Object 1. You passed: please, pretty please"
1092
- EOY
1093
- )
1094
- end
1095
-
1096
- ##
1097
- ## Test the Psych::Stream class -- INACTIVE at the moment
1098
- ##
1099
- #def test_document
1100
- # y = Psych::Stream.new( :Indent => 2, :UseVersion => 0 )
1101
- # y.add(
1102
- # { 'hi' => 'hello', 'map' =>
1103
- # { 'good' => 'two' },
1104
- # 'time' => Time.now,
1105
- # 'try' => /^po(.*)$/,
1106
- # 'bye' => 'goodbye'
1107
- # }
1108
- # )
1109
- # y.add( { 'po' => 'nil', 'oper' => 90 } )
1110
- # y.add( { 'hi' => 'wow!', 'bye' => 'wow!' } )
1111
- # y.add( { [ 'Red Socks', 'Boston' ] => [ 'One', 'Two', 'Three' ] } )
1112
- # y.add( [ true, false, false ] )
1113
- #end
1114
-
1115
- #
1116
- # Test YPath choices parsing
1117
- #
1118
- #def test_ypath_parsing
1119
- # assert_path_segments( "/*/((one|three)/name|place)|//place",
1120
- # [ ["*", "one", "name"],
1121
- # ["*", "three", "name"],
1122
- # ["*", "place"],
1123
- # ["/", "place"] ]
1124
- # )
1125
- #end
1126
-
1127
- #
1128
- # Tests from Tanaka Akira on [ruby-core]
1129
- #
1130
- def test_akira
1131
-
1132
- # Commas in plain scalars [ruby-core:1066]
1133
- assert_to_yaml(
1134
- {"A"=>"A,","B"=>"B"}, <<EOY
1135
- A: "A,"
1136
- B: B
1137
- EOY
1138
- )
1139
-
1140
- # Double-quoted keys [ruby-core:1069]
1141
- assert_to_yaml(
1142
- {"1"=>2, "2"=>3}, <<EOY
1143
- '1': 2
1144
- "2": 3
1145
- EOY
1146
- )
1147
-
1148
- # Anchored mapping [ruby-core:1071]
1149
- assert_to_yaml(
1150
- [{"a"=>"b"}] * 2, <<EOY
1151
- - &id001
1152
- a: b
1153
- - *id001
1154
- EOY
1155
- )
1156
-
1157
- # Stress test [ruby-core:1071]
1158
- # a = []; 1000.times { a << {"a"=>"b", "c"=>"d"} }
1159
- # Psych::load( a.to_yaml )
1160
-
1161
- end
1162
-
1163
- #
1164
- # Test Time.now cycle
1165
- #
1166
- def test_time_now_cycle
1167
- #
1168
- # From Minero Aoki [ruby-core:2305]
1169
- #
1170
- #require 'yaml'
1171
- t = Time.now
1172
- t = Time.at(t.tv_sec, t.tv_usec)
1173
- 5.times do
1174
- assert_cycle(t)
1175
- end
1176
- end
1177
-
1178
- #
1179
- # Test Range cycle
1180
- #
1181
- def test_range_cycle
1182
- #
1183
- # From Minero Aoki [ruby-core:02306]
1184
- #
1185
- assert_cycle("a".."z")
1186
-
1187
- #
1188
- # From Nobu Nakada [ruby-core:02311]
1189
- #
1190
- assert_cycle(0..1)
1191
- assert_cycle(1.0e20 .. 2.0e20)
1192
- assert_cycle("0".."1")
1193
- assert_cycle(".."..."...")
1194
- assert_cycle(".rb"..".pl")
1195
- assert_cycle(".rb"...".pl")
1196
- assert_cycle('"'...".")
1197
- assert_cycle("'"...".")
1198
- end
1199
-
1200
- #
1201
- # Circular references
1202
- #
1203
- def test_circular_references
1204
- a = []; a[0] = a; a[1] = a
1205
- inspect_str = "[[...], [...]]"
1206
- assert_equal( inspect_str, Psych::load(Psych.dump(a)).inspect )
1207
- end
1208
-
1209
- #
1210
- # Test Symbol cycle
1211
- #
1212
- def test_symbol_cycle
1213
- #
1214
- # From Aaron Schrab [ruby-Bugs:2535]
1215
- #
1216
- assert_cycle(:"^foo")
1217
- end
1218
-
1219
- #
1220
- # Test Numeric cycle
1221
- #
1222
- class NumericTest < Numeric
1223
- def initialize(value)
1224
- @value = value
1225
- end
1226
- def ==(other)
1227
- @value == other.instance_eval{ @value }
1228
- end
1229
- end
1230
- def test_numeric_cycle
1231
- assert_cycle(1) # Fixnum
1232
- assert_cycle(111111111111111111111111111111111) # Bignum
1233
- assert_cycle(NumericTest.new(3)) # Subclass of Numeric
1234
- end
1235
-
1236
- #
1237
- # Test empty map/seq in map cycle
1238
- #
1239
- def test_empty_map_key
1240
- #
1241
- # empty seq as key
1242
- #
1243
- assert_cycle({[]=>""})
1244
-
1245
- #
1246
- # empty map as key
1247
- #
1248
- assert_cycle({{}=>""})
1249
- end
1250
-
1251
- #
1252
- # contributed by riley lynch [ruby-Bugs-8548]
1253
- #
1254
- def test_object_id_collision
1255
- omap = Psych::Omap.new
1256
- 1000.times { |i| omap["key_#{i}"] = { "value" => i } }
1257
- raise "id collision in ordered map" if Psych.dump(omap) =~ /id\d+/
1258
- end
1259
-
1260
- def test_date_out_of_range
1261
- Psych::load('1900-01-01T00:00:00+00:00')
1262
- end
1263
-
1264
- def test_normal_exit
1265
- Psych.load("2000-01-01 00:00:00.#{"0"*1000} +00:00\n")
1266
- # '[ruby-core:13735]'
1267
- end
1268
-
1269
- def test_multiline_string_uses_literal_style
1270
- yaml = Psych.dump("multi\nline\nstring")
1271
- assert_match("|", yaml)
1272
- end
1273
-
1274
- def test_string_starting_with_non_word_character_uses_double_quotes_without_exclamation_mark
1275
- yaml = Psych.dump("@123'abc")
1276
- refute_match("!", yaml)
1277
- end
1278
-
1279
- def test_string_dump_with_colon
1280
- yaml = Psych.dump 'x: foo'
1281
- refute_match '!', yaml
1282
- end
1283
-
1284
- def test_string_dump_starting_with_star
1285
- yaml = Psych.dump '*foo'
1286
- refute_match '!', yaml
1287
- end
1288
- end