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.
- checksums.yaml +5 -5
- data/CONTRIBUTING.md +24 -0
- data/{ext/psych/yaml/LICENSE → LICENSE} +9 -7
- data/README.md +80 -0
- data/ext/psych/depend +14 -0
- data/ext/psych/extconf.rb +43 -28
- data/ext/psych/psych.c +6 -4
- data/ext/psych/psych.h +0 -3
- data/ext/psych/psych_emitter.c +165 -132
- data/ext/psych/psych_parser.c +298 -331
- data/ext/psych/psych_to_ruby.c +0 -5
- data/ext/psych/psych_yaml_tree.c +0 -13
- data/lib/psych/class_loader.rb +11 -8
- data/lib/psych/coder.rb +1 -0
- data/lib/psych/core_ext.rb +3 -19
- data/lib/psych/exception.rb +17 -2
- data/lib/psych/handler.rb +8 -2
- data/lib/psych/handlers/document_stream.rb +2 -1
- data/lib/psych/handlers/recorder.rb +2 -1
- data/lib/psych/json/ruby_events.rb +1 -0
- data/lib/psych/json/stream.rb +3 -2
- data/lib/psych/json/tree_builder.rb +2 -1
- data/lib/psych/json/yaml_events.rb +1 -0
- data/lib/psych/nodes/alias.rb +3 -0
- data/lib/psych/nodes/document.rb +3 -0
- data/lib/psych/nodes/mapping.rb +3 -0
- data/lib/psych/nodes/node.rb +25 -5
- data/lib/psych/nodes/scalar.rb +4 -1
- data/lib/psych/nodes/sequence.rb +3 -0
- data/lib/psych/nodes/stream.rb +3 -0
- data/lib/psych/nodes.rb +8 -7
- data/lib/psych/omap.rb +1 -0
- data/lib/psych/parser.rb +14 -0
- data/lib/psych/scalar_scanner.rb +41 -49
- data/lib/psych/set.rb +1 -0
- data/lib/psych/stream.rb +1 -0
- data/lib/psych/streaming.rb +1 -0
- data/lib/psych/syntax_error.rb +2 -1
- data/lib/psych/tree_builder.rb +48 -7
- data/lib/psych/versions.rb +10 -0
- data/lib/psych/visitors/depth_first.rb +1 -0
- data/lib/psych/visitors/emitter.rb +1 -0
- data/lib/psych/visitors/json_tree.rb +2 -1
- data/lib/psych/visitors/to_ruby.rb +64 -33
- data/lib/psych/visitors/visitor.rb +18 -3
- data/lib/psych/visitors/yaml_tree.rb +128 -149
- data/lib/psych/visitors.rb +7 -6
- data/lib/psych/y.rb +1 -0
- data/lib/psych.rb +360 -95
- metadata +36 -169
- data/.autotest +0 -18
- data/.gemtest +0 -0
- data/.travis.yml +0 -11
- data/CHANGELOG.rdoc +0 -562
- data/Manifest.txt +0 -112
- data/README.rdoc +0 -71
- data/Rakefile +0 -74
- data/ext/psych/yaml/api.c +0 -1415
- data/ext/psych/yaml/config.h +0 -10
- data/ext/psych/yaml/dumper.c +0 -394
- data/ext/psych/yaml/emitter.c +0 -2329
- data/ext/psych/yaml/loader.c +0 -459
- data/ext/psych/yaml/parser.c +0 -1370
- data/ext/psych/yaml/reader.c +0 -469
- data/ext/psych/yaml/scanner.c +0 -3583
- data/ext/psych/yaml/writer.c +0 -141
- data/ext/psych/yaml/yaml.h +0 -1971
- data/ext/psych/yaml/yaml_private.h +0 -664
- data/lib/psych/deprecated.rb +0 -85
- data/test/psych/handlers/test_recorder.rb +0 -25
- data/test/psych/helper.rb +0 -114
- data/test/psych/json/test_stream.rb +0 -109
- data/test/psych/nodes/test_enumerable.rb +0 -43
- data/test/psych/test_alias_and_anchor.rb +0 -96
- data/test/psych/test_array.rb +0 -57
- data/test/psych/test_boolean.rb +0 -36
- data/test/psych/test_class.rb +0 -36
- data/test/psych/test_coder.rb +0 -184
- data/test/psych/test_date_time.rb +0 -38
- data/test/psych/test_deprecated.rb +0 -214
- data/test/psych/test_document.rb +0 -46
- data/test/psych/test_emitter.rb +0 -93
- data/test/psych/test_encoding.rb +0 -259
- data/test/psych/test_exception.rb +0 -157
- data/test/psych/test_hash.rb +0 -94
- data/test/psych/test_json_tree.rb +0 -65
- data/test/psych/test_marshalable.rb +0 -54
- data/test/psych/test_merge_keys.rb +0 -180
- data/test/psych/test_nil.rb +0 -18
- data/test/psych/test_null.rb +0 -19
- data/test/psych/test_numeric.rb +0 -45
- data/test/psych/test_object.rb +0 -44
- data/test/psych/test_object_references.rb +0 -71
- data/test/psych/test_omap.rb +0 -75
- data/test/psych/test_parser.rb +0 -339
- data/test/psych/test_psych.rb +0 -168
- data/test/psych/test_safe_load.rb +0 -97
- data/test/psych/test_scalar.rb +0 -11
- data/test/psych/test_scalar_scanner.rb +0 -106
- data/test/psych/test_serialize_subclasses.rb +0 -38
- data/test/psych/test_set.rb +0 -49
- data/test/psych/test_stream.rb +0 -93
- data/test/psych/test_string.rb +0 -226
- data/test/psych/test_struct.rb +0 -49
- data/test/psych/test_symbol.rb +0 -25
- data/test/psych/test_tainted.rb +0 -130
- data/test/psych/test_to_yaml_properties.rb +0 -63
- data/test/psych/test_tree_builder.rb +0 -79
- data/test/psych/test_yaml.rb +0 -1288
- data/test/psych/test_yamldbm.rb +0 -193
- data/test/psych/test_yamlstore.rb +0 -85
- data/test/psych/visitors/test_depth_first.rb +0 -49
- data/test/psych/visitors/test_emitter.rb +0 -144
- data/test/psych/visitors/test_to_ruby.rb +0 -326
- data/test/psych/visitors/test_yaml_tree.rb +0 -173
data/test/psych/test_coder.rb
DELETED
@@ -1,184 +0,0 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
|
3
|
-
module Psych
|
4
|
-
class TestCoder < TestCase
|
5
|
-
class InitApi
|
6
|
-
attr_accessor :implicit
|
7
|
-
attr_accessor :style
|
8
|
-
attr_accessor :tag
|
9
|
-
attr_accessor :a, :b, :c
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
@a = 1
|
13
|
-
@b = 2
|
14
|
-
@c = 3
|
15
|
-
end
|
16
|
-
|
17
|
-
def init_with coder
|
18
|
-
@a = coder['aa']
|
19
|
-
@b = coder['bb']
|
20
|
-
@implicit = coder.implicit
|
21
|
-
@tag = coder.tag
|
22
|
-
@style = coder.style
|
23
|
-
end
|
24
|
-
|
25
|
-
def encode_with coder
|
26
|
-
coder['aa'] = @a
|
27
|
-
coder['bb'] = @b
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class TaggingCoder < InitApi
|
32
|
-
def encode_with coder
|
33
|
-
super
|
34
|
-
coder.tag = coder.tag.sub(/!/, '!hello')
|
35
|
-
coder.implicit = false
|
36
|
-
coder.style = Psych::Nodes::Mapping::FLOW
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class ScalarCoder
|
41
|
-
def encode_with coder
|
42
|
-
coder.scalar = "foo"
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class Represent
|
47
|
-
yaml_tag 'foo'
|
48
|
-
def encode_with coder
|
49
|
-
coder.represent_scalar 'foo', 'bar'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
class RepresentWithInit
|
54
|
-
yaml_tag name
|
55
|
-
attr_accessor :str
|
56
|
-
|
57
|
-
def init_with coder
|
58
|
-
@str = coder.scalar
|
59
|
-
end
|
60
|
-
|
61
|
-
def encode_with coder
|
62
|
-
coder.represent_scalar self.class.name, 'bar'
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class RepresentWithSeq
|
67
|
-
yaml_tag name
|
68
|
-
attr_accessor :seq
|
69
|
-
|
70
|
-
def init_with coder
|
71
|
-
@seq = coder.seq
|
72
|
-
end
|
73
|
-
|
74
|
-
def encode_with coder
|
75
|
-
coder.represent_seq self.class.name, %w{ foo bar }
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
class RepresentWithMap
|
80
|
-
yaml_tag name
|
81
|
-
attr_accessor :map
|
82
|
-
|
83
|
-
def init_with coder
|
84
|
-
@map = coder.map
|
85
|
-
end
|
86
|
-
|
87
|
-
def encode_with coder
|
88
|
-
coder.represent_map self.class.name, { "string" => 'a', :symbol => 'b' }
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class RepresentWithObject
|
93
|
-
def encode_with coder
|
94
|
-
coder.represent_object self.class.name, 20
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_represent_with_object
|
99
|
-
thing = Psych.load(Psych.dump(RepresentWithObject.new))
|
100
|
-
assert_equal 20, thing
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_json_dump_exclude_tag
|
104
|
-
refute_match('TestCoder::InitApi', Psych.to_json(InitApi.new))
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_map_takes_block
|
108
|
-
coder = Psych::Coder.new 'foo'
|
109
|
-
tag = coder.tag
|
110
|
-
style = coder.style
|
111
|
-
coder.map { |map| map.add 'foo', 'bar' }
|
112
|
-
assert_equal 'bar', coder['foo']
|
113
|
-
assert_equal tag, coder.tag
|
114
|
-
assert_equal style, coder.style
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_map_with_tag
|
118
|
-
coder = Psych::Coder.new 'foo'
|
119
|
-
coder.map('hello') { |map| map.add 'foo', 'bar' }
|
120
|
-
assert_equal 'bar', coder['foo']
|
121
|
-
assert_equal 'hello', coder.tag
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_map_with_tag_and_style
|
125
|
-
coder = Psych::Coder.new 'foo'
|
126
|
-
coder.map('hello', 'world') { |map| map.add 'foo', 'bar' }
|
127
|
-
assert_equal 'bar', coder['foo']
|
128
|
-
assert_equal 'hello', coder.tag
|
129
|
-
assert_equal 'world', coder.style
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_represent_map
|
133
|
-
thing = Psych.load(Psych.dump(RepresentWithMap.new))
|
134
|
-
assert_equal({ "string" => 'a', :symbol => 'b' }, thing.map)
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_represent_sequence
|
138
|
-
thing = Psych.load(Psych.dump(RepresentWithSeq.new))
|
139
|
-
assert_equal %w{ foo bar }, thing.seq
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_represent_with_init
|
143
|
-
thing = Psych.load(Psych.dump(RepresentWithInit.new))
|
144
|
-
assert_equal 'bar', thing.str
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_represent!
|
148
|
-
assert_match(/foo/, Psych.dump(Represent.new))
|
149
|
-
assert_instance_of(Represent, Psych.load(Psych.dump(Represent.new)))
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_scalar_coder
|
153
|
-
foo = Psych.load(Psych.dump(ScalarCoder.new))
|
154
|
-
assert_equal 'foo', foo
|
155
|
-
end
|
156
|
-
|
157
|
-
def test_load_dumped_tagging
|
158
|
-
foo = InitApi.new
|
159
|
-
bar = Psych.load(Psych.dump(foo))
|
160
|
-
assert_equal false, bar.implicit
|
161
|
-
assert_equal "!ruby/object:Psych::TestCoder::InitApi", bar.tag
|
162
|
-
assert_equal Psych::Nodes::Mapping::BLOCK, bar.style
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_dump_with_tag
|
166
|
-
foo = TaggingCoder.new
|
167
|
-
assert_match(/hello/, Psych.dump(foo))
|
168
|
-
assert_match(/\{aa/, Psych.dump(foo))
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_dump_encode_with
|
172
|
-
foo = InitApi.new
|
173
|
-
assert_match(/aa/, Psych.dump(foo))
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_dump_init_with
|
177
|
-
foo = InitApi.new
|
178
|
-
bar = Psych.load(Psych.dump(foo))
|
179
|
-
assert_equal foo.a, bar.a
|
180
|
-
assert_equal foo.b, bar.b
|
181
|
-
assert_nil bar.c
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
require 'date'
|
3
|
-
|
4
|
-
module Psych
|
5
|
-
class TestDateTime < TestCase
|
6
|
-
def test_negative_year
|
7
|
-
time = Time.utc -1, 12, 16
|
8
|
-
assert_cycle time
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_new_datetime
|
12
|
-
assert_cycle DateTime.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_invalid_date
|
16
|
-
assert_cycle "2013-10-31T10:40:07-000000000000033"
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_string_tag
|
20
|
-
dt = DateTime.now
|
21
|
-
yaml = Psych.dump dt
|
22
|
-
assert_match(/DateTime/, yaml)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_round_trip
|
26
|
-
dt = DateTime.now
|
27
|
-
assert_cycle dt
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_alias_with_time
|
31
|
-
t = Time.now
|
32
|
-
h = {:a => t, :b => t}
|
33
|
-
yaml = Psych.dump h
|
34
|
-
assert_match('&', yaml)
|
35
|
-
assert_match('*', yaml)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,214 +0,0 @@
|
|
1
|
-
require_relative 'helper'
|
2
|
-
|
3
|
-
module Psych
|
4
|
-
class TestDeprecated < TestCase
|
5
|
-
def teardown
|
6
|
-
$VERBOSE = @orig_verbose
|
7
|
-
Psych.domain_types.clear
|
8
|
-
end
|
9
|
-
|
10
|
-
class QuickEmitter
|
11
|
-
attr_reader :name
|
12
|
-
attr_reader :value
|
13
|
-
|
14
|
-
def initialize
|
15
|
-
@name = 'hello!!'
|
16
|
-
@value = 'Friday!'
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_yaml opts = {}
|
20
|
-
Psych.quick_emit object_id, opts do |out|
|
21
|
-
out.map taguri, to_yaml_style do |map|
|
22
|
-
map.add 'name', @name
|
23
|
-
map.add 'value', nil
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def setup
|
30
|
-
@qe = QuickEmitter.new
|
31
|
-
@orig_verbose, $VERBOSE = $VERBOSE, false
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_quick_emit
|
35
|
-
qe2 = Psych.load @qe.to_yaml
|
36
|
-
assert_equal @qe.name, qe2.name
|
37
|
-
assert_instance_of QuickEmitter, qe2
|
38
|
-
assert_nil qe2.value
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_recursive_quick_emit
|
42
|
-
hash = { :qe => @qe }
|
43
|
-
hash2 = Psych.load Psych.dump hash
|
44
|
-
qe = hash2[:qe]
|
45
|
-
|
46
|
-
assert_equal @qe.name, qe.name
|
47
|
-
assert_instance_of QuickEmitter, qe
|
48
|
-
assert_nil qe.value
|
49
|
-
end
|
50
|
-
|
51
|
-
class QuickEmitterEncodeWith
|
52
|
-
attr_reader :name
|
53
|
-
attr_reader :value
|
54
|
-
|
55
|
-
def initialize
|
56
|
-
@name = 'hello!!'
|
57
|
-
@value = 'Friday!'
|
58
|
-
end
|
59
|
-
|
60
|
-
def encode_with coder
|
61
|
-
coder.map do |map|
|
62
|
-
map.add 'name', @name
|
63
|
-
map.add 'value', nil
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def to_yaml opts = {}
|
68
|
-
raise
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
###
|
73
|
-
# An object that defines both to_yaml and encode_with should only call
|
74
|
-
# encode_with.
|
75
|
-
def test_recursive_quick_emit_encode_with
|
76
|
-
qeew = QuickEmitterEncodeWith.new
|
77
|
-
hash = { :qe => qeew }
|
78
|
-
hash2 = Psych.load Psych.dump hash
|
79
|
-
qe = hash2[:qe]
|
80
|
-
|
81
|
-
assert_equal qeew.name, qe.name
|
82
|
-
assert_instance_of QuickEmitterEncodeWith, qe
|
83
|
-
assert_nil qe.value
|
84
|
-
end
|
85
|
-
|
86
|
-
class YamlInit
|
87
|
-
attr_reader :name
|
88
|
-
attr_reader :value
|
89
|
-
|
90
|
-
def initialize
|
91
|
-
@name = 'hello!!'
|
92
|
-
@value = 'Friday!'
|
93
|
-
end
|
94
|
-
|
95
|
-
def yaml_initialize tag, vals
|
96
|
-
vals.each { |ivar, val| instance_variable_set "@#{ivar}", 'TGIF!' }
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_yaml_initialize
|
101
|
-
hash = { :yi => YamlInit.new }
|
102
|
-
hash2 = Psych.load Psych.dump hash
|
103
|
-
yi = hash2[:yi]
|
104
|
-
|
105
|
-
assert_equal 'TGIF!', yi.name
|
106
|
-
assert_equal 'TGIF!', yi.value
|
107
|
-
assert_instance_of YamlInit, yi
|
108
|
-
end
|
109
|
-
|
110
|
-
class YamlInitAndInitWith
|
111
|
-
attr_reader :name
|
112
|
-
attr_reader :value
|
113
|
-
|
114
|
-
def initialize
|
115
|
-
@name = 'shaners'
|
116
|
-
@value = 'Friday!'
|
117
|
-
end
|
118
|
-
|
119
|
-
def init_with coder
|
120
|
-
coder.map.each { |ivar, val| instance_variable_set "@#{ivar}", 'TGIF!' }
|
121
|
-
end
|
122
|
-
|
123
|
-
def yaml_initialize tag, vals
|
124
|
-
raise
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
###
|
129
|
-
# An object that implements both yaml_initialize and init_with should not
|
130
|
-
# receive the yaml_initialize call.
|
131
|
-
def test_yaml_initialize_and_init_with
|
132
|
-
hash = { :yi => YamlInitAndInitWith.new }
|
133
|
-
hash2 = Psych.load Psych.dump hash
|
134
|
-
yi = hash2[:yi]
|
135
|
-
|
136
|
-
assert_equal 'TGIF!', yi.name
|
137
|
-
assert_equal 'TGIF!', yi.value
|
138
|
-
assert_instance_of YamlInitAndInitWith, yi
|
139
|
-
end
|
140
|
-
|
141
|
-
def test_coder_scalar
|
142
|
-
coder = Psych::Coder.new 'foo'
|
143
|
-
coder.scalar('tag', 'some string', :plain)
|
144
|
-
assert_equal 'tag', coder.tag
|
145
|
-
assert_equal 'some string', coder.scalar
|
146
|
-
assert_equal :scalar, coder.type
|
147
|
-
end
|
148
|
-
|
149
|
-
class YamlAs
|
150
|
-
TestCase.suppress_warning do
|
151
|
-
psych_yaml_as 'helloworld' # this should be yaml_as but to avoid syck
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_yaml_as
|
156
|
-
assert_match(/helloworld/, Psych.dump(YamlAs.new))
|
157
|
-
end
|
158
|
-
|
159
|
-
def test_ruby_type
|
160
|
-
types = []
|
161
|
-
appender = lambda { |*args| types << args }
|
162
|
-
|
163
|
-
Psych.add_ruby_type('foo', &appender)
|
164
|
-
Psych.load <<-eoyml
|
165
|
-
- !ruby.yaml.org,2002/foo bar
|
166
|
-
eoyml
|
167
|
-
|
168
|
-
assert_equal [["tag:ruby.yaml.org,2002:foo", "bar"]], types
|
169
|
-
end
|
170
|
-
|
171
|
-
def test_detect_implicit
|
172
|
-
assert_equal '', Psych.detect_implicit(nil)
|
173
|
-
assert_equal '', Psych.detect_implicit(Object.new)
|
174
|
-
assert_equal '', Psych.detect_implicit(1.2)
|
175
|
-
assert_equal 'null', Psych.detect_implicit('')
|
176
|
-
assert_equal 'string', Psych.detect_implicit('foo')
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_private_type
|
180
|
-
types = []
|
181
|
-
Psych.add_private_type('foo') { |*args| types << args }
|
182
|
-
Psych.load <<-eoyml
|
183
|
-
- !x-private:foo bar
|
184
|
-
eoyml
|
185
|
-
|
186
|
-
assert_equal [["x-private:foo", "bar"]], types
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_tagurize
|
190
|
-
assert_nil Psych.tagurize nil
|
191
|
-
assert_equal Psych, Psych.tagurize(Psych)
|
192
|
-
assert_equal 'tag:yaml.org,2002:foo', Psych.tagurize('foo')
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_read_type_class
|
196
|
-
things = Psych.read_type_class 'tag:yaml.org,2002:int:Psych::TestDeprecated::QuickEmitter', Object
|
197
|
-
assert_equal 'int', things.first
|
198
|
-
assert_equal Psych::TestDeprecated::QuickEmitter, things.last
|
199
|
-
end
|
200
|
-
|
201
|
-
def test_read_type_class_no_class
|
202
|
-
things = Psych.read_type_class 'tag:yaml.org,2002:int', Object
|
203
|
-
assert_equal 'int', things.first
|
204
|
-
assert_equal Object, things.last
|
205
|
-
end
|
206
|
-
|
207
|
-
def test_object_maker
|
208
|
-
thing = Psych.object_maker(Object, { 'a' => 'b', 'c' => 'd' })
|
209
|
-
assert_instance_of(Object, thing)
|
210
|
-
assert_equal 'b', thing.instance_variable_get(:@a)
|
211
|
-
assert_equal 'd', thing.instance_variable_get(:@c)
|
212
|
-
end
|
213
|
-
end
|
214
|
-
end
|
data/test/psych/test_document.rb
DELETED
@@ -1,46 +0,0 @@
|
|
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
|
data/test/psych/test_emitter.rb
DELETED
@@ -1,93 +0,0 @@
|
|
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
|