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,339 +0,0 @@
1
- # coding: utf-8
2
-
3
- require_relative 'helper'
4
-
5
- module Psych
6
- class TestParser < TestCase
7
- class EventCatcher < Handler
8
- attr_accessor :parser
9
- attr_reader :calls, :marks
10
- def initialize
11
- @parser = nil
12
- @calls = []
13
- @marks = []
14
- end
15
-
16
- (Handler.instance_methods(true) -
17
- Object.instance_methods).each do |m|
18
- class_eval %{
19
- def #{m} *args
20
- super
21
- @marks << @parser.mark if @parser
22
- @calls << [:#{m}, args]
23
- end
24
- }
25
- end
26
- end
27
-
28
- def setup
29
- super
30
- @handler = EventCatcher.new
31
- @parser = Psych::Parser.new @handler
32
- @handler.parser = @parser
33
- end
34
-
35
- def test_ast_roundtrip
36
- parser = Psych.parser
37
- parser.parse('null')
38
- ast = parser.handler.root
39
- assert_match(/^null/, ast.yaml)
40
- end
41
-
42
- def test_exception_memory_leak
43
- yaml = <<-eoyaml
44
- %YAML 1.1
45
- %TAG ! tag:tenderlovemaking.com,2009:
46
- --- &ponies
47
- - first element
48
- - *ponies
49
- - foo: bar
50
- ...
51
- eoyaml
52
-
53
- [:start_stream, :start_document, :end_document, :alias, :scalar,
54
- :start_sequence, :end_sequence, :start_mapping, :end_mapping,
55
- :end_stream].each do |method|
56
-
57
- klass = Class.new(Psych::Handler) do
58
- define_method(method) do |*args|
59
- raise
60
- end
61
- end
62
-
63
- parser = Psych::Parser.new klass.new
64
- 2.times {
65
- assert_raises(RuntimeError, method.to_s) do
66
- parser.parse yaml
67
- end
68
- }
69
- end
70
- end
71
-
72
- def test_multiparse
73
- 3.times do
74
- @parser.parse '--- foo'
75
- end
76
- end
77
-
78
- def test_filename
79
- ex = assert_raises(Psych::SyntaxError) do
80
- @parser.parse '--- `', 'omg!'
81
- end
82
- assert_match 'omg!', ex.message
83
- end
84
-
85
- def test_line_numbers
86
- assert_equal 0, @parser.mark.line
87
- @parser.parse "---\n- hello\n- world"
88
- line_calls = @handler.marks.map(&:line).zip(@handler.calls.map(&:first))
89
- assert_equal [[0, :start_stream],
90
- [0, :start_document],
91
- [1, :start_sequence],
92
- [2, :scalar],
93
- [3, :scalar],
94
- [3, :end_sequence],
95
- [3, :end_document],
96
- [3, :end_stream]], line_calls
97
-
98
- assert_equal 3, @parser.mark.line
99
- end
100
-
101
- def test_column_numbers
102
- assert_equal 0, @parser.mark.column
103
- @parser.parse "---\n- hello\n- world"
104
- col_calls = @handler.marks.map(&:column).zip(@handler.calls.map(&:first))
105
- assert_equal [[0, :start_stream],
106
- [3, :start_document],
107
- [1, :start_sequence],
108
- [0, :scalar],
109
- [0, :scalar],
110
- [0, :end_sequence],
111
- [0, :end_document],
112
- [0, :end_stream]], col_calls
113
-
114
- assert_equal 0, @parser.mark.column
115
- end
116
-
117
- def test_index_numbers
118
- assert_equal 0, @parser.mark.index
119
- @parser.parse "---\n- hello\n- world"
120
- idx_calls = @handler.marks.map(&:index).zip(@handler.calls.map(&:first))
121
- assert_equal [[0, :start_stream],
122
- [3, :start_document],
123
- [5, :start_sequence],
124
- [12, :scalar],
125
- [19, :scalar],
126
- [19, :end_sequence],
127
- [19, :end_document],
128
- [19, :end_stream]], idx_calls
129
-
130
- assert_equal 19, @parser.mark.index
131
- end
132
-
133
- def test_bom
134
- tadpole = 'おたまじゃくし'
135
-
136
- # BOM + text
137
- yml = "\uFEFF#{tadpole}".encode('UTF-16LE')
138
- @parser.parse yml
139
- assert_equal tadpole, @parser.handler.calls[2][1].first
140
- end
141
-
142
- def test_external_encoding
143
- tadpole = 'おたまじゃくし'
144
-
145
- @parser.external_encoding = Psych::Parser::UTF16LE
146
- @parser.parse tadpole.encode 'UTF-16LE'
147
- assert_equal tadpole, @parser.handler.calls[2][1].first
148
- end
149
-
150
- def test_bogus_io
151
- o = Object.new
152
- def o.external_encoding; nil end
153
- def o.read len; self end
154
-
155
- assert_raises(TypeError) do
156
- @parser.parse o
157
- end
158
- end
159
-
160
- def test_parse_io
161
- @parser.parse StringIO.new("--- a")
162
- assert_called :start_stream
163
- assert_called :scalar
164
- assert_called :end_stream
165
- end
166
-
167
- def test_syntax_error
168
- assert_raises(Psych::SyntaxError) do
169
- @parser.parse("---\n\"foo\"\n\"bar\"\n")
170
- end
171
- end
172
-
173
- def test_syntax_error_twice
174
- assert_raises(Psych::SyntaxError) do
175
- @parser.parse("---\n\"foo\"\n\"bar\"\n")
176
- end
177
-
178
- assert_raises(Psych::SyntaxError) do
179
- @parser.parse("---\n\"foo\"\n\"bar\"\n")
180
- end
181
- end
182
-
183
- def test_syntax_error_has_path_for_string
184
- e = assert_raises(Psych::SyntaxError) do
185
- @parser.parse("---\n\"foo\"\n\"bar\"\n")
186
- end
187
- assert_match '(<unknown>):', e.message
188
- end
189
-
190
- def test_syntax_error_has_path_for_io
191
- io = StringIO.new "---\n\"foo\"\n\"bar\"\n"
192
- def io.path; "hello!"; end
193
-
194
- e = assert_raises(Psych::SyntaxError) do
195
- @parser.parse(io)
196
- end
197
- assert_match "(#{io.path}):", e.message
198
- end
199
-
200
- def test_mapping_end
201
- @parser.parse("---\n!!map { key: value }")
202
- assert_called :end_mapping
203
- end
204
-
205
- def test_mapping_tag
206
- @parser.parse("---\n!!map { key: value }")
207
- assert_called :start_mapping, ["tag:yaml.org,2002:map", false, Nodes::Mapping::FLOW]
208
- end
209
-
210
- def test_mapping_anchor
211
- @parser.parse("---\n&A { key: value }")
212
- assert_called :start_mapping, ['A', true, Nodes::Mapping::FLOW]
213
- end
214
-
215
- def test_mapping_block
216
- @parser.parse("---\n key: value")
217
- assert_called :start_mapping, [true, Nodes::Mapping::BLOCK]
218
- end
219
-
220
- def test_mapping_start
221
- @parser.parse("---\n{ key: value }")
222
- assert_called :start_mapping
223
- assert_called :start_mapping, [true, Nodes::Mapping::FLOW]
224
- end
225
-
226
- def test_sequence_end
227
- @parser.parse("---\n&A [1, 2]")
228
- assert_called :end_sequence
229
- end
230
-
231
- def test_sequence_start_anchor
232
- @parser.parse("---\n&A [1, 2]")
233
- assert_called :start_sequence, ["A", true, Nodes::Sequence::FLOW]
234
- end
235
-
236
- def test_sequence_start_tag
237
- @parser.parse("---\n!!seq [1, 2]")
238
- assert_called :start_sequence, ["tag:yaml.org,2002:seq", false, Nodes::Sequence::FLOW]
239
- end
240
-
241
- def test_sequence_start_flow
242
- @parser.parse("---\n[1, 2]")
243
- assert_called :start_sequence, [true, Nodes::Sequence::FLOW]
244
- end
245
-
246
- def test_sequence_start_block
247
- @parser.parse("---\n - 1\n - 2")
248
- assert_called :start_sequence, [true, Nodes::Sequence::BLOCK]
249
- end
250
-
251
- def test_literal_scalar
252
- @parser.parse(<<-eoyml)
253
- %YAML 1.1
254
- ---
255
- "literal\n\
256
- \ttext\n"
257
- eoyml
258
- assert_called :scalar, ['literal text ', false, true, Nodes::Scalar::DOUBLE_QUOTED]
259
- end
260
-
261
- def test_scalar
262
- @parser.parse("--- foo\n")
263
- assert_called :scalar, ['foo', true, false, Nodes::Scalar::PLAIN]
264
- end
265
-
266
- def test_scalar_with_tag
267
- @parser.parse("---\n!!str foo\n")
268
- assert_called :scalar, ['foo', 'tag:yaml.org,2002:str', false, false, Nodes::Scalar::PLAIN]
269
- end
270
-
271
- def test_scalar_with_anchor
272
- @parser.parse("---\n&A foo\n")
273
- assert_called :scalar, ['foo', 'A', true, false, Nodes::Scalar::PLAIN]
274
- end
275
-
276
- def test_scalar_plain_implicit
277
- @parser.parse("---\n&A foo\n")
278
- assert_called :scalar, ['foo', 'A', true, false, Nodes::Scalar::PLAIN]
279
- end
280
-
281
- def test_alias
282
- @parser.parse(<<-eoyml)
283
- %YAML 1.1
284
- ---
285
- !!seq [
286
- !!str "Without properties",
287
- &A !!str "Anchored",
288
- !!str "Tagged",
289
- *A,
290
- !!str "",
291
- ]
292
- eoyml
293
- assert_called :alias, ['A']
294
- end
295
-
296
- def test_end_stream
297
- @parser.parse("--- foo\n")
298
- assert_called :end_stream
299
- end
300
-
301
- def test_start_stream
302
- @parser.parse("--- foo\n")
303
- assert_called :start_stream
304
- end
305
-
306
- def test_end_document_implicit
307
- @parser.parse("\"foo\"\n")
308
- assert_called :end_document, [true]
309
- end
310
-
311
- def test_end_document_explicit
312
- @parser.parse("\"foo\"\n...")
313
- assert_called :end_document, [false]
314
- end
315
-
316
- def test_start_document_version
317
- @parser.parse("%YAML 1.1\n---\n\"foo\"\n")
318
- assert_called :start_document, [[1,1], [], false]
319
- end
320
-
321
- def test_start_document_tag
322
- @parser.parse("%TAG !yaml! tag:yaml.org,2002\n---\n!yaml!str \"foo\"\n")
323
- assert_called :start_document, [[], [['!yaml!', 'tag:yaml.org,2002']], false]
324
- end
325
-
326
- def assert_called call, with = nil, parser = @parser
327
- if with
328
- call = parser.handler.calls.find { |x|
329
- x.first == call && x.last.compact == with
330
- }
331
- assert(call,
332
- "#{[call,with].inspect} not in #{parser.handler.calls.inspect}"
333
- )
334
- else
335
- assert parser.handler.calls.any? { |x| x.first == call }
336
- end
337
- end
338
- end
339
- end
@@ -1,168 +0,0 @@
1
- require_relative 'helper'
2
-
3
- require 'stringio'
4
- require 'tempfile'
5
-
6
- class TestPsych < Psych::TestCase
7
- def teardown
8
- Psych.domain_types.clear
9
- end
10
-
11
- def test_line_width
12
- yml = Psych.dump('123456 7', { :line_width => 5 })
13
- assert_match(/^\s*7/, yml)
14
- end
15
-
16
- def test_indent
17
- yml = Psych.dump({:a => {'b' => 'c'}}, {:indentation => 5})
18
- assert_match(/^[ ]{5}b/, yml)
19
- end
20
-
21
- def test_canonical
22
- yml = Psych.dump({:a => {'b' => 'c'}}, {:canonical => true})
23
- assert_match(/\? "b/, yml)
24
- end
25
-
26
- def test_header
27
- yml = Psych.dump({:a => {'b' => 'c'}}, {:header => true})
28
- assert_match(/YAML/, yml)
29
- end
30
-
31
- def test_version_array
32
- yml = Psych.dump({:a => {'b' => 'c'}}, {:version => [1,1]})
33
- assert_match(/1.1/, yml)
34
- end
35
-
36
- def test_version_string
37
- yml = Psych.dump({:a => {'b' => 'c'}}, {:version => '1.1'})
38
- assert_match(/1.1/, yml)
39
- end
40
-
41
- def test_version_bool
42
- yml = Psych.dump({:a => {'b' => 'c'}}, {:version => true})
43
- assert_match(/1.1/, yml)
44
- end
45
-
46
- def test_load_argument_error
47
- assert_raises(TypeError) do
48
- Psych.load nil
49
- end
50
- end
51
-
52
- def test_non_existing_class_on_deserialize
53
- e = assert_raises(ArgumentError) do
54
- Psych.load("--- !ruby/object:NonExistent\nfoo: 1")
55
- end
56
- assert_equal 'undefined class/module NonExistent', e.message
57
- end
58
-
59
- def test_dump_stream
60
- things = [22, "foo \n", {}]
61
- stream = Psych.dump_stream(*things)
62
- assert_equal things, Psych.load_stream(stream)
63
- end
64
-
65
- def test_dump_file
66
- hash = {'hello' => 'TGIF!'}
67
- Tempfile.create('fun.yml') do |io|
68
- assert_equal io, Psych.dump(hash, io)
69
- io.rewind
70
- assert_equal Psych.dump(hash), io.read
71
- end
72
- end
73
-
74
- def test_dump_io
75
- hash = {'hello' => 'TGIF!'}
76
- stringio = StringIO.new ''
77
- assert_equal stringio, Psych.dump(hash, stringio)
78
- assert_equal Psych.dump(hash), stringio.string
79
- end
80
-
81
- def test_simple
82
- assert_equal 'foo', Psych.load("--- foo\n")
83
- end
84
-
85
- def test_libyaml_version
86
- assert Psych.libyaml_version
87
- assert_equal Psych.libyaml_version.join('.'), Psych::LIBYAML_VERSION
88
- end
89
-
90
- def test_load_documents
91
- docs = Psych.load_documents("--- foo\n...\n--- bar\n...")
92
- assert_equal %w{ foo bar }, docs
93
- end
94
-
95
- def test_parse_stream
96
- docs = Psych.parse_stream("--- foo\n...\n--- bar\n...")
97
- assert_equal %w{ foo bar }, docs.children.map { |x| x.transform }
98
- end
99
-
100
- def test_add_builtin_type
101
- got = nil
102
- Psych.add_builtin_type 'omap' do |type, val|
103
- got = val
104
- end
105
- Psych.load('--- !!omap hello')
106
- assert_equal 'hello', got
107
- ensure
108
- Psych.remove_type 'omap'
109
- end
110
-
111
- def test_domain_types
112
- got = nil
113
- Psych.add_domain_type 'foo.bar,2002', 'foo' do |type, val|
114
- got = val
115
- end
116
-
117
- Psych.load('--- !foo.bar,2002/foo hello')
118
- assert_equal 'hello', got
119
-
120
- Psych.load("--- !foo.bar,2002/foo\n- hello\n- world")
121
- assert_equal %w{ hello world }, got
122
-
123
- Psych.load("--- !foo.bar,2002/foo\nhello: world")
124
- assert_equal({ 'hello' => 'world' }, got)
125
- end
126
-
127
- def test_load_file
128
- Tempfile.create(['yikes', 'yml']) {|t|
129
- t.binmode
130
- t.write('--- hello world')
131
- t.close
132
- assert_equal 'hello world', Psych.load_file(t.path)
133
- }
134
- end
135
-
136
- def test_parse_file
137
- Tempfile.create(['yikes', 'yml']) {|t|
138
- t.binmode
139
- t.write('--- hello world')
140
- t.close
141
- assert_equal 'hello world', Psych.parse_file(t.path).transform
142
- }
143
- end
144
-
145
- def test_degenerate_strings
146
- assert_equal false, Psych.load(' ')
147
- assert_equal false, Psych.parse(' ')
148
- assert_equal false, Psych.load('')
149
- assert_equal false, Psych.parse('')
150
- end
151
-
152
- def test_callbacks
153
- types = []
154
- appender = lambda { |*args| types << args }
155
-
156
- Psych.add_builtin_type('foo', &appender)
157
- Psych.add_domain_type('example.com,2002', 'foo', &appender)
158
- Psych.load <<-eoyml
159
- - !tag:yaml.org,2002:foo bar
160
- - !tag:example.com,2002:foo bar
161
- eoyml
162
-
163
- assert_equal [
164
- ["tag:yaml.org,2002:foo", "bar"],
165
- ["tag:example.com,2002:foo", "bar"]
166
- ], types
167
- end
168
- end
@@ -1,97 +0,0 @@
1
- require 'psych/helper'
2
-
3
- module Psych
4
- class TestSafeLoad < TestCase
5
- class Foo; end
6
-
7
- [1, 2.2, {}, [], "foo"].each do |obj|
8
- define_method(:"test_basic_#{obj.class}") do
9
- assert_safe_cycle obj
10
- end
11
- end
12
-
13
- def test_no_recursion
14
- x = []
15
- x << x
16
- assert_raises(Psych::BadAlias) do
17
- Psych.safe_load Psych.dump(x)
18
- end
19
- end
20
-
21
- def test_explicit_recursion
22
- x = []
23
- x << x
24
- assert_equal(x, Psych.safe_load(Psych.dump(x), [], [], true))
25
- end
26
-
27
- def test_symbol_whitelist
28
- yml = Psych.dump :foo
29
- assert_raises(Psych::DisallowedClass) do
30
- Psych.safe_load yml
31
- end
32
- assert_equal(:foo, Psych.safe_load(yml, [Symbol], [:foo]))
33
- end
34
-
35
- def test_symbol
36
- assert_raises(Psych::DisallowedClass) do
37
- assert_safe_cycle :foo
38
- end
39
- assert_raises(Psych::DisallowedClass) do
40
- Psych.safe_load '--- !ruby/symbol foo', []
41
- end
42
- assert_safe_cycle :foo, [Symbol]
43
- assert_safe_cycle :foo, %w{ Symbol }
44
- assert_equal :foo, Psych.safe_load('--- !ruby/symbol foo', [Symbol])
45
- end
46
-
47
- def test_foo
48
- assert_raises(Psych::DisallowedClass) do
49
- Psych.safe_load '--- !ruby/object:Foo {}', [Foo]
50
- end
51
- assert_raises(Psych::DisallowedClass) do
52
- assert_safe_cycle Foo.new
53
- end
54
- assert_kind_of(Foo, Psych.safe_load(Psych.dump(Foo.new), [Foo]))
55
- end
56
-
57
- X = Struct.new(:x)
58
- def test_struct_depends_on_sym
59
- assert_safe_cycle(X.new, [X, Symbol])
60
- assert_raises(Psych::DisallowedClass) do
61
- cycle X.new, [X]
62
- end
63
- end
64
-
65
- def test_anon_struct
66
- assert Psych.safe_load(<<-eoyml, [Struct, Symbol])
67
- --- !ruby/struct
68
- foo: bar
69
- eoyml
70
-
71
- assert_raises(Psych::DisallowedClass) do
72
- Psych.safe_load(<<-eoyml, [Struct])
73
- --- !ruby/struct
74
- foo: bar
75
- eoyml
76
- end
77
-
78
- assert_raises(Psych::DisallowedClass) do
79
- Psych.safe_load(<<-eoyml, [Symbol])
80
- --- !ruby/struct
81
- foo: bar
82
- eoyml
83
- end
84
- end
85
-
86
- private
87
-
88
- def cycle object, whitelist = []
89
- Psych.safe_load(Psych.dump(object), whitelist)
90
- end
91
-
92
- def assert_safe_cycle object, whitelist = []
93
- other = cycle object, whitelist
94
- assert_equal object, other
95
- end
96
- end
97
- end
@@ -1,11 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require_relative 'helper'
4
-
5
- module Psych
6
- class TestScalar < TestCase
7
- def test_utf_8
8
- assert_equal "日本語", Psych.load("--- 日本語")
9
- end
10
- end
11
- end
@@ -1,106 +0,0 @@
1
- require_relative 'helper'
2
- require 'date'
3
-
4
- module Psych
5
- class TestScalarScanner < TestCase
6
- attr_reader :ss
7
-
8
- def setup
9
- super
10
- @ss = Psych::ScalarScanner.new ClassLoader.new
11
- end
12
-
13
- def test_scan_time
14
- { '2001-12-15T02:59:43.1Z' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
15
- '2001-12-14t21:59:43.10-05:00' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
16
- '2001-12-14 21:59:43.10 -5' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
17
- '2001-12-15 2:59:43.10' => Time.utc(2001, 12, 15, 02, 59, 43, 100000),
18
- '2011-02-24 11:17:06 -0800' => Time.utc(2011, 02, 24, 19, 17, 06)
19
- }.each do |time_str, time|
20
- assert_equal time, @ss.tokenize(time_str)
21
- end
22
- end
23
-
24
- def test_scan_bad_time
25
- [ '2001-12-15T02:59:73.1Z',
26
- '2001-12-14t90:59:43.10-05:00',
27
- '2001-92-14 21:59:43.10 -5',
28
- '2001-12-15 92:59:43.10',
29
- '2011-02-24 81:17:06 -0800',
30
- ].each do |time_str|
31
- assert_equal time_str, @ss.tokenize(time_str)
32
- end
33
- end
34
-
35
- def test_scan_bad_dates
36
- x = '2000-15-01'
37
- assert_equal x, @ss.tokenize(x)
38
-
39
- x = '2000-10-51'
40
- assert_equal x, @ss.tokenize(x)
41
-
42
- x = '2000-10-32'
43
- assert_equal x, @ss.tokenize(x)
44
- end
45
-
46
- def test_scan_good_edge_date
47
- x = '2000-1-31'
48
- assert_equal Date.strptime(x, '%Y-%m-%d'), @ss.tokenize(x)
49
- end
50
-
51
- def test_scan_bad_edge_date
52
- x = '2000-11-31'
53
- assert_equal x, @ss.tokenize(x)
54
- end
55
-
56
- def test_scan_date
57
- date = '1980-12-16'
58
- token = @ss.tokenize date
59
- assert_equal 1980, token.year
60
- assert_equal 12, token.month
61
- assert_equal 16, token.day
62
- end
63
-
64
- def test_scan_inf
65
- assert_equal(1 / 0.0, ss.tokenize('.inf'))
66
- end
67
-
68
- def test_scan_minus_inf
69
- assert_equal(-1 / 0.0, ss.tokenize('-.inf'))
70
- end
71
-
72
- def test_scan_nan
73
- assert ss.tokenize('.nan').nan?
74
- end
75
-
76
- def test_scan_null
77
- assert_equal nil, ss.tokenize('null')
78
- assert_equal nil, ss.tokenize('~')
79
- assert_equal nil, ss.tokenize('')
80
- end
81
-
82
- def test_scan_symbol
83
- assert_equal :foo, ss.tokenize(':foo')
84
- end
85
-
86
- def test_scan_sexagesimal_float
87
- assert_equal 685230.15, ss.tokenize('190:20:30.15')
88
- end
89
-
90
- def test_scan_sexagesimal_int
91
- assert_equal 685230, ss.tokenize('190:20:30')
92
- end
93
-
94
- def test_scan_float
95
- assert_equal 1.2, ss.tokenize('1.2')
96
- end
97
-
98
- def test_scan_true
99
- assert_equal true, ss.tokenize('true')
100
- end
101
-
102
- def test_scan_strings_starting_with_underscores
103
- assert_equal "_100", ss.tokenize('_100')
104
- end
105
- end
106
- end