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.
Files changed (115) hide show
  1. checksums.yaml +5 -5
  2. data/CONTRIBUTING.md +24 -0
  3. data/{ext/psych/yaml/LICENSE → LICENSE} +9 -7
  4. data/README.md +80 -0
  5. data/ext/psych/depend +14 -0
  6. data/ext/psych/extconf.rb +43 -28
  7. data/ext/psych/psych.c +6 -4
  8. data/ext/psych/psych.h +0 -3
  9. data/ext/psych/psych_emitter.c +165 -132
  10. data/ext/psych/psych_parser.c +298 -331
  11. data/ext/psych/psych_to_ruby.c +0 -5
  12. data/ext/psych/psych_yaml_tree.c +0 -13
  13. data/lib/psych/class_loader.rb +11 -8
  14. data/lib/psych/coder.rb +1 -0
  15. data/lib/psych/core_ext.rb +3 -19
  16. data/lib/psych/exception.rb +17 -2
  17. data/lib/psych/handler.rb +8 -2
  18. data/lib/psych/handlers/document_stream.rb +2 -1
  19. data/lib/psych/handlers/recorder.rb +2 -1
  20. data/lib/psych/json/ruby_events.rb +1 -0
  21. data/lib/psych/json/stream.rb +3 -2
  22. data/lib/psych/json/tree_builder.rb +2 -1
  23. data/lib/psych/json/yaml_events.rb +1 -0
  24. data/lib/psych/nodes/alias.rb +3 -0
  25. data/lib/psych/nodes/document.rb +3 -0
  26. data/lib/psych/nodes/mapping.rb +3 -0
  27. data/lib/psych/nodes/node.rb +25 -5
  28. data/lib/psych/nodes/scalar.rb +4 -1
  29. data/lib/psych/nodes/sequence.rb +3 -0
  30. data/lib/psych/nodes/stream.rb +3 -0
  31. data/lib/psych/nodes.rb +8 -7
  32. data/lib/psych/omap.rb +1 -0
  33. data/lib/psych/parser.rb +14 -0
  34. data/lib/psych/scalar_scanner.rb +41 -49
  35. data/lib/psych/set.rb +1 -0
  36. data/lib/psych/stream.rb +1 -0
  37. data/lib/psych/streaming.rb +1 -0
  38. data/lib/psych/syntax_error.rb +2 -1
  39. data/lib/psych/tree_builder.rb +48 -7
  40. data/lib/psych/versions.rb +10 -0
  41. data/lib/psych/visitors/depth_first.rb +1 -0
  42. data/lib/psych/visitors/emitter.rb +1 -0
  43. data/lib/psych/visitors/json_tree.rb +2 -1
  44. data/lib/psych/visitors/to_ruby.rb +64 -33
  45. data/lib/psych/visitors/visitor.rb +18 -3
  46. data/lib/psych/visitors/yaml_tree.rb +128 -149
  47. data/lib/psych/visitors.rb +7 -6
  48. data/lib/psych/y.rb +1 -0
  49. data/lib/psych.rb +360 -95
  50. metadata +36 -169
  51. data/.autotest +0 -18
  52. data/.gemtest +0 -0
  53. data/.travis.yml +0 -11
  54. data/CHANGELOG.rdoc +0 -562
  55. data/Manifest.txt +0 -112
  56. data/README.rdoc +0 -71
  57. data/Rakefile +0 -74
  58. data/ext/psych/yaml/api.c +0 -1415
  59. data/ext/psych/yaml/config.h +0 -10
  60. data/ext/psych/yaml/dumper.c +0 -394
  61. data/ext/psych/yaml/emitter.c +0 -2329
  62. data/ext/psych/yaml/loader.c +0 -459
  63. data/ext/psych/yaml/parser.c +0 -1370
  64. data/ext/psych/yaml/reader.c +0 -469
  65. data/ext/psych/yaml/scanner.c +0 -3583
  66. data/ext/psych/yaml/writer.c +0 -141
  67. data/ext/psych/yaml/yaml.h +0 -1971
  68. data/ext/psych/yaml/yaml_private.h +0 -664
  69. data/lib/psych/deprecated.rb +0 -85
  70. data/test/psych/handlers/test_recorder.rb +0 -25
  71. data/test/psych/helper.rb +0 -114
  72. data/test/psych/json/test_stream.rb +0 -109
  73. data/test/psych/nodes/test_enumerable.rb +0 -43
  74. data/test/psych/test_alias_and_anchor.rb +0 -96
  75. data/test/psych/test_array.rb +0 -57
  76. data/test/psych/test_boolean.rb +0 -36
  77. data/test/psych/test_class.rb +0 -36
  78. data/test/psych/test_coder.rb +0 -184
  79. data/test/psych/test_date_time.rb +0 -38
  80. data/test/psych/test_deprecated.rb +0 -214
  81. data/test/psych/test_document.rb +0 -46
  82. data/test/psych/test_emitter.rb +0 -93
  83. data/test/psych/test_encoding.rb +0 -259
  84. data/test/psych/test_exception.rb +0 -157
  85. data/test/psych/test_hash.rb +0 -94
  86. data/test/psych/test_json_tree.rb +0 -65
  87. data/test/psych/test_marshalable.rb +0 -54
  88. data/test/psych/test_merge_keys.rb +0 -180
  89. data/test/psych/test_nil.rb +0 -18
  90. data/test/psych/test_null.rb +0 -19
  91. data/test/psych/test_numeric.rb +0 -45
  92. data/test/psych/test_object.rb +0 -44
  93. data/test/psych/test_object_references.rb +0 -71
  94. data/test/psych/test_omap.rb +0 -75
  95. data/test/psych/test_parser.rb +0 -339
  96. data/test/psych/test_psych.rb +0 -168
  97. data/test/psych/test_safe_load.rb +0 -97
  98. data/test/psych/test_scalar.rb +0 -11
  99. data/test/psych/test_scalar_scanner.rb +0 -106
  100. data/test/psych/test_serialize_subclasses.rb +0 -38
  101. data/test/psych/test_set.rb +0 -49
  102. data/test/psych/test_stream.rb +0 -93
  103. data/test/psych/test_string.rb +0 -226
  104. data/test/psych/test_struct.rb +0 -49
  105. data/test/psych/test_symbol.rb +0 -25
  106. data/test/psych/test_tainted.rb +0 -130
  107. data/test/psych/test_to_yaml_properties.rb +0 -63
  108. data/test/psych/test_tree_builder.rb +0 -79
  109. data/test/psych/test_yaml.rb +0 -1288
  110. data/test/psych/test_yamldbm.rb +0 -193
  111. data/test/psych/test_yamlstore.rb +0 -85
  112. data/test/psych/visitors/test_depth_first.rb +0 -49
  113. data/test/psych/visitors/test_emitter.rb +0 -144
  114. data/test/psych/visitors/test_to_ruby.rb +0 -326
  115. data/test/psych/visitors/test_yaml_tree.rb +0 -173
@@ -1,180 +0,0 @@
1
- require_relative 'helper'
2
-
3
- module Psych
4
- class TestMergeKeys < TestCase
5
- class Product
6
- attr_reader :bar
7
- end
8
-
9
- def test_merge_key_with_bare_hash
10
- doc = Psych.load <<-eodoc
11
- map:
12
- <<:
13
- hello: world
14
- eodoc
15
- hash = { "map" => { "hello" => "world" } }
16
- assert_equal hash, doc
17
- end
18
-
19
- def test_roundtrip_with_chevron_key
20
- h = {}
21
- v = { 'a' => h, '<<' => h }
22
- assert_cycle v
23
- end
24
-
25
- def test_explicit_string
26
- doc = Psych.load <<-eoyml
27
- a: &me { hello: world }
28
- b: { !!str '<<': *me }
29
- eoyml
30
- expected = {
31
- "a" => { "hello" => "world" },
32
- "b" => {
33
- "<<" => { "hello" => "world" }
34
- }
35
- }
36
- assert_equal expected, doc
37
- end
38
-
39
- def test_mergekey_with_object
40
- s = <<-eoyml
41
- foo: &foo
42
- bar: 10
43
- product:
44
- !ruby/object:#{Product.name}
45
- <<: *foo
46
- eoyml
47
- hash = Psych.load s
48
- assert_equal({"bar" => 10}, hash["foo"])
49
- product = hash["product"]
50
- assert_equal 10, product.bar
51
- end
52
-
53
- def test_merge_nil
54
- yaml = <<-eoyml
55
- defaults: &defaults
56
- development:
57
- <<: *defaults
58
- eoyml
59
- assert_equal({'<<' => nil }, Psych.load(yaml)['development'])
60
- end
61
-
62
- def test_merge_array
63
- yaml = <<-eoyml
64
- foo: &hello
65
- - 1
66
- baz:
67
- <<: *hello
68
- eoyml
69
- assert_equal({'<<' => [1]}, Psych.load(yaml)['baz'])
70
- end
71
-
72
- def test_merge_is_not_partial
73
- yaml = <<-eoyml
74
- default: &default
75
- hello: world
76
- foo: &hello
77
- - 1
78
- baz:
79
- <<: [*hello, *default]
80
- eoyml
81
- doc = Psych.load yaml
82
- refute doc['baz'].key? 'hello'
83
- assert_equal({'<<' => [[1], {"hello"=>"world"}]}, Psych.load(yaml)['baz'])
84
- end
85
-
86
- def test_merge_seq_nil
87
- yaml = <<-eoyml
88
- foo: &hello
89
- baz:
90
- <<: [*hello]
91
- eoyml
92
- assert_equal({'<<' => [nil]}, Psych.load(yaml)['baz'])
93
- end
94
-
95
- def test_bad_seq_merge
96
- yaml = <<-eoyml
97
- defaults: &defaults [1, 2, 3]
98
- development:
99
- <<: *defaults
100
- eoyml
101
- assert_equal({'<<' => [1,2,3]}, Psych.load(yaml)['development'])
102
- end
103
-
104
- def test_missing_merge_key
105
- yaml = <<-eoyml
106
- bar:
107
- << : *foo
108
- eoyml
109
- exp = assert_raises(Psych::BadAlias) { Psych.load yaml }
110
- assert_match 'foo', exp.message
111
- end
112
-
113
- # [ruby-core:34679]
114
- def test_merge_key
115
- yaml = <<-eoyml
116
- foo: &foo
117
- hello: world
118
- bar:
119
- << : *foo
120
- baz: boo
121
- eoyml
122
-
123
- hash = {
124
- "foo" => { "hello" => "world"},
125
- "bar" => { "hello" => "world", "baz" => "boo" } }
126
- assert_equal hash, Psych.load(yaml)
127
- end
128
-
129
- def test_multiple_maps
130
- yaml = <<-eoyaml
131
- ---
132
- - &CENTER { x: 1, y: 2 }
133
- - &LEFT { x: 0, y: 2 }
134
- - &BIG { r: 10 }
135
- - &SMALL { r: 1 }
136
-
137
- # All the following maps are equal:
138
-
139
- - # Merge multiple maps
140
- << : [ *CENTER, *BIG ]
141
- label: center/big
142
- eoyaml
143
-
144
- hash = {
145
- 'x' => 1,
146
- 'y' => 2,
147
- 'r' => 10,
148
- 'label' => 'center/big'
149
- }
150
-
151
- assert_equal hash, Psych.load(yaml)[4]
152
- end
153
-
154
- def test_override
155
- yaml = <<-eoyaml
156
- ---
157
- - &CENTER { x: 1, y: 2 }
158
- - &LEFT { x: 0, y: 2 }
159
- - &BIG { r: 10 }
160
- - &SMALL { r: 1 }
161
-
162
- # All the following maps are equal:
163
-
164
- - # Override
165
- << : [ *BIG, *LEFT, *SMALL ]
166
- x: 1
167
- label: center/big
168
- eoyaml
169
-
170
- hash = {
171
- 'x' => 1,
172
- 'y' => 2,
173
- 'r' => 10,
174
- 'label' => 'center/big'
175
- }
176
-
177
- assert_equal hash, Psych.load(yaml)[4]
178
- end
179
- end
180
- end
@@ -1,18 +0,0 @@
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
@@ -1,19 +0,0 @@
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
@@ -1,45 +0,0 @@
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
@@ -1,44 +0,0 @@
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
@@ -1,71 +0,0 @@
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
@@ -1,75 +0,0 @@
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