psych 2.1.0-java → 2.1.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/Gemfile +3 -0
- data/Mavenfile +7 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/ext/java/PsychEmitter.java +345 -0
- data/ext/java/PsychLibrary.java +93 -0
- data/ext/java/PsychParser.java +399 -0
- data/ext/java/PsychToRuby.java +79 -0
- data/ext/java/PsychYamlTree.java +55 -0
- data/ext/psych/.gitignore +11 -0
- data/lib/psych.rb +2 -2
- data/lib/psych/visitors/to_ruby.rb +2 -2
- data/psych.gemspec +39 -0
- metadata +19 -53
- data/test/psych/handlers/test_recorder.rb +0 -26
- data/test/psych/helper.rb +0 -122
- data/test/psych/json/test_stream.rb +0 -110
- data/test/psych/nodes/test_enumerable.rb +0 -44
- data/test/psych/test_alias_and_anchor.rb +0 -97
- data/test/psych/test_array.rb +0 -58
- data/test/psych/test_boolean.rb +0 -37
- data/test/psych/test_class.rb +0 -37
- data/test/psych/test_coder.rb +0 -207
- data/test/psych/test_date_time.rb +0 -39
- data/test/psych/test_deprecated.rb +0 -215
- data/test/psych/test_document.rb +0 -47
- data/test/psych/test_emitter.rb +0 -112
- data/test/psych/test_encoding.rb +0 -269
- data/test/psych/test_exception.rb +0 -158
- data/test/psych/test_hash.rb +0 -95
- data/test/psych/test_json_tree.rb +0 -66
- data/test/psych/test_merge_keys.rb +0 -181
- data/test/psych/test_nil.rb +0 -19
- data/test/psych/test_null.rb +0 -20
- data/test/psych/test_numeric.rb +0 -46
- data/test/psych/test_object.rb +0 -45
- data/test/psych/test_object_references.rb +0 -72
- data/test/psych/test_omap.rb +0 -76
- data/test/psych/test_parser.rb +0 -340
- data/test/psych/test_psych.rb +0 -184
- data/test/psych/test_safe_load.rb +0 -98
- data/test/psych/test_scalar.rb +0 -12
- data/test/psych/test_scalar_scanner.rb +0 -111
- data/test/psych/test_serialize_subclasses.rb +0 -39
- data/test/psych/test_set.rb +0 -50
- data/test/psych/test_stream.rb +0 -94
- data/test/psych/test_string.rb +0 -231
- data/test/psych/test_struct.rb +0 -50
- data/test/psych/test_symbol.rb +0 -26
- data/test/psych/test_tainted.rb +0 -131
- data/test/psych/test_to_yaml_properties.rb +0 -64
- data/test/psych/test_tree_builder.rb +0 -80
- data/test/psych/test_yaml.rb +0 -1293
- data/test/psych/test_yamldbm.rb +0 -193
- data/test/psych/test_yamlstore.rb +0 -86
- data/test/psych/visitors/test_depth_first.rb +0 -50
- data/test/psych/visitors/test_emitter.rb +0 -145
- data/test/psych/visitors/test_to_ruby.rb +0 -332
- data/test/psych/visitors/test_yaml_tree.rb +0 -180
data/test/psych/test_nil.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
module Psych
|
5
|
-
class TestNil < TestCase
|
6
|
-
def test_nil
|
7
|
-
yml = Psych.dump nil
|
8
|
-
assert_match(/--- \n(?:\.\.\.\n)?/, yml)
|
9
|
-
assert_nil Psych.load(yml)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_array_nil
|
13
|
-
yml = Psych.dump [nil]
|
14
|
-
assert_equal "---\n- \n", yml
|
15
|
-
assert_equal [nil], Psych.load(yml)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
data/test/psych/test_null.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
module Psych
|
5
|
-
###
|
6
|
-
# Test null from YAML spec:
|
7
|
-
# http://yaml.org/type/null.html
|
8
|
-
class TestNull < TestCase
|
9
|
-
def test_null_list
|
10
|
-
assert_equal [nil] * 5, Psych.load(<<-eoyml)
|
11
|
-
---
|
12
|
-
- ~
|
13
|
-
- null
|
14
|
-
-
|
15
|
-
- Null
|
16
|
-
- NULL
|
17
|
-
eoyml
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/test/psych/test_numeric.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require_relative 'helper'
|
3
|
-
require 'bigdecimal'
|
4
|
-
|
5
|
-
module Psych
|
6
|
-
###
|
7
|
-
# Test numerics from YAML spec:
|
8
|
-
# http://yaml.org/type/float.html
|
9
|
-
# http://yaml.org/type/int.html
|
10
|
-
class TestNumeric < TestCase
|
11
|
-
def setup
|
12
|
-
@old_debug = $DEBUG
|
13
|
-
$DEBUG = true
|
14
|
-
end
|
15
|
-
|
16
|
-
def teardown
|
17
|
-
$DEBUG = @old_debug
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_load_float_with_dot
|
21
|
-
assert_equal 1.0, Psych.load('--- 1.')
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_non_float_with_0
|
25
|
-
str = Psych.load('--- 090')
|
26
|
-
assert_equal '090', str
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_big_decimal_tag
|
30
|
-
decimal = BigDecimal("12.34")
|
31
|
-
assert_match "!ruby/object:BigDecimal", Psych.dump(decimal)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_big_decimal_round_trip
|
35
|
-
decimal = BigDecimal("12.34")
|
36
|
-
assert_cycle decimal
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_does_not_attempt_numeric
|
40
|
-
str = Psych.load('--- 4 roses')
|
41
|
-
assert_equal '4 roses', str
|
42
|
-
str = Psych.load('--- 1.1.1')
|
43
|
-
assert_equal '1.1.1', str
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
data/test/psych/test_object.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
module Psych
|
5
|
-
class Tagged
|
6
|
-
yaml_tag '!foo'
|
7
|
-
|
8
|
-
attr_accessor :baz
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@baz = 'bar'
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class Foo
|
16
|
-
attr_accessor :parent
|
17
|
-
|
18
|
-
def initialize parent
|
19
|
-
@parent = parent
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class TestObject < TestCase
|
24
|
-
def test_dump_with_tag
|
25
|
-
tag = Tagged.new
|
26
|
-
assert_match('foo', Psych.dump(tag))
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_tag_round_trip
|
30
|
-
tag = Tagged.new
|
31
|
-
tag2 = Psych.load(Psych.dump(tag))
|
32
|
-
assert_equal tag.baz, tag2.baz
|
33
|
-
assert_instance_of(Tagged, tag2)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_cyclic_references
|
37
|
-
foo = Foo.new(nil)
|
38
|
-
foo.parent = foo
|
39
|
-
loaded = Psych.load Psych.dump foo
|
40
|
-
|
41
|
-
assert_instance_of(Foo, loaded)
|
42
|
-
assert_equal loaded, loaded.parent
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
module Psych
|
5
|
-
class TestObjectReferences < TestCase
|
6
|
-
def test_range_has_references
|
7
|
-
assert_reference_trip 1..2
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_module_has_references
|
11
|
-
assert_reference_trip Psych
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_class_has_references
|
15
|
-
assert_reference_trip TestObjectReferences
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_rational_has_references
|
19
|
-
assert_reference_trip Rational('1.2')
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_complex_has_references
|
23
|
-
assert_reference_trip Complex(1, 2)
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_datetime_has_references
|
27
|
-
assert_reference_trip DateTime.now
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_struct_has_references
|
31
|
-
assert_reference_trip Struct.new(:foo).new(1)
|
32
|
-
end
|
33
|
-
|
34
|
-
def assert_reference_trip obj
|
35
|
-
yml = Psych.dump([obj, obj])
|
36
|
-
assert_match(/\*-?\d+/, yml)
|
37
|
-
data = Psych.load yml
|
38
|
-
assert_equal data.first.object_id, data.last.object_id
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_float_references
|
42
|
-
data = Psych.load <<-eoyml
|
43
|
-
---\s
|
44
|
-
- &name 1.2
|
45
|
-
- *name
|
46
|
-
eoyml
|
47
|
-
assert_equal data.first, data.last
|
48
|
-
assert_equal data.first.object_id, data.last.object_id
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_binary_references
|
52
|
-
data = Psych.load <<-eoyml
|
53
|
-
---
|
54
|
-
- &name !binary |-
|
55
|
-
aGVsbG8gd29ybGQh
|
56
|
-
- *name
|
57
|
-
eoyml
|
58
|
-
assert_equal data.first, data.last
|
59
|
-
assert_equal data.first.object_id, data.last.object_id
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_regexp_references
|
63
|
-
data = Psych.load <<-eoyml
|
64
|
-
---\s
|
65
|
-
- &name !ruby/regexp /pattern/i
|
66
|
-
- *name
|
67
|
-
eoyml
|
68
|
-
assert_equal data.first, data.last
|
69
|
-
assert_equal data.first.object_id, data.last.object_id
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
data/test/psych/test_omap.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
module Psych
|
5
|
-
class TestOmap < TestCase
|
6
|
-
def test_parse_as_map
|
7
|
-
o = Psych.load "--- !!omap\na: 1\nb: 2"
|
8
|
-
assert_kind_of Psych::Omap, o
|
9
|
-
assert_equal 1, o['a']
|
10
|
-
assert_equal 2, o['b']
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_self_referential
|
14
|
-
map = Psych::Omap.new
|
15
|
-
map['foo'] = 'bar'
|
16
|
-
map['self'] = map
|
17
|
-
assert_equal(map, Psych.load(Psych.dump(map)))
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_keys
|
21
|
-
map = Psych::Omap.new
|
22
|
-
map['foo'] = 'bar'
|
23
|
-
assert_equal 'bar', map['foo']
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_order
|
27
|
-
map = Psych::Omap.new
|
28
|
-
map['a'] = 'b'
|
29
|
-
map['b'] = 'c'
|
30
|
-
assert_equal [%w{a b}, %w{b c}], map.to_a
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_square
|
34
|
-
list = [["a", "b"], ["b", "c"]]
|
35
|
-
map = Psych::Omap[*list.flatten]
|
36
|
-
assert_equal list, map.to_a
|
37
|
-
assert_equal 'b', map['a']
|
38
|
-
assert_equal 'c', map['b']
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_dump
|
42
|
-
map = Psych::Omap['a', 'b', 'c', 'd']
|
43
|
-
yaml = Psych.dump(map)
|
44
|
-
assert_match('!omap', yaml)
|
45
|
-
assert_match('- a: b', yaml)
|
46
|
-
assert_match('- c: d', yaml)
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_round_trip
|
50
|
-
list = [["a", "b"], ["b", "c"]]
|
51
|
-
map = Psych::Omap[*list.flatten]
|
52
|
-
assert_cycle(map)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_load
|
56
|
-
list = [["a", "b"], ["c", "d"]]
|
57
|
-
map = Psych.load(<<-eoyml)
|
58
|
-
--- !omap
|
59
|
-
- a: b
|
60
|
-
- c: d
|
61
|
-
eoyml
|
62
|
-
assert_equal list, map.to_a
|
63
|
-
end
|
64
|
-
|
65
|
-
# NOTE: This test will not work with Syck
|
66
|
-
def test_load_shorthand
|
67
|
-
list = [["a", "b"], ["c", "d"]]
|
68
|
-
map = Psych.load(<<-eoyml)
|
69
|
-
--- !!omap
|
70
|
-
- a: b
|
71
|
-
- c: d
|
72
|
-
eoyml
|
73
|
-
assert_equal list, map.to_a
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
data/test/psych/test_parser.rb
DELETED
@@ -1,340 +0,0 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
# frozen_string_literal: false
|
3
|
-
|
4
|
-
require_relative 'helper'
|
5
|
-
|
6
|
-
module Psych
|
7
|
-
class TestParser < TestCase
|
8
|
-
class EventCatcher < Handler
|
9
|
-
attr_accessor :parser
|
10
|
-
attr_reader :calls, :marks
|
11
|
-
def initialize
|
12
|
-
@parser = nil
|
13
|
-
@calls = []
|
14
|
-
@marks = []
|
15
|
-
end
|
16
|
-
|
17
|
-
(Handler.instance_methods(true) -
|
18
|
-
Object.instance_methods).each do |m|
|
19
|
-
class_eval %{
|
20
|
-
def #{m} *args
|
21
|
-
super
|
22
|
-
@marks << @parser.mark if @parser
|
23
|
-
@calls << [:#{m}, args]
|
24
|
-
end
|
25
|
-
}
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def setup
|
30
|
-
super
|
31
|
-
@handler = EventCatcher.new
|
32
|
-
@parser = Psych::Parser.new @handler
|
33
|
-
@handler.parser = @parser
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_ast_roundtrip
|
37
|
-
parser = Psych.parser
|
38
|
-
parser.parse('null')
|
39
|
-
ast = parser.handler.root
|
40
|
-
assert_match(/^null/, ast.yaml)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_exception_memory_leak
|
44
|
-
yaml = <<-eoyaml
|
45
|
-
%YAML 1.1
|
46
|
-
%TAG ! tag:tenderlovemaking.com,2009:
|
47
|
-
--- &ponies
|
48
|
-
- first element
|
49
|
-
- *ponies
|
50
|
-
- foo: bar
|
51
|
-
...
|
52
|
-
eoyaml
|
53
|
-
|
54
|
-
[:start_stream, :start_document, :end_document, :alias, :scalar,
|
55
|
-
:start_sequence, :end_sequence, :start_mapping, :end_mapping,
|
56
|
-
:end_stream].each do |method|
|
57
|
-
|
58
|
-
klass = Class.new(Psych::Handler) do
|
59
|
-
define_method(method) do |*args|
|
60
|
-
raise
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
parser = Psych::Parser.new klass.new
|
65
|
-
2.times {
|
66
|
-
assert_raises(RuntimeError, method.to_s) do
|
67
|
-
parser.parse yaml
|
68
|
-
end
|
69
|
-
}
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_multiparse
|
74
|
-
3.times do
|
75
|
-
@parser.parse '--- foo'
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_filename
|
80
|
-
ex = assert_raises(Psych::SyntaxError) do
|
81
|
-
@parser.parse '--- `', 'omg!'
|
82
|
-
end
|
83
|
-
assert_match 'omg!', ex.message
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_line_numbers
|
87
|
-
assert_equal 0, @parser.mark.line
|
88
|
-
@parser.parse "---\n- hello\n- world"
|
89
|
-
line_calls = @handler.marks.map(&:line).zip(@handler.calls.map(&:first))
|
90
|
-
assert_equal [[0, :start_stream],
|
91
|
-
[0, :start_document],
|
92
|
-
[1, :start_sequence],
|
93
|
-
[2, :scalar],
|
94
|
-
[3, :scalar],
|
95
|
-
[3, :end_sequence],
|
96
|
-
[3, :end_document],
|
97
|
-
[3, :end_stream]], line_calls
|
98
|
-
|
99
|
-
assert_equal 3, @parser.mark.line
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_column_numbers
|
103
|
-
assert_equal 0, @parser.mark.column
|
104
|
-
@parser.parse "---\n- hello\n- world"
|
105
|
-
col_calls = @handler.marks.map(&:column).zip(@handler.calls.map(&:first))
|
106
|
-
assert_equal [[0, :start_stream],
|
107
|
-
[3, :start_document],
|
108
|
-
[1, :start_sequence],
|
109
|
-
[0, :scalar],
|
110
|
-
[0, :scalar],
|
111
|
-
[0, :end_sequence],
|
112
|
-
[0, :end_document],
|
113
|
-
[0, :end_stream]], col_calls
|
114
|
-
|
115
|
-
assert_equal 0, @parser.mark.column
|
116
|
-
end
|
117
|
-
|
118
|
-
def test_index_numbers
|
119
|
-
assert_equal 0, @parser.mark.index
|
120
|
-
@parser.parse "---\n- hello\n- world"
|
121
|
-
idx_calls = @handler.marks.map(&:index).zip(@handler.calls.map(&:first))
|
122
|
-
assert_equal [[0, :start_stream],
|
123
|
-
[3, :start_document],
|
124
|
-
[5, :start_sequence],
|
125
|
-
[12, :scalar],
|
126
|
-
[19, :scalar],
|
127
|
-
[19, :end_sequence],
|
128
|
-
[19, :end_document],
|
129
|
-
[19, :end_stream]], idx_calls
|
130
|
-
|
131
|
-
assert_equal 19, @parser.mark.index
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_bom
|
135
|
-
tadpole = 'おたまじゃくし'
|
136
|
-
|
137
|
-
# BOM + text
|
138
|
-
yml = "\uFEFF#{tadpole}".encode('UTF-16LE')
|
139
|
-
@parser.parse yml
|
140
|
-
assert_equal tadpole, @parser.handler.calls[2][1].first
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_external_encoding
|
144
|
-
tadpole = 'おたまじゃくし'
|
145
|
-
|
146
|
-
@parser.external_encoding = Psych::Parser::UTF16LE
|
147
|
-
@parser.parse tadpole.encode 'UTF-16LE'
|
148
|
-
assert_equal tadpole, @parser.handler.calls[2][1].first
|
149
|
-
end
|
150
|
-
|
151
|
-
def test_bogus_io
|
152
|
-
o = Object.new
|
153
|
-
def o.external_encoding; nil end
|
154
|
-
def o.read len; self end
|
155
|
-
|
156
|
-
assert_raises(TypeError) do
|
157
|
-
@parser.parse o
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
def test_parse_io
|
162
|
-
@parser.parse StringIO.new("--- a")
|
163
|
-
assert_called :start_stream
|
164
|
-
assert_called :scalar
|
165
|
-
assert_called :end_stream
|
166
|
-
end
|
167
|
-
|
168
|
-
def test_syntax_error
|
169
|
-
assert_raises(Psych::SyntaxError) do
|
170
|
-
@parser.parse("---\n\"foo\"\n\"bar\"\n")
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
def test_syntax_error_twice
|
175
|
-
assert_raises(Psych::SyntaxError) do
|
176
|
-
@parser.parse("---\n\"foo\"\n\"bar\"\n")
|
177
|
-
end
|
178
|
-
|
179
|
-
assert_raises(Psych::SyntaxError) do
|
180
|
-
@parser.parse("---\n\"foo\"\n\"bar\"\n")
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_syntax_error_has_path_for_string
|
185
|
-
e = assert_raises(Psych::SyntaxError) do
|
186
|
-
@parser.parse("---\n\"foo\"\n\"bar\"\n")
|
187
|
-
end
|
188
|
-
assert_match '(<unknown>):', e.message
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_syntax_error_has_path_for_io
|
192
|
-
io = StringIO.new "---\n\"foo\"\n\"bar\"\n"
|
193
|
-
def io.path; "hello!"; end
|
194
|
-
|
195
|
-
e = assert_raises(Psych::SyntaxError) do
|
196
|
-
@parser.parse(io)
|
197
|
-
end
|
198
|
-
assert_match "(#{io.path}):", e.message
|
199
|
-
end
|
200
|
-
|
201
|
-
def test_mapping_end
|
202
|
-
@parser.parse("---\n!!map { key: value }")
|
203
|
-
assert_called :end_mapping
|
204
|
-
end
|
205
|
-
|
206
|
-
def test_mapping_tag
|
207
|
-
@parser.parse("---\n!!map { key: value }")
|
208
|
-
assert_called :start_mapping, ["tag:yaml.org,2002:map", false, Nodes::Mapping::FLOW]
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_mapping_anchor
|
212
|
-
@parser.parse("---\n&A { key: value }")
|
213
|
-
assert_called :start_mapping, ['A', true, Nodes::Mapping::FLOW]
|
214
|
-
end
|
215
|
-
|
216
|
-
def test_mapping_block
|
217
|
-
@parser.parse("---\n key: value")
|
218
|
-
assert_called :start_mapping, [true, Nodes::Mapping::BLOCK]
|
219
|
-
end
|
220
|
-
|
221
|
-
def test_mapping_start
|
222
|
-
@parser.parse("---\n{ key: value }")
|
223
|
-
assert_called :start_mapping
|
224
|
-
assert_called :start_mapping, [true, Nodes::Mapping::FLOW]
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_sequence_end
|
228
|
-
@parser.parse("---\n&A [1, 2]")
|
229
|
-
assert_called :end_sequence
|
230
|
-
end
|
231
|
-
|
232
|
-
def test_sequence_start_anchor
|
233
|
-
@parser.parse("---\n&A [1, 2]")
|
234
|
-
assert_called :start_sequence, ["A", true, Nodes::Sequence::FLOW]
|
235
|
-
end
|
236
|
-
|
237
|
-
def test_sequence_start_tag
|
238
|
-
@parser.parse("---\n!!seq [1, 2]")
|
239
|
-
assert_called :start_sequence, ["tag:yaml.org,2002:seq", false, Nodes::Sequence::FLOW]
|
240
|
-
end
|
241
|
-
|
242
|
-
def test_sequence_start_flow
|
243
|
-
@parser.parse("---\n[1, 2]")
|
244
|
-
assert_called :start_sequence, [true, Nodes::Sequence::FLOW]
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_sequence_start_block
|
248
|
-
@parser.parse("---\n - 1\n - 2")
|
249
|
-
assert_called :start_sequence, [true, Nodes::Sequence::BLOCK]
|
250
|
-
end
|
251
|
-
|
252
|
-
def test_literal_scalar
|
253
|
-
@parser.parse(<<-eoyml)
|
254
|
-
%YAML 1.1
|
255
|
-
---
|
256
|
-
"literal\n\
|
257
|
-
\ttext\n"
|
258
|
-
eoyml
|
259
|
-
assert_called :scalar, ['literal text ', false, true, Nodes::Scalar::DOUBLE_QUOTED]
|
260
|
-
end
|
261
|
-
|
262
|
-
def test_scalar
|
263
|
-
@parser.parse("--- foo\n")
|
264
|
-
assert_called :scalar, ['foo', true, false, Nodes::Scalar::PLAIN]
|
265
|
-
end
|
266
|
-
|
267
|
-
def test_scalar_with_tag
|
268
|
-
@parser.parse("---\n!!str foo\n")
|
269
|
-
assert_called :scalar, ['foo', 'tag:yaml.org,2002:str', false, false, Nodes::Scalar::PLAIN]
|
270
|
-
end
|
271
|
-
|
272
|
-
def test_scalar_with_anchor
|
273
|
-
@parser.parse("---\n&A foo\n")
|
274
|
-
assert_called :scalar, ['foo', 'A', true, false, Nodes::Scalar::PLAIN]
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_scalar_plain_implicit
|
278
|
-
@parser.parse("---\n&A foo\n")
|
279
|
-
assert_called :scalar, ['foo', 'A', true, false, Nodes::Scalar::PLAIN]
|
280
|
-
end
|
281
|
-
|
282
|
-
def test_alias
|
283
|
-
@parser.parse(<<-eoyml)
|
284
|
-
%YAML 1.1
|
285
|
-
---
|
286
|
-
!!seq [
|
287
|
-
!!str "Without properties",
|
288
|
-
&A !!str "Anchored",
|
289
|
-
!!str "Tagged",
|
290
|
-
*A,
|
291
|
-
!!str "",
|
292
|
-
]
|
293
|
-
eoyml
|
294
|
-
assert_called :alias, ['A']
|
295
|
-
end
|
296
|
-
|
297
|
-
def test_end_stream
|
298
|
-
@parser.parse("--- foo\n")
|
299
|
-
assert_called :end_stream
|
300
|
-
end
|
301
|
-
|
302
|
-
def test_start_stream
|
303
|
-
@parser.parse("--- foo\n")
|
304
|
-
assert_called :start_stream
|
305
|
-
end
|
306
|
-
|
307
|
-
def test_end_document_implicit
|
308
|
-
@parser.parse("\"foo\"\n")
|
309
|
-
assert_called :end_document, [true]
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_end_document_explicit
|
313
|
-
@parser.parse("\"foo\"\n...")
|
314
|
-
assert_called :end_document, [false]
|
315
|
-
end
|
316
|
-
|
317
|
-
def test_start_document_version
|
318
|
-
@parser.parse("%YAML 1.1\n---\n\"foo\"\n")
|
319
|
-
assert_called :start_document, [[1,1], [], false]
|
320
|
-
end
|
321
|
-
|
322
|
-
def test_start_document_tag
|
323
|
-
@parser.parse("%TAG !yaml! tag:yaml.org,2002\n---\n!yaml!str \"foo\"\n")
|
324
|
-
assert_called :start_document, [[], [['!yaml!', 'tag:yaml.org,2002']], false]
|
325
|
-
end
|
326
|
-
|
327
|
-
def assert_called call, with = nil, parser = @parser
|
328
|
-
if with
|
329
|
-
call = parser.handler.calls.find { |x|
|
330
|
-
x.first == call && x.last.compact == with
|
331
|
-
}
|
332
|
-
assert(call,
|
333
|
-
"#{[call,with].inspect} not in #{parser.handler.calls.inspect}"
|
334
|
-
)
|
335
|
-
else
|
336
|
-
assert parser.handler.calls.any? { |x| x.first == call }
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
end
|