psych 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.travis.yml +1 -10
  4. data/Gemfile +3 -0
  5. data/Mavenfile +7 -0
  6. data/Rakefile +27 -119
  7. data/bin/console +7 -0
  8. data/bin/setup +6 -0
  9. data/ext/java/PsychEmitter.java +345 -0
  10. data/ext/java/PsychLibrary.java +93 -0
  11. data/ext/java/PsychParser.java +399 -0
  12. data/ext/java/PsychToRuby.java +79 -0
  13. data/ext/java/PsychYamlTree.java +55 -0
  14. data/ext/psych/.gitignore +11 -0
  15. data/lib/psych.rb +2 -2
  16. data/lib/psych/scalar_scanner.rb +1 -1
  17. data/lib/psych/visitors/to_ruby.rb +2 -2
  18. data/psych.gemspec +39 -0
  19. metadata +21 -84
  20. data/.autotest +0 -18
  21. data/Manifest.txt +0 -114
  22. data/test/psych/handlers/test_recorder.rb +0 -26
  23. data/test/psych/helper.rb +0 -122
  24. data/test/psych/json/test_stream.rb +0 -110
  25. data/test/psych/nodes/test_enumerable.rb +0 -44
  26. data/test/psych/test_alias_and_anchor.rb +0 -97
  27. data/test/psych/test_array.rb +0 -58
  28. data/test/psych/test_boolean.rb +0 -37
  29. data/test/psych/test_class.rb +0 -37
  30. data/test/psych/test_coder.rb +0 -207
  31. data/test/psych/test_date_time.rb +0 -39
  32. data/test/psych/test_deprecated.rb +0 -215
  33. data/test/psych/test_document.rb +0 -47
  34. data/test/psych/test_emitter.rb +0 -111
  35. data/test/psych/test_encoding.rb +0 -269
  36. data/test/psych/test_exception.rb +0 -158
  37. data/test/psych/test_hash.rb +0 -95
  38. data/test/psych/test_json_tree.rb +0 -66
  39. data/test/psych/test_merge_keys.rb +0 -181
  40. data/test/psych/test_nil.rb +0 -19
  41. data/test/psych/test_null.rb +0 -20
  42. data/test/psych/test_numeric.rb +0 -46
  43. data/test/psych/test_object.rb +0 -45
  44. data/test/psych/test_object_references.rb +0 -72
  45. data/test/psych/test_omap.rb +0 -76
  46. data/test/psych/test_parser.rb +0 -340
  47. data/test/psych/test_psych.rb +0 -184
  48. data/test/psych/test_safe_load.rb +0 -98
  49. data/test/psych/test_scalar.rb +0 -12
  50. data/test/psych/test_scalar_scanner.rb +0 -107
  51. data/test/psych/test_serialize_subclasses.rb +0 -39
  52. data/test/psych/test_set.rb +0 -50
  53. data/test/psych/test_stream.rb +0 -94
  54. data/test/psych/test_string.rb +0 -227
  55. data/test/psych/test_struct.rb +0 -50
  56. data/test/psych/test_symbol.rb +0 -26
  57. data/test/psych/test_tainted.rb +0 -131
  58. data/test/psych/test_to_yaml_properties.rb +0 -64
  59. data/test/psych/test_tree_builder.rb +0 -80
  60. data/test/psych/test_yaml.rb +0 -1293
  61. data/test/psych/test_yamldbm.rb +0 -193
  62. data/test/psych/test_yamlstore.rb +0 -86
  63. data/test/psych/visitors/test_depth_first.rb +0 -50
  64. data/test/psych/visitors/test_emitter.rb +0 -145
  65. data/test/psych/visitors/test_to_ruby.rb +0 -332
  66. data/test/psych/visitors/test_yaml_tree.rb +0 -180
@@ -1,47 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestDocument < TestCase
6
- def setup
7
- super
8
- @stream = Psych.parse_stream(<<-eoyml)
9
- %YAML 1.1
10
- %TAG ! tag:tenderlovemaking.com,2009:
11
- --- !fun
12
- eoyml
13
- @doc = @stream.children.first
14
- end
15
-
16
- def test_parse_tag
17
- assert_equal([['!', 'tag:tenderlovemaking.com,2009:']],
18
- @doc.tag_directives)
19
- end
20
-
21
- def test_emit_tag
22
- assert_match('%TAG ! tag:tenderlovemaking.com,2009:', @stream.yaml)
23
- end
24
-
25
- def test_emit_multitag
26
- @doc.tag_directives << ['!!', 'foo.com,2009:']
27
- yaml = @stream.yaml
28
- assert_match('%TAG ! tag:tenderlovemaking.com,2009:', yaml)
29
- assert_match('%TAG !! foo.com,2009:', yaml)
30
- end
31
-
32
- def test_emit_bad_tag
33
- assert_raises(RuntimeError) do
34
- @doc.tag_directives = [['!']]
35
- @stream.yaml
36
- end
37
- end
38
-
39
- def test_parse_version
40
- assert_equal([1,1], @doc.version)
41
- end
42
-
43
- def test_emit_version
44
- assert_match('%YAML 1.1', @stream.yaml)
45
- end
46
- end
47
- end
@@ -1,111 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # frozen_string_literal: false
3
-
4
- require_relative 'helper'
5
-
6
- module Psych
7
- class TestEmitter < TestCase
8
- def setup
9
- super
10
- @out = StringIO.new('')
11
- @emitter = Psych::Emitter.new @out
12
- end
13
-
14
- def test_line_width
15
- @emitter.line_width = 10
16
- assert_equal 10, @emitter.line_width
17
- end
18
-
19
- def test_set_canonical
20
- @emitter.canonical = true
21
- assert_equal true, @emitter.canonical
22
-
23
- @emitter.canonical = false
24
- assert_equal false, @emitter.canonical
25
- end
26
-
27
- def test_indentation_set
28
- assert_equal 2, @emitter.indentation
29
- @emitter.indentation = 5
30
- assert_equal 5, @emitter.indentation
31
- end
32
-
33
- def test_emit_utf_8
34
- @emitter.start_stream Psych::Nodes::Stream::UTF8
35
- @emitter.start_document [], [], false
36
- @emitter.scalar '日本語', nil, nil, false, true, 1
37
- @emitter.end_document true
38
- @emitter.end_stream
39
- assert_match('日本語', @out.string)
40
- end
41
-
42
- def test_start_stream_arg_error
43
- assert_raises(TypeError) do
44
- @emitter.start_stream 'asdfasdf'
45
- end
46
- end
47
-
48
- def test_start_doc_arg_error
49
- @emitter.start_stream Psych::Nodes::Stream::UTF8
50
-
51
- [
52
- [nil, [], false],
53
- [[nil, nil], [], false],
54
- [[], 'foo', false],
55
- [[], ['foo'], false],
56
- [[], [nil,nil], false],
57
- ].each do |args|
58
- assert_raises(TypeError) do
59
- @emitter.start_document(*args)
60
- end
61
- end
62
- end
63
-
64
- def test_scalar_arg_error
65
- @emitter.start_stream Psych::Nodes::Stream::UTF8
66
- @emitter.start_document [], [], false
67
-
68
- [
69
- [:foo, nil, nil, false, true, 1],
70
- ['foo', Object.new, nil, false, true, 1],
71
- ['foo', nil, Object.new, false, true, 1],
72
- ['foo', nil, nil, false, true, :foo],
73
- [nil, nil, nil, false, true, 1],
74
- ].each do |args|
75
- assert_raises(TypeError) do
76
- @emitter.scalar(*args)
77
- end
78
- end
79
- end
80
-
81
- def test_start_sequence_arg_error
82
- @emitter.start_stream Psych::Nodes::Stream::UTF8
83
- @emitter.start_document [], [], false
84
-
85
- assert_raises(TypeError) do
86
- @emitter.start_sequence(nil, Object.new, true, 1)
87
- end
88
-
89
- assert_raises(TypeError) do
90
- @emitter.start_sequence(nil, nil, true, :foo)
91
- end
92
- end
93
-
94
- def test_resizing_tags
95
- @emitter.start_stream Psych::Nodes::Stream::UTF8
96
-
97
- tags = []
98
- version = [1,1]
99
- obj = Object.new
100
- obj.instance_variable_set(:@tags, tags)
101
- def obj.to_str
102
- (1..10).map{|x| @tags.push(["AAAA","BBBB"])}
103
- return "x"
104
- end
105
-
106
- tags.push([obj, "tag:TALOS"])
107
- @emitter.start_document(version, tags, 0)
108
- assert(true)
109
- end
110
- end
111
- end
@@ -1,269 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- # frozen_string_literal: false
3
-
4
- require_relative 'helper'
5
-
6
- module Psych
7
- class TestEncoding < TestCase
8
- class EncodingCatcher < Handler
9
- attr_reader :strings
10
- def initialize
11
- @strings = []
12
- end
13
-
14
- (Handler.instance_methods(true) -
15
- Object.instance_methods).each do |m|
16
- class_eval %{
17
- def #{m} *args
18
- @strings += args.flatten.find_all { |a|
19
- String === a
20
- }
21
- end
22
- }
23
- end
24
- end
25
-
26
- def setup
27
- super
28
- @buffer = StringIO.new
29
- @handler = EncodingCatcher.new
30
- @parser = Psych::Parser.new @handler
31
- @utf8 = Encoding.find('UTF-8')
32
- @emitter = Psych::Emitter.new @buffer
33
- end
34
-
35
- def test_dump_load_encoding_object
36
- assert_cycle Encoding::US_ASCII
37
- assert_cycle Encoding::UTF_8
38
- end
39
-
40
- def test_transcode_shiftjis
41
- str = "こんにちは!"
42
- loaded = Psych.load("--- こんにちは!".encode('SHIFT_JIS'))
43
- assert_equal str, loaded
44
- end
45
-
46
- def test_transcode_utf16le
47
- str = "こんにちは!"
48
- loaded = Psych.load("--- こんにちは!".encode('UTF-16LE'))
49
- assert_equal str, loaded
50
- end
51
-
52
- def test_transcode_utf16be
53
- str = "こんにちは!"
54
- loaded = Psych.load("--- こんにちは!".encode('UTF-16BE'))
55
- assert_equal str, loaded
56
- end
57
-
58
- def test_io_shiftjis
59
- Tempfile.create(['shiftjis', 'yml'], :encoding => 'SHIFT_JIS') {|t|
60
- t.write '--- こんにちは!'
61
- t.close
62
-
63
- # If the external encoding isn't utf8, utf16le, or utf16be, we cannot
64
- # process the file.
65
- File.open(t.path, 'r', :encoding => 'SHIFT_JIS') do |f|
66
- assert_raises Psych::SyntaxError do
67
- Psych.load(f)
68
- end
69
- end
70
- }
71
- end
72
-
73
- def test_io_utf16le
74
- Tempfile.create(['utf16le', 'yml']) {|t|
75
- t.binmode
76
- t.write '--- こんにちは!'.encode('UTF-16LE')
77
- t.close
78
-
79
- File.open(t.path, 'rb', :encoding => 'UTF-16LE') do |f|
80
- assert_equal "こんにちは!", Psych.load(f)
81
- end
82
- }
83
- end
84
-
85
- def test_io_utf16be
86
- Tempfile.create(['utf16be', 'yml']) {|t|
87
- t.binmode
88
- t.write '--- こんにちは!'.encode('UTF-16BE')
89
- t.close
90
-
91
- File.open(t.path, 'rb', :encoding => 'UTF-16BE') do |f|
92
- assert_equal "こんにちは!", Psych.load(f)
93
- end
94
- }
95
- end
96
-
97
- def test_io_utf8
98
- Tempfile.create(['utf8', 'yml']) {|t|
99
- t.binmode
100
- t.write '--- こんにちは!'.encode('UTF-8')
101
- t.close
102
-
103
- File.open(t.path, 'rb', :encoding => 'UTF-8') do |f|
104
- assert_equal "こんにちは!", Psych.load(f)
105
- end
106
- }
107
- end
108
-
109
- def test_emit_alias
110
- @emitter.start_stream Psych::Parser::UTF8
111
- @emitter.start_document [], [], true
112
- e = assert_raises(RuntimeError) do
113
- @emitter.alias 'ドラえもん'.encode('EUC-JP')
114
- end
115
- assert_match(/alias value/, e.message)
116
- end
117
-
118
- def test_to_yaml_is_valid
119
- with_default_external(Encoding::US_ASCII) do
120
- with_default_internal(nil) do
121
- s = "こんにちは!"
122
- # If no encoding is specified, use UTF-8
123
- assert_equal Encoding::UTF_8, Psych.dump(s).encoding
124
- assert_equal s, Psych.load(Psych.dump(s))
125
- end
126
- end
127
- end
128
-
129
- def test_start_mapping
130
- foo = 'foo'
131
- bar = 'バー'
132
-
133
- @emitter.start_stream Psych::Parser::UTF8
134
- @emitter.start_document [], [], true
135
- @emitter.start_mapping(
136
- foo.encode('Shift_JIS'),
137
- bar.encode('UTF-16LE'),
138
- false, Nodes::Sequence::ANY)
139
- @emitter.end_mapping
140
- @emitter.end_document false
141
- @emitter.end_stream
142
-
143
- @parser.parse @buffer.string
144
- assert_encodings @utf8, @handler.strings
145
- assert_equal [foo, bar], @handler.strings
146
- end
147
-
148
- def test_start_sequence
149
- foo = 'foo'
150
- bar = 'バー'
151
-
152
- @emitter.start_stream Psych::Parser::UTF8
153
- @emitter.start_document [], [], true
154
- @emitter.start_sequence(
155
- foo.encode('Shift_JIS'),
156
- bar.encode('UTF-16LE'),
157
- false, Nodes::Sequence::ANY)
158
- @emitter.end_sequence
159
- @emitter.end_document false
160
- @emitter.end_stream
161
-
162
- @parser.parse @buffer.string
163
- assert_encodings @utf8, @handler.strings
164
- assert_equal [foo, bar], @handler.strings
165
- end
166
-
167
- def test_doc_tag_encoding
168
- key = '鍵'
169
- @emitter.start_stream Psych::Parser::UTF8
170
- @emitter.start_document(
171
- [1, 1],
172
- [['!'.encode('EUC-JP'), key.encode('EUC-JP')]],
173
- true
174
- )
175
- @emitter.scalar 'foo', nil, nil, true, false, Nodes::Scalar::ANY
176
- @emitter.end_document false
177
- @emitter.end_stream
178
-
179
- @parser.parse @buffer.string
180
- assert_encodings @utf8, @handler.strings
181
- assert_equal key, @handler.strings[1]
182
- end
183
-
184
- def test_emitter_encoding
185
- str = "壁に耳あり、障子に目あり"
186
- thing = Psych.load Psych.dump str.encode('EUC-JP')
187
- assert_equal str, thing
188
- end
189
-
190
- def test_default_internal
191
- with_default_internal(Encoding::EUC_JP) do
192
- str = "壁に耳あり、障子に目あり"
193
- assert_equal @utf8, str.encoding
194
-
195
- @parser.parse str
196
- assert_encodings Encoding::EUC_JP, @handler.strings
197
- assert_equal str, @handler.strings.first.encode('UTF-8')
198
- end
199
- end
200
-
201
- def test_scalar
202
- @parser.parse("--- a")
203
- assert_encodings @utf8, @handler.strings
204
- end
205
-
206
- def test_alias
207
- @parser.parse(<<-eoyml)
208
- %YAML 1.1
209
- ---
210
- !!seq [
211
- !!str "Without properties",
212
- &A !!str "Anchored",
213
- !!str "Tagged",
214
- *A,
215
- !!str "",
216
- ]
217
- eoyml
218
- assert_encodings @utf8, @handler.strings
219
- end
220
-
221
- def test_list_anchor
222
- list = %w{ a b }
223
- list << list
224
- @parser.parse(Psych.dump(list))
225
- assert_encodings @utf8, @handler.strings
226
- end
227
-
228
- def test_map_anchor
229
- h = {}
230
- h['a'] = h
231
- @parser.parse(Psych.dump(h))
232
- assert_encodings @utf8, @handler.strings
233
- end
234
-
235
- def test_map_tag
236
- @parser.parse(<<-eoyml)
237
- %YAML 1.1
238
- ---
239
- !!map { a : b }
240
- eoyml
241
- assert_encodings @utf8, @handler.strings
242
- end
243
-
244
- def test_doc_tag
245
- @parser.parse(<<-eoyml)
246
- %YAML 1.1
247
- %TAG ! tag:tenderlovemaking.com,2009:
248
- --- !fun
249
- eoyml
250
- assert_encodings @utf8, @handler.strings
251
- end
252
-
253
- def test_dump_non_ascii_string_to_file
254
- Tempfile.create(['utf8', 'yml'], :encoding => 'UTF-8') do |t|
255
- h = {'one' => 'いち'}
256
- Psych.dump(h, t)
257
- t.close
258
- assert_equal h, Psych.load_file(t.path)
259
- end
260
- end
261
-
262
- private
263
- def assert_encodings encoding, strings
264
- strings.each do |str|
265
- assert_equal encoding, str.encoding, str
266
- end
267
- end
268
- end
269
- end
@@ -1,158 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestException < TestCase
6
- class Wups < Exception
7
- attr_reader :foo, :bar
8
- def initialize *args
9
- super
10
- @foo = 1
11
- @bar = 2
12
- end
13
- end
14
-
15
- def setup
16
- super
17
- @wups = Wups.new
18
- end
19
-
20
- def test_naming_exception
21
- err = String.xxx rescue $!
22
- new_err = Psych.load(Psych.dump(err))
23
- assert_equal err.message, new_err.message
24
- end
25
-
26
- def test_load_takes_file
27
- ex = assert_raises(Psych::SyntaxError) do
28
- Psych.load '--- `'
29
- end
30
- assert_nil ex.file
31
-
32
- ex = assert_raises(Psych::SyntaxError) do
33
- Psych.load '--- `', 'meow'
34
- end
35
- assert_equal 'meow', ex.file
36
- end
37
-
38
- def test_psych_parse_stream_takes_file
39
- ex = assert_raises(Psych::SyntaxError) do
40
- Psych.parse_stream '--- `'
41
- end
42
- assert_nil ex.file
43
- assert_match '(<unknown>)', ex.message
44
-
45
- ex = assert_raises(Psych::SyntaxError) do
46
- Psych.parse_stream '--- `', 'omg!'
47
- end
48
- assert_equal 'omg!', ex.file
49
- assert_match 'omg!', ex.message
50
- end
51
-
52
- def test_load_stream_takes_file
53
- ex = assert_raises(Psych::SyntaxError) do
54
- Psych.load_stream '--- `'
55
- end
56
- assert_nil ex.file
57
- assert_match '(<unknown>)', ex.message
58
-
59
- ex = assert_raises(Psych::SyntaxError) do
60
- Psych.load_stream '--- `', 'omg!'
61
- end
62
- assert_equal 'omg!', ex.file
63
- end
64
-
65
- def test_parse_file_exception
66
- Tempfile.create(['parsefile', 'yml']) {|t|
67
- t.binmode
68
- t.write '--- `'
69
- t.close
70
- ex = assert_raises(Psych::SyntaxError) do
71
- Psych.parse_file t.path
72
- end
73
- assert_equal t.path, ex.file
74
- }
75
- end
76
-
77
- def test_load_file_exception
78
- Tempfile.create(['loadfile', 'yml']) {|t|
79
- t.binmode
80
- t.write '--- `'
81
- t.close
82
- ex = assert_raises(Psych::SyntaxError) do
83
- Psych.load_file t.path
84
- end
85
- assert_equal t.path, ex.file
86
- }
87
- end
88
-
89
- def test_psych_parse_takes_file
90
- ex = assert_raises(Psych::SyntaxError) do
91
- Psych.parse '--- `'
92
- end
93
- assert_match '(<unknown>)', ex.message
94
- assert_nil ex.file
95
-
96
- ex = assert_raises(Psych::SyntaxError) do
97
- Psych.parse '--- `', 'omg!'
98
- end
99
- assert_match 'omg!', ex.message
100
- end
101
-
102
- def test_attributes
103
- e = assert_raises(Psych::SyntaxError) {
104
- Psych.load '--- `foo'
105
- }
106
-
107
- assert_nil e.file
108
- assert_equal 1, e.line
109
- assert_equal 5, e.column
110
- # FIXME: offset isn't being set correctly by libyaml
111
- # assert_equal 5, e.offset
112
-
113
- assert e.problem
114
- assert e.context
115
- end
116
-
117
- def test_convert
118
- w = Psych.load(Psych.dump(@wups))
119
- assert_equal @wups, w
120
- assert_equal 1, w.foo
121
- assert_equal 2, w.bar
122
- end
123
-
124
- def test_to_yaml_properties
125
- class << @wups
126
- def to_yaml_properties
127
- [:@foo]
128
- end
129
- end
130
-
131
- w = Psych.load(Psych.dump(@wups))
132
- assert_equal @wups, w
133
- assert_equal 1, w.foo
134
- assert_nil w.bar
135
- end
136
-
137
- def test_psych_syntax_error
138
- Tempfile.create(['parsefile', 'yml']) do |t|
139
- t.binmode
140
- t.write '--- `'
141
- t.close
142
-
143
- begin
144
- Psych.parse_file t.path
145
- rescue StandardError
146
- assert true # count assertion
147
- ensure
148
- return unless $!
149
-
150
- ancestors = $!.class.ancestors.inspect
151
-
152
- flunk "Psych::SyntaxError not rescued by StandardError: #{ancestors}"
153
- end
154
- end
155
- end
156
-
157
- end
158
- end