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,36 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
###
|
5
|
+
# Test booleans from YAML spec:
|
6
|
+
# http://yaml.org/type/bool.html
|
7
|
+
class TestBoolean < TestCase
|
8
|
+
%w{ yes Yes YES true True TRUE on On ON }.each do |truth|
|
9
|
+
define_method(:"test_#{truth}") do
|
10
|
+
assert_equal true, Psych.load("--- #{truth}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
%w{ no No NO false False FALSE off Off OFF }.each do |truth|
|
15
|
+
define_method(:"test_#{truth}") do
|
16
|
+
assert_equal false, Psych.load("--- #{truth}")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
###
|
21
|
+
# YAML spec says "y" and "Y" may be used as true, but Syck treats them
|
22
|
+
# as literal strings
|
23
|
+
def test_y
|
24
|
+
assert_equal "y", Psych.load("--- y")
|
25
|
+
assert_equal "Y", Psych.load("--- Y")
|
26
|
+
end
|
27
|
+
|
28
|
+
###
|
29
|
+
# YAML spec says "n" and "N" may be used as false, but Syck treats them
|
30
|
+
# as literal strings
|
31
|
+
def test_n
|
32
|
+
assert_equal "n", Psych.load("--- n")
|
33
|
+
assert_equal "N", Psych.load("--- N")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
class TestClass < TestCase
|
5
|
+
module Foo
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_cycle_anonymous_class
|
9
|
+
assert_raises(::TypeError) do
|
10
|
+
assert_cycle(Class.new)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_cycle_anonymous_module
|
15
|
+
assert_raises(::TypeError) do
|
16
|
+
assert_cycle(Module.new)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_cycle
|
21
|
+
assert_cycle(TestClass)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_dump
|
25
|
+
Psych.dump TestClass
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_cycle_module
|
29
|
+
assert_cycle(Foo)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_dump_module
|
33
|
+
Psych.dump Foo
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,206 @@
|
|
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
|
+
class Referential
|
99
|
+
attr_reader :a
|
100
|
+
|
101
|
+
def initialize
|
102
|
+
@a = self
|
103
|
+
end
|
104
|
+
|
105
|
+
def encode_with(c)
|
106
|
+
c['a'] = @a
|
107
|
+
end
|
108
|
+
|
109
|
+
def init_with(c)
|
110
|
+
@a = c['a']
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_self_referential
|
115
|
+
x = Referential.new
|
116
|
+
copy = Psych.load Psych.dump x
|
117
|
+
assert_equal copy, copy.a
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_represent_with_object
|
121
|
+
thing = Psych.load(Psych.dump(RepresentWithObject.new))
|
122
|
+
assert_equal 20, thing
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_json_dump_exclude_tag
|
126
|
+
refute_match('TestCoder::InitApi', Psych.to_json(InitApi.new))
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_map_takes_block
|
130
|
+
coder = Psych::Coder.new 'foo'
|
131
|
+
tag = coder.tag
|
132
|
+
style = coder.style
|
133
|
+
coder.map { |map| map.add 'foo', 'bar' }
|
134
|
+
assert_equal 'bar', coder['foo']
|
135
|
+
assert_equal tag, coder.tag
|
136
|
+
assert_equal style, coder.style
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_map_with_tag
|
140
|
+
coder = Psych::Coder.new 'foo'
|
141
|
+
coder.map('hello') { |map| map.add 'foo', 'bar' }
|
142
|
+
assert_equal 'bar', coder['foo']
|
143
|
+
assert_equal 'hello', coder.tag
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_map_with_tag_and_style
|
147
|
+
coder = Psych::Coder.new 'foo'
|
148
|
+
coder.map('hello', 'world') { |map| map.add 'foo', 'bar' }
|
149
|
+
assert_equal 'bar', coder['foo']
|
150
|
+
assert_equal 'hello', coder.tag
|
151
|
+
assert_equal 'world', coder.style
|
152
|
+
end
|
153
|
+
|
154
|
+
def test_represent_map
|
155
|
+
thing = Psych.load(Psych.dump(RepresentWithMap.new))
|
156
|
+
assert_equal({ "string" => 'a', :symbol => 'b' }, thing.map)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_represent_sequence
|
160
|
+
thing = Psych.load(Psych.dump(RepresentWithSeq.new))
|
161
|
+
assert_equal %w{ foo bar }, thing.seq
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_represent_with_init
|
165
|
+
thing = Psych.load(Psych.dump(RepresentWithInit.new))
|
166
|
+
assert_equal 'bar', thing.str
|
167
|
+
end
|
168
|
+
|
169
|
+
def test_represent!
|
170
|
+
assert_match(/foo/, Psych.dump(Represent.new))
|
171
|
+
assert_instance_of(Represent, Psych.load(Psych.dump(Represent.new)))
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_scalar_coder
|
175
|
+
foo = Psych.load(Psych.dump(ScalarCoder.new))
|
176
|
+
assert_equal 'foo', foo
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_load_dumped_tagging
|
180
|
+
foo = InitApi.new
|
181
|
+
bar = Psych.load(Psych.dump(foo))
|
182
|
+
assert_equal false, bar.implicit
|
183
|
+
assert_equal "!ruby/object:Psych::TestCoder::InitApi", bar.tag
|
184
|
+
assert_equal Psych::Nodes::Mapping::BLOCK, bar.style
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_dump_with_tag
|
188
|
+
foo = TaggingCoder.new
|
189
|
+
assert_match(/hello/, Psych.dump(foo))
|
190
|
+
assert_match(/\{aa/, Psych.dump(foo))
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_dump_encode_with
|
194
|
+
foo = InitApi.new
|
195
|
+
assert_match(/aa/, Psych.dump(foo))
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_dump_init_with
|
199
|
+
foo = InitApi.new
|
200
|
+
bar = Psych.load(Psych.dump(foo))
|
201
|
+
assert_equal foo.a, bar.a
|
202
|
+
assert_equal foo.b, bar.b
|
203
|
+
assert_nil bar.c
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
@@ -0,0 +1,38 @@
|
|
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
|
@@ -0,0 +1,214 @@
|
|
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
|