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