psych 2.1.0 → 2.1.1

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/.travis.yml +1 -10
  4. data/Gemfile +3 -0
  5. data/Mavenfile +7 -0
  6. data/Rakefile +27 -119
  7. data/bin/console +7 -0
  8. data/bin/setup +6 -0
  9. data/ext/java/PsychEmitter.java +345 -0
  10. data/ext/java/PsychLibrary.java +93 -0
  11. data/ext/java/PsychParser.java +399 -0
  12. data/ext/java/PsychToRuby.java +79 -0
  13. data/ext/java/PsychYamlTree.java +55 -0
  14. data/ext/psych/.gitignore +11 -0
  15. data/lib/psych.rb +2 -2
  16. data/lib/psych/scalar_scanner.rb +1 -1
  17. data/lib/psych/visitors/to_ruby.rb +2 -2
  18. data/psych.gemspec +39 -0
  19. metadata +21 -84
  20. data/.autotest +0 -18
  21. data/Manifest.txt +0 -114
  22. data/test/psych/handlers/test_recorder.rb +0 -26
  23. data/test/psych/helper.rb +0 -122
  24. data/test/psych/json/test_stream.rb +0 -110
  25. data/test/psych/nodes/test_enumerable.rb +0 -44
  26. data/test/psych/test_alias_and_anchor.rb +0 -97
  27. data/test/psych/test_array.rb +0 -58
  28. data/test/psych/test_boolean.rb +0 -37
  29. data/test/psych/test_class.rb +0 -37
  30. data/test/psych/test_coder.rb +0 -207
  31. data/test/psych/test_date_time.rb +0 -39
  32. data/test/psych/test_deprecated.rb +0 -215
  33. data/test/psych/test_document.rb +0 -47
  34. data/test/psych/test_emitter.rb +0 -111
  35. data/test/psych/test_encoding.rb +0 -269
  36. data/test/psych/test_exception.rb +0 -158
  37. data/test/psych/test_hash.rb +0 -95
  38. data/test/psych/test_json_tree.rb +0 -66
  39. data/test/psych/test_merge_keys.rb +0 -181
  40. data/test/psych/test_nil.rb +0 -19
  41. data/test/psych/test_null.rb +0 -20
  42. data/test/psych/test_numeric.rb +0 -46
  43. data/test/psych/test_object.rb +0 -45
  44. data/test/psych/test_object_references.rb +0 -72
  45. data/test/psych/test_omap.rb +0 -76
  46. data/test/psych/test_parser.rb +0 -340
  47. data/test/psych/test_psych.rb +0 -184
  48. data/test/psych/test_safe_load.rb +0 -98
  49. data/test/psych/test_scalar.rb +0 -12
  50. data/test/psych/test_scalar_scanner.rb +0 -107
  51. data/test/psych/test_serialize_subclasses.rb +0 -39
  52. data/test/psych/test_set.rb +0 -50
  53. data/test/psych/test_stream.rb +0 -94
  54. data/test/psych/test_string.rb +0 -227
  55. data/test/psych/test_struct.rb +0 -50
  56. data/test/psych/test_symbol.rb +0 -26
  57. data/test/psych/test_tainted.rb +0 -131
  58. data/test/psych/test_to_yaml_properties.rb +0 -64
  59. data/test/psych/test_tree_builder.rb +0 -80
  60. data/test/psych/test_yaml.rb +0 -1293
  61. data/test/psych/test_yamldbm.rb +0 -193
  62. data/test/psych/test_yamlstore.rb +0 -86
  63. data/test/psych/visitors/test_depth_first.rb +0 -50
  64. data/test/psych/visitors/test_emitter.rb +0 -145
  65. data/test/psych/visitors/test_to_ruby.rb +0 -332
  66. data/test/psych/visitors/test_yaml_tree.rb +0 -180
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- ###
6
- # Test booleans from YAML spec:
7
- # http://yaml.org/type/bool.html
8
- class TestBoolean < TestCase
9
- %w{ yes Yes YES true True TRUE on On ON }.each do |truth|
10
- define_method(:"test_#{truth}") do
11
- assert_equal true, Psych.load("--- #{truth}")
12
- end
13
- end
14
-
15
- %w{ no No NO false False FALSE off Off OFF }.each do |truth|
16
- define_method(:"test_#{truth}") do
17
- assert_equal false, Psych.load("--- #{truth}")
18
- end
19
- end
20
-
21
- ###
22
- # YAML spec says "y" and "Y" may be used as true, but Syck treats them
23
- # as literal strings
24
- def test_y
25
- assert_equal "y", Psych.load("--- y")
26
- assert_equal "Y", Psych.load("--- Y")
27
- end
28
-
29
- ###
30
- # YAML spec says "n" and "N" may be used as false, but Syck treats them
31
- # as literal strings
32
- def test_n
33
- assert_equal "n", Psych.load("--- n")
34
- assert_equal "N", Psych.load("--- N")
35
- end
36
- end
37
- end
@@ -1,37 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestClass < TestCase
6
- module Foo
7
- end
8
-
9
- def test_cycle_anonymous_class
10
- assert_raises(::TypeError) do
11
- assert_cycle(Class.new)
12
- end
13
- end
14
-
15
- def test_cycle_anonymous_module
16
- assert_raises(::TypeError) do
17
- assert_cycle(Module.new)
18
- end
19
- end
20
-
21
- def test_cycle
22
- assert_cycle(TestClass)
23
- end
24
-
25
- def test_dump
26
- Psych.dump TestClass
27
- end
28
-
29
- def test_cycle_module
30
- assert_cycle(Foo)
31
- end
32
-
33
- def test_dump_module
34
- Psych.dump Foo
35
- end
36
- end
37
- end
@@ -1,207 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestCoder < TestCase
6
- class InitApi
7
- attr_accessor :implicit
8
- attr_accessor :style
9
- attr_accessor :tag
10
- attr_accessor :a, :b, :c
11
-
12
- def initialize
13
- @a = 1
14
- @b = 2
15
- @c = 3
16
- end
17
-
18
- def init_with coder
19
- @a = coder['aa']
20
- @b = coder['bb']
21
- @implicit = coder.implicit
22
- @tag = coder.tag
23
- @style = coder.style
24
- end
25
-
26
- def encode_with coder
27
- coder['aa'] = @a
28
- coder['bb'] = @b
29
- end
30
- end
31
-
32
- class TaggingCoder < InitApi
33
- def encode_with coder
34
- super
35
- coder.tag = coder.tag.sub(/!/, '!hello')
36
- coder.implicit = false
37
- coder.style = Psych::Nodes::Mapping::FLOW
38
- end
39
- end
40
-
41
- class ScalarCoder
42
- def encode_with coder
43
- coder.scalar = "foo"
44
- end
45
- end
46
-
47
- class Represent
48
- yaml_tag 'foo'
49
- def encode_with coder
50
- coder.represent_scalar 'foo', 'bar'
51
- end
52
- end
53
-
54
- class RepresentWithInit
55
- yaml_tag name
56
- attr_accessor :str
57
-
58
- def init_with coder
59
- @str = coder.scalar
60
- end
61
-
62
- def encode_with coder
63
- coder.represent_scalar self.class.name, 'bar'
64
- end
65
- end
66
-
67
- class RepresentWithSeq
68
- yaml_tag name
69
- attr_accessor :seq
70
-
71
- def init_with coder
72
- @seq = coder.seq
73
- end
74
-
75
- def encode_with coder
76
- coder.represent_seq self.class.name, %w{ foo bar }
77
- end
78
- end
79
-
80
- class RepresentWithMap
81
- yaml_tag name
82
- attr_accessor :map
83
-
84
- def init_with coder
85
- @map = coder.map
86
- end
87
-
88
- def encode_with coder
89
- coder.represent_map self.class.name, { "string" => 'a', :symbol => 'b' }
90
- end
91
- end
92
-
93
- class RepresentWithObject
94
- def encode_with coder
95
- coder.represent_object self.class.name, 20
96
- end
97
- end
98
-
99
- class Referential
100
- attr_reader :a
101
-
102
- def initialize
103
- @a = self
104
- end
105
-
106
- def encode_with(c)
107
- c['a'] = @a
108
- end
109
-
110
- def init_with(c)
111
- @a = c['a']
112
- end
113
- end
114
-
115
- def test_self_referential
116
- x = Referential.new
117
- copy = Psych.load Psych.dump x
118
- assert_equal copy, copy.a
119
- end
120
-
121
- def test_represent_with_object
122
- thing = Psych.load(Psych.dump(RepresentWithObject.new))
123
- assert_equal 20, thing
124
- end
125
-
126
- def test_json_dump_exclude_tag
127
- refute_match('TestCoder::InitApi', Psych.to_json(InitApi.new))
128
- end
129
-
130
- def test_map_takes_block
131
- coder = Psych::Coder.new 'foo'
132
- tag = coder.tag
133
- style = coder.style
134
- coder.map { |map| map.add 'foo', 'bar' }
135
- assert_equal 'bar', coder['foo']
136
- assert_equal tag, coder.tag
137
- assert_equal style, coder.style
138
- end
139
-
140
- def test_map_with_tag
141
- coder = Psych::Coder.new 'foo'
142
- coder.map('hello') { |map| map.add 'foo', 'bar' }
143
- assert_equal 'bar', coder['foo']
144
- assert_equal 'hello', coder.tag
145
- end
146
-
147
- def test_map_with_tag_and_style
148
- coder = Psych::Coder.new 'foo'
149
- coder.map('hello', 'world') { |map| map.add 'foo', 'bar' }
150
- assert_equal 'bar', coder['foo']
151
- assert_equal 'hello', coder.tag
152
- assert_equal 'world', coder.style
153
- end
154
-
155
- def test_represent_map
156
- thing = Psych.load(Psych.dump(RepresentWithMap.new))
157
- assert_equal({ "string" => 'a', :symbol => 'b' }, thing.map)
158
- end
159
-
160
- def test_represent_sequence
161
- thing = Psych.load(Psych.dump(RepresentWithSeq.new))
162
- assert_equal %w{ foo bar }, thing.seq
163
- end
164
-
165
- def test_represent_with_init
166
- thing = Psych.load(Psych.dump(RepresentWithInit.new))
167
- assert_equal 'bar', thing.str
168
- end
169
-
170
- def test_represent!
171
- assert_match(/foo/, Psych.dump(Represent.new))
172
- assert_instance_of(Represent, Psych.load(Psych.dump(Represent.new)))
173
- end
174
-
175
- def test_scalar_coder
176
- foo = Psych.load(Psych.dump(ScalarCoder.new))
177
- assert_equal 'foo', foo
178
- end
179
-
180
- def test_load_dumped_tagging
181
- foo = InitApi.new
182
- bar = Psych.load(Psych.dump(foo))
183
- assert_equal false, bar.implicit
184
- assert_equal "!ruby/object:Psych::TestCoder::InitApi", bar.tag
185
- assert_equal Psych::Nodes::Mapping::BLOCK, bar.style
186
- end
187
-
188
- def test_dump_with_tag
189
- foo = TaggingCoder.new
190
- assert_match(/hello/, Psych.dump(foo))
191
- assert_match(/\{aa/, Psych.dump(foo))
192
- end
193
-
194
- def test_dump_encode_with
195
- foo = InitApi.new
196
- assert_match(/aa/, Psych.dump(foo))
197
- end
198
-
199
- def test_dump_init_with
200
- foo = InitApi.new
201
- bar = Psych.load(Psych.dump(foo))
202
- assert_equal foo.a, bar.a
203
- assert_equal foo.b, bar.b
204
- assert_nil bar.c
205
- end
206
- end
207
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
- require 'date'
4
-
5
- module Psych
6
- class TestDateTime < TestCase
7
- def test_negative_year
8
- time = Time.utc -1, 12, 16
9
- assert_cycle time
10
- end
11
-
12
- def test_new_datetime
13
- assert_cycle DateTime.new
14
- end
15
-
16
- def test_invalid_date
17
- assert_cycle "2013-10-31T10:40:07-000000000000033"
18
- end
19
-
20
- def test_string_tag
21
- dt = DateTime.now
22
- yaml = Psych.dump dt
23
- assert_match(/DateTime/, yaml)
24
- end
25
-
26
- def test_round_trip
27
- dt = DateTime.now
28
- assert_cycle dt
29
- end
30
-
31
- def test_alias_with_time
32
- t = Time.now
33
- h = {:a => t, :b => t}
34
- yaml = Psych.dump h
35
- assert_match('&', yaml)
36
- assert_match('*', yaml)
37
- end
38
- end
39
- end
@@ -1,215 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestDeprecated < TestCase
6
- def teardown
7
- $VERBOSE = @orig_verbose
8
- Psych.domain_types.clear
9
- end
10
-
11
- class QuickEmitter
12
- attr_reader :name
13
- attr_reader :value
14
-
15
- def initialize
16
- @name = 'hello!!'
17
- @value = 'Friday!'
18
- end
19
-
20
- def to_yaml opts = {}
21
- Psych.quick_emit object_id, opts do |out|
22
- out.map taguri, to_yaml_style do |map|
23
- map.add 'name', @name
24
- map.add 'value', nil
25
- end
26
- end
27
- end
28
- end
29
-
30
- def setup
31
- @qe = QuickEmitter.new
32
- @orig_verbose, $VERBOSE = $VERBOSE, false
33
- end
34
-
35
- def test_quick_emit
36
- qe2 = Psych.load @qe.to_yaml
37
- assert_equal @qe.name, qe2.name
38
- assert_instance_of QuickEmitter, qe2
39
- assert_nil qe2.value
40
- end
41
-
42
- def test_recursive_quick_emit
43
- hash = { :qe => @qe }
44
- hash2 = Psych.load Psych.dump hash
45
- qe = hash2[:qe]
46
-
47
- assert_equal @qe.name, qe.name
48
- assert_instance_of QuickEmitter, qe
49
- assert_nil qe.value
50
- end
51
-
52
- class QuickEmitterEncodeWith
53
- attr_reader :name
54
- attr_reader :value
55
-
56
- def initialize
57
- @name = 'hello!!'
58
- @value = 'Friday!'
59
- end
60
-
61
- def encode_with coder
62
- coder.map do |map|
63
- map.add 'name', @name
64
- map.add 'value', nil
65
- end
66
- end
67
-
68
- def to_yaml opts = {}
69
- raise
70
- end
71
- end
72
-
73
- ###
74
- # An object that defines both to_yaml and encode_with should only call
75
- # encode_with.
76
- def test_recursive_quick_emit_encode_with
77
- qeew = QuickEmitterEncodeWith.new
78
- hash = { :qe => qeew }
79
- hash2 = Psych.load Psych.dump hash
80
- qe = hash2[:qe]
81
-
82
- assert_equal qeew.name, qe.name
83
- assert_instance_of QuickEmitterEncodeWith, qe
84
- assert_nil qe.value
85
- end
86
-
87
- class YamlInit
88
- attr_reader :name
89
- attr_reader :value
90
-
91
- def initialize
92
- @name = 'hello!!'
93
- @value = 'Friday!'
94
- end
95
-
96
- def yaml_initialize tag, vals
97
- vals.each { |ivar, val| instance_variable_set "@#{ivar}", 'TGIF!' }
98
- end
99
- end
100
-
101
- def test_yaml_initialize
102
- hash = { :yi => YamlInit.new }
103
- hash2 = Psych.load Psych.dump hash
104
- yi = hash2[:yi]
105
-
106
- assert_equal 'TGIF!', yi.name
107
- assert_equal 'TGIF!', yi.value
108
- assert_instance_of YamlInit, yi
109
- end
110
-
111
- class YamlInitAndInitWith
112
- attr_reader :name
113
- attr_reader :value
114
-
115
- def initialize
116
- @name = 'shaners'
117
- @value = 'Friday!'
118
- end
119
-
120
- def init_with coder
121
- coder.map.each { |ivar, val| instance_variable_set "@#{ivar}", 'TGIF!' }
122
- end
123
-
124
- def yaml_initialize tag, vals
125
- raise
126
- end
127
- end
128
-
129
- ###
130
- # An object that implements both yaml_initialize and init_with should not
131
- # receive the yaml_initialize call.
132
- def test_yaml_initialize_and_init_with
133
- hash = { :yi => YamlInitAndInitWith.new }
134
- hash2 = Psych.load Psych.dump hash
135
- yi = hash2[:yi]
136
-
137
- assert_equal 'TGIF!', yi.name
138
- assert_equal 'TGIF!', yi.value
139
- assert_instance_of YamlInitAndInitWith, yi
140
- end
141
-
142
- def test_coder_scalar
143
- coder = Psych::Coder.new 'foo'
144
- coder.scalar('tag', 'some string', :plain)
145
- assert_equal 'tag', coder.tag
146
- assert_equal 'some string', coder.scalar
147
- assert_equal :scalar, coder.type
148
- end
149
-
150
- class YamlAs
151
- TestCase.suppress_warning do
152
- psych_yaml_as 'helloworld' # this should be yaml_as but to avoid syck
153
- end
154
- end
155
-
156
- def test_yaml_as
157
- assert_match(/helloworld/, Psych.dump(YamlAs.new))
158
- end
159
-
160
- def test_ruby_type
161
- types = []
162
- appender = lambda { |*args| types << args }
163
-
164
- Psych.add_ruby_type('foo', &appender)
165
- Psych.load <<-eoyml
166
- - !ruby.yaml.org,2002/foo bar
167
- eoyml
168
-
169
- assert_equal [["tag:ruby.yaml.org,2002:foo", "bar"]], types
170
- end
171
-
172
- def test_detect_implicit
173
- assert_equal '', Psych.detect_implicit(nil)
174
- assert_equal '', Psych.detect_implicit(Object.new)
175
- assert_equal '', Psych.detect_implicit(1.2)
176
- assert_equal 'null', Psych.detect_implicit('')
177
- assert_equal 'string', Psych.detect_implicit('foo')
178
- end
179
-
180
- def test_private_type
181
- types = []
182
- Psych.add_private_type('foo') { |*args| types << args }
183
- Psych.load <<-eoyml
184
- - !x-private:foo bar
185
- eoyml
186
-
187
- assert_equal [["x-private:foo", "bar"]], types
188
- end
189
-
190
- def test_tagurize
191
- assert_nil Psych.tagurize nil
192
- assert_equal Psych, Psych.tagurize(Psych)
193
- assert_equal 'tag:yaml.org,2002:foo', Psych.tagurize('foo')
194
- end
195
-
196
- def test_read_type_class
197
- things = Psych.read_type_class 'tag:yaml.org,2002:int:Psych::TestDeprecated::QuickEmitter', Object
198
- assert_equal 'int', things.first
199
- assert_equal Psych::TestDeprecated::QuickEmitter, things.last
200
- end
201
-
202
- def test_read_type_class_no_class
203
- things = Psych.read_type_class 'tag:yaml.org,2002:int', Object
204
- assert_equal 'int', things.first
205
- assert_equal Object, things.last
206
- end
207
-
208
- def test_object_maker
209
- thing = Psych.object_maker(Object, { 'a' => 'b', 'c' => 'd' })
210
- assert_instance_of(Object, thing)
211
- assert_equal 'b', thing.instance_variable_get(:@a)
212
- assert_equal 'd', thing.instance_variable_get(:@c)
213
- end
214
- end
215
- end