psych-shopifork 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.autotest +18 -0
- data/.gemtest +0 -0
- data/.travis.yml +9 -0
- data/CHANGELOG.rdoc +414 -0
- data/Manifest.txt +113 -0
- data/README.rdoc +71 -0
- data/Rakefile +72 -0
- data/ext/psych/depend +3 -0
- data/ext/psych/extconf.rb +36 -0
- data/ext/psych/psych.c +34 -0
- data/ext/psych/psych.h +20 -0
- data/ext/psych/psych_emitter.c +538 -0
- data/ext/psych/psych_emitter.h +8 -0
- data/ext/psych/psych_parser.c +579 -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 +1392 -0
- data/ext/psych/yaml/config.h +11 -0
- data/ext/psych/yaml/dumper.c +394 -0
- data/ext/psych/yaml/emitter.c +2335 -0
- data/ext/psych/yaml/loader.c +432 -0
- data/ext/psych/yaml/parser.c +1374 -0
- data/ext/psych/yaml/reader.c +465 -0
- data/ext/psych/yaml/scanner.c +3570 -0
- data/ext/psych/yaml/writer.c +141 -0
- data/ext/psych/yaml/yaml.h +1971 -0
- data/ext/psych/yaml/yaml_private.h +643 -0
- data/lib/psych.rb +497 -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/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 +372 -0
- data/lib/psych/visitors/visitor.rb +19 -0
- data/lib/psych/visitors/yaml_tree.rb +507 -0
- data/lib/psych/y.rb +9 -0
- data/test/psych/handlers/test_recorder.rb +25 -0
- data/test/psych/helper.rb +114 -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 +184 -0
- data/test/psych/test_date_time.rb +25 -0
- data/test/psych/test_deprecated.rb +214 -0
- data/test/psych/test_document.rb +46 -0
- data/test/psych/test_emitter.rb +94 -0
- data/test/psych/test_encoding.rb +254 -0
- data/test/psych/test_engine_manager.rb +47 -0
- data/test/psych/test_exception.rb +151 -0
- data/test/psych/test_hash.rb +44 -0
- data/test/psych/test_json_tree.rb +65 -0
- data/test/psych/test_merge_keys.rb +132 -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 +67 -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 +153 -0
- data/test/psych/test_struct.rb +49 -0
- data/test/psych/test_symbol.rb +17 -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 +1289 -0
- data/test/psych/test_yamldbm.rb +197 -0
- data/test/psych/test_yamlstore.rb +87 -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 +326 -0
- data/test/psych/visitors/test_yaml_tree.rb +173 -0
- metadata +257 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
class TestHash < TestCase
|
5
|
+
class X < Hash
|
6
|
+
end
|
7
|
+
|
8
|
+
def setup
|
9
|
+
super
|
10
|
+
@hash = { :a => 'b' }
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_empty_subclass
|
14
|
+
assert_match "!ruby/hash:#{X}", Psych.dump(X.new)
|
15
|
+
x = Psych.load Psych.dump X.new
|
16
|
+
assert_equal X, x.class
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_map
|
20
|
+
x = Psych.load "--- !map:#{X} { }\n"
|
21
|
+
assert_equal X, x.class
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_self_referential
|
25
|
+
@hash['self'] = @hash
|
26
|
+
assert_cycle(@hash)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_cycles
|
30
|
+
assert_cycle(@hash)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_ref_append
|
34
|
+
hash = Psych.load(<<-eoyml)
|
35
|
+
---
|
36
|
+
foo: &foo
|
37
|
+
hello: world
|
38
|
+
bar:
|
39
|
+
<<: *foo
|
40
|
+
eoyml
|
41
|
+
assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
class TestJSONTree < TestCase
|
5
|
+
def test_string
|
6
|
+
assert_match(/"foo"/, Psych.to_json("foo"))
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_symbol
|
10
|
+
assert_match(/"foo"/, Psych.to_json(:foo))
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_nil
|
14
|
+
assert_match(/^null/, Psych.to_json(nil))
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_int
|
18
|
+
assert_match(/^10/, Psych.to_json(10))
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_float
|
22
|
+
assert_match(/^1.2/, Psych.to_json(1.2))
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_hash
|
26
|
+
hash = { 'one' => 'two' }
|
27
|
+
json = Psych.to_json(hash)
|
28
|
+
assert_match(/}$/, json)
|
29
|
+
assert_match(/^\{/, json)
|
30
|
+
assert_match(/['"]one['"]/, json)
|
31
|
+
assert_match(/['"]two['"]/, json)
|
32
|
+
end
|
33
|
+
|
34
|
+
class Bar
|
35
|
+
def encode_with coder
|
36
|
+
coder.represent_seq 'omg', %w{ a b c }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_json_list_dump_exclude_tag
|
41
|
+
json = Psych.to_json Bar.new
|
42
|
+
refute_match('omg', json)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_list_to_json
|
46
|
+
list = %w{ one two }
|
47
|
+
json = Psych.to_json(list)
|
48
|
+
assert_match(/]$/, json)
|
49
|
+
assert_match(/^\[/, json)
|
50
|
+
assert_match(/"one"/, json)
|
51
|
+
assert_match(/"two"/, json)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_time
|
55
|
+
time = Time.utc(2010, 10, 10)
|
56
|
+
assert_equal "{\"a\": \"2010-10-10 00:00:00.000000000 Z\"}\n",
|
57
|
+
Psych.to_json({'a' => time })
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_datetime
|
61
|
+
time = Time.new(2010, 10, 10).to_datetime
|
62
|
+
assert_equal "{\"a\": \"#{time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")}\"}\n", Psych.to_json({'a' => time })
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
class TestMergeKeys < TestCase
|
5
|
+
def test_merge_nil
|
6
|
+
yaml = <<-eoyml
|
7
|
+
defaults: &defaults
|
8
|
+
development:
|
9
|
+
<<: *defaults
|
10
|
+
eoyml
|
11
|
+
assert_equal({'<<' => nil }, Psych.load(yaml)['development'])
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_merge_array
|
15
|
+
yaml = <<-eoyml
|
16
|
+
foo: &hello
|
17
|
+
- 1
|
18
|
+
baz:
|
19
|
+
<<: *hello
|
20
|
+
eoyml
|
21
|
+
assert_equal({'<<' => [1]}, Psych.load(yaml)['baz'])
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_merge_is_not_partial
|
25
|
+
yaml = <<-eoyml
|
26
|
+
default: &default
|
27
|
+
hello: world
|
28
|
+
foo: &hello
|
29
|
+
- 1
|
30
|
+
baz:
|
31
|
+
<<: [*hello, *default]
|
32
|
+
eoyml
|
33
|
+
doc = Psych.load yaml
|
34
|
+
refute doc['baz'].key? 'hello'
|
35
|
+
assert_equal({'<<' => [[1], {"hello"=>"world"}]}, Psych.load(yaml)['baz'])
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_merge_seq_nil
|
39
|
+
yaml = <<-eoyml
|
40
|
+
foo: &hello
|
41
|
+
baz:
|
42
|
+
<<: [*hello]
|
43
|
+
eoyml
|
44
|
+
assert_equal({'<<' => [nil]}, Psych.load(yaml)['baz'])
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_bad_seq_merge
|
48
|
+
yaml = <<-eoyml
|
49
|
+
defaults: &defaults [1, 2, 3]
|
50
|
+
development:
|
51
|
+
<<: *defaults
|
52
|
+
eoyml
|
53
|
+
assert_equal({'<<' => [1,2,3]}, Psych.load(yaml)['development'])
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_missing_merge_key
|
57
|
+
yaml = <<-eoyml
|
58
|
+
bar:
|
59
|
+
<< : *foo
|
60
|
+
eoyml
|
61
|
+
exp = assert_raises(Psych::BadAlias) { Psych.load yaml }
|
62
|
+
assert_match 'foo', exp.message
|
63
|
+
end
|
64
|
+
|
65
|
+
# [ruby-core:34679]
|
66
|
+
def test_merge_key
|
67
|
+
yaml = <<-eoyml
|
68
|
+
foo: &foo
|
69
|
+
hello: world
|
70
|
+
bar:
|
71
|
+
<< : *foo
|
72
|
+
baz: boo
|
73
|
+
eoyml
|
74
|
+
|
75
|
+
hash = {
|
76
|
+
"foo" => { "hello" => "world"},
|
77
|
+
"bar" => { "hello" => "world", "baz" => "boo" } }
|
78
|
+
assert_equal hash, Psych.load(yaml)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_multiple_maps
|
82
|
+
yaml = <<-eoyaml
|
83
|
+
---
|
84
|
+
- &CENTER { x: 1, y: 2 }
|
85
|
+
- &LEFT { x: 0, y: 2 }
|
86
|
+
- &BIG { r: 10 }
|
87
|
+
- &SMALL { r: 1 }
|
88
|
+
|
89
|
+
# All the following maps are equal:
|
90
|
+
|
91
|
+
- # Merge multiple maps
|
92
|
+
<< : [ *CENTER, *BIG ]
|
93
|
+
label: center/big
|
94
|
+
eoyaml
|
95
|
+
|
96
|
+
hash = {
|
97
|
+
'x' => 1,
|
98
|
+
'y' => 2,
|
99
|
+
'r' => 10,
|
100
|
+
'label' => 'center/big'
|
101
|
+
}
|
102
|
+
|
103
|
+
assert_equal hash, Psych.load(yaml)[4]
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_override
|
107
|
+
yaml = <<-eoyaml
|
108
|
+
---
|
109
|
+
- &CENTER { x: 1, y: 2 }
|
110
|
+
- &LEFT { x: 0, y: 2 }
|
111
|
+
- &BIG { r: 10 }
|
112
|
+
- &SMALL { r: 1 }
|
113
|
+
|
114
|
+
# All the following maps are equal:
|
115
|
+
|
116
|
+
- # Override
|
117
|
+
<< : [ *BIG, *LEFT, *SMALL ]
|
118
|
+
x: 1
|
119
|
+
label: center/big
|
120
|
+
eoyaml
|
121
|
+
|
122
|
+
hash = {
|
123
|
+
'x' => 1,
|
124
|
+
'y' => 2,
|
125
|
+
'r' => 10,
|
126
|
+
'label' => 'center/big'
|
127
|
+
}
|
128
|
+
|
129
|
+
assert_equal hash, Psych.load(yaml)[4]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
class TestNil < TestCase
|
5
|
+
def test_nil
|
6
|
+
yml = Psych.dump nil
|
7
|
+
assert_match(/--- \n(?:\.\.\.\n)?/, yml)
|
8
|
+
assert_nil Psych.load(yml)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_array_nil
|
12
|
+
yml = Psych.dump [nil]
|
13
|
+
assert_equal "---\n- \n", yml
|
14
|
+
assert_equal [nil], Psych.load(yml)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
###
|
5
|
+
# Test null from YAML spec:
|
6
|
+
# http://yaml.org/type/null.html
|
7
|
+
class TestNull < TestCase
|
8
|
+
def test_null_list
|
9
|
+
assert_equal [nil] * 5, Psych.load(<<-eoyml)
|
10
|
+
---
|
11
|
+
- ~
|
12
|
+
- null
|
13
|
+
-
|
14
|
+
- Null
|
15
|
+
- NULL
|
16
|
+
eoyml
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
require 'bigdecimal'
|
3
|
+
|
4
|
+
module Psych
|
5
|
+
###
|
6
|
+
# Test numerics from YAML spec:
|
7
|
+
# http://yaml.org/type/float.html
|
8
|
+
# http://yaml.org/type/int.html
|
9
|
+
class TestNumeric < TestCase
|
10
|
+
def setup
|
11
|
+
@old_debug = $DEBUG
|
12
|
+
$DEBUG = true
|
13
|
+
end
|
14
|
+
|
15
|
+
def teardown
|
16
|
+
$DEBUG = @old_debug
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_load_float_with_dot
|
20
|
+
assert_equal 1.0, Psych.load('--- 1.')
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_non_float_with_0
|
24
|
+
str = Psych.load('--- 090')
|
25
|
+
assert_equal '090', str
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_big_decimal_tag
|
29
|
+
decimal = BigDecimal("12.34")
|
30
|
+
assert_match "!ruby/object:BigDecimal", Psych.dump(decimal)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_big_decimal_round_trip
|
34
|
+
decimal = BigDecimal("12.34")
|
35
|
+
assert_cycle decimal
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_does_not_attempt_numeric
|
39
|
+
str = Psych.load('--- 4 roses')
|
40
|
+
assert_equal '4 roses', str
|
41
|
+
str = Psych.load('--- 1.1.1')
|
42
|
+
assert_equal '1.1.1', str
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'helper'
|
2
|
+
|
3
|
+
module Psych
|
4
|
+
class Tagged
|
5
|
+
yaml_tag '!foo'
|
6
|
+
|
7
|
+
attr_accessor :baz
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@baz = 'bar'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Foo
|
15
|
+
attr_accessor :parent
|
16
|
+
|
17
|
+
def initialize parent
|
18
|
+
@parent = parent
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class TestObject < TestCase
|
23
|
+
def test_dump_with_tag
|
24
|
+
tag = Tagged.new
|
25
|
+
assert_match('foo', Psych.dump(tag))
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_tag_round_trip
|
29
|
+
tag = Tagged.new
|
30
|
+
tag2 = Psych.load(Psych.dump(tag))
|
31
|
+
assert_equal tag.baz, tag2.baz
|
32
|
+
assert_instance_of(Tagged, tag2)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_cyclic_references
|
36
|
+
foo = Foo.new(nil)
|
37
|
+
foo.parent = foo
|
38
|
+
loaded = Psych.load Psych.dump foo
|
39
|
+
|
40
|
+
assert_instance_of(Foo, loaded)
|
41
|
+
assert_equal loaded, loaded.parent
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,67 @@
|
|
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 assert_reference_trip obj
|
30
|
+
yml = Psych.dump([obj, obj])
|
31
|
+
assert_match(/\*-?\d+/, yml)
|
32
|
+
data = Psych.load yml
|
33
|
+
assert_equal data.first.object_id, data.last.object_id
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_float_references
|
37
|
+
data = Psych.load <<-eoyml
|
38
|
+
---\s
|
39
|
+
- &name 1.2
|
40
|
+
- *name
|
41
|
+
eoyml
|
42
|
+
assert_equal data.first, data.last
|
43
|
+
assert_equal data.first.object_id, data.last.object_id
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_binary_references
|
47
|
+
data = Psych.load <<-eoyml
|
48
|
+
---
|
49
|
+
- &name !binary |-
|
50
|
+
aGVsbG8gd29ybGQh
|
51
|
+
- *name
|
52
|
+
eoyml
|
53
|
+
assert_equal data.first, data.last
|
54
|
+
assert_equal data.first.object_id, data.last.object_id
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_regexp_references
|
58
|
+
data = Psych.load <<-eoyml
|
59
|
+
---\s
|
60
|
+
- &name !ruby/regexp /pattern/i
|
61
|
+
- *name
|
62
|
+
eoyml
|
63
|
+
assert_equal data.first, data.last
|
64
|
+
assert_equal data.first.object_id, data.last.object_id
|
65
|
+
end
|
66
|
+
end
|
67
|
+
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
|