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,71 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
class TestObjectReferences < TestCase
|
5
|
+
def test_range_has_references
|
6
|
+
assert_reference_trip 1..2
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_module_has_references
|
10
|
+
assert_reference_trip Psych
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_class_has_references
|
14
|
+
assert_reference_trip TestObjectReferences
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_rational_has_references
|
18
|
+
assert_reference_trip Rational('1.2')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_complex_has_references
|
22
|
+
assert_reference_trip Complex(1, 2)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_datetime_has_references
|
26
|
+
assert_reference_trip DateTime.now
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_struct_has_references
|
30
|
+
assert_reference_trip Struct.new(:foo).new(1)
|
31
|
+
end
|
32
|
+
|
33
|
+
def assert_reference_trip obj
|
34
|
+
yml = Psych.dump([obj, obj])
|
35
|
+
assert_match(/\*-?\d+/, yml)
|
36
|
+
data = Psych.load yml
|
37
|
+
assert_equal data.first.object_id, data.last.object_id
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_float_references
|
41
|
+
data = Psych.load <<-eoyml
|
42
|
+
---\s
|
43
|
+
- &name 1.2
|
44
|
+
- *name
|
45
|
+
eoyml
|
46
|
+
assert_equal data.first, data.last
|
47
|
+
assert_equal data.first.object_id, data.last.object_id
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_binary_references
|
51
|
+
data = Psych.load <<-eoyml
|
52
|
+
---
|
53
|
+
- &name !binary |-
|
54
|
+
aGVsbG8gd29ybGQh
|
55
|
+
- *name
|
56
|
+
eoyml
|
57
|
+
assert_equal data.first, data.last
|
58
|
+
assert_equal data.first.object_id, data.last.object_id
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_regexp_references
|
62
|
+
data = Psych.load <<-eoyml
|
63
|
+
---\s
|
64
|
+
- &name !ruby/regexp /pattern/i
|
65
|
+
- *name
|
66
|
+
eoyml
|
67
|
+
assert_equal data.first, data.last
|
68
|
+
assert_equal data.first.object_id, data.last.object_id
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
class TestOmap < TestCase
|
5
|
+
def test_parse_as_map
|
6
|
+
o = Psych.load "--- !!omap\na: 1\nb: 2"
|
7
|
+
assert_kind_of Psych::Omap, o
|
8
|
+
assert_equal 1, o['a']
|
9
|
+
assert_equal 2, o['b']
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_self_referential
|
13
|
+
map = Psych::Omap.new
|
14
|
+
map['foo'] = 'bar'
|
15
|
+
map['self'] = map
|
16
|
+
assert_equal(map, Psych.load(Psych.dump(map)))
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_keys
|
20
|
+
map = Psych::Omap.new
|
21
|
+
map['foo'] = 'bar'
|
22
|
+
assert_equal 'bar', map['foo']
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_order
|
26
|
+
map = Psych::Omap.new
|
27
|
+
map['a'] = 'b'
|
28
|
+
map['b'] = 'c'
|
29
|
+
assert_equal [%w{a b}, %w{b c}], map.to_a
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_square
|
33
|
+
list = [["a", "b"], ["b", "c"]]
|
34
|
+
map = Psych::Omap[*list.flatten]
|
35
|
+
assert_equal list, map.to_a
|
36
|
+
assert_equal 'b', map['a']
|
37
|
+
assert_equal 'c', map['b']
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_dump
|
41
|
+
map = Psych::Omap['a', 'b', 'c', 'd']
|
42
|
+
yaml = Psych.dump(map)
|
43
|
+
assert_match('!omap', yaml)
|
44
|
+
assert_match('- a: b', yaml)
|
45
|
+
assert_match('- c: d', yaml)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_round_trip
|
49
|
+
list = [["a", "b"], ["b", "c"]]
|
50
|
+
map = Psych::Omap[*list.flatten]
|
51
|
+
assert_cycle(map)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_load
|
55
|
+
list = [["a", "b"], ["c", "d"]]
|
56
|
+
map = Psych.load(<<-eoyml)
|
57
|
+
--- !omap
|
58
|
+
- a: b
|
59
|
+
- c: d
|
60
|
+
eoyml
|
61
|
+
assert_equal list, map.to_a
|
62
|
+
end
|
63
|
+
|
64
|
+
# NOTE: This test will not work with Syck
|
65
|
+
def test_load_shorthand
|
66
|
+
list = [["a", "b"], ["c", "d"]]
|
67
|
+
map = Psych.load(<<-eoyml)
|
68
|
+
--- !!omap
|
69
|
+
- a: b
|
70
|
+
- c: d
|
71
|
+
eoyml
|
72
|
+
assert_equal list, map.to_a
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,339 @@
|
|
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
|