psych 2.1.0-java → 2.1.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +14 -0
  3. data/Gemfile +3 -0
  4. data/Mavenfile +7 -0
  5. data/bin/console +7 -0
  6. data/bin/setup +6 -0
  7. data/ext/java/PsychEmitter.java +345 -0
  8. data/ext/java/PsychLibrary.java +93 -0
  9. data/ext/java/PsychParser.java +399 -0
  10. data/ext/java/PsychToRuby.java +79 -0
  11. data/ext/java/PsychYamlTree.java +55 -0
  12. data/ext/psych/.gitignore +11 -0
  13. data/lib/psych.rb +2 -2
  14. data/lib/psych/visitors/to_ruby.rb +2 -2
  15. data/psych.gemspec +39 -0
  16. metadata +19 -53
  17. data/test/psych/handlers/test_recorder.rb +0 -26
  18. data/test/psych/helper.rb +0 -122
  19. data/test/psych/json/test_stream.rb +0 -110
  20. data/test/psych/nodes/test_enumerable.rb +0 -44
  21. data/test/psych/test_alias_and_anchor.rb +0 -97
  22. data/test/psych/test_array.rb +0 -58
  23. data/test/psych/test_boolean.rb +0 -37
  24. data/test/psych/test_class.rb +0 -37
  25. data/test/psych/test_coder.rb +0 -207
  26. data/test/psych/test_date_time.rb +0 -39
  27. data/test/psych/test_deprecated.rb +0 -215
  28. data/test/psych/test_document.rb +0 -47
  29. data/test/psych/test_emitter.rb +0 -112
  30. data/test/psych/test_encoding.rb +0 -269
  31. data/test/psych/test_exception.rb +0 -158
  32. data/test/psych/test_hash.rb +0 -95
  33. data/test/psych/test_json_tree.rb +0 -66
  34. data/test/psych/test_merge_keys.rb +0 -181
  35. data/test/psych/test_nil.rb +0 -19
  36. data/test/psych/test_null.rb +0 -20
  37. data/test/psych/test_numeric.rb +0 -46
  38. data/test/psych/test_object.rb +0 -45
  39. data/test/psych/test_object_references.rb +0 -72
  40. data/test/psych/test_omap.rb +0 -76
  41. data/test/psych/test_parser.rb +0 -340
  42. data/test/psych/test_psych.rb +0 -184
  43. data/test/psych/test_safe_load.rb +0 -98
  44. data/test/psych/test_scalar.rb +0 -12
  45. data/test/psych/test_scalar_scanner.rb +0 -111
  46. data/test/psych/test_serialize_subclasses.rb +0 -39
  47. data/test/psych/test_set.rb +0 -50
  48. data/test/psych/test_stream.rb +0 -94
  49. data/test/psych/test_string.rb +0 -231
  50. data/test/psych/test_struct.rb +0 -50
  51. data/test/psych/test_symbol.rb +0 -26
  52. data/test/psych/test_tainted.rb +0 -131
  53. data/test/psych/test_to_yaml_properties.rb +0 -64
  54. data/test/psych/test_tree_builder.rb +0 -80
  55. data/test/psych/test_yaml.rb +0 -1293
  56. data/test/psych/test_yamldbm.rb +0 -193
  57. data/test/psych/test_yamlstore.rb +0 -86
  58. data/test/psych/visitors/test_depth_first.rb +0 -50
  59. data/test/psych/visitors/test_emitter.rb +0 -145
  60. data/test/psych/visitors/test_to_ruby.rb +0 -332
  61. data/test/psych/visitors/test_yaml_tree.rb +0 -180
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: false
2
- require 'psych/helper'
3
-
4
- module Psych
5
- module Nodes
6
- class TestEnumerable < TestCase
7
- def test_includes_enumerable
8
- yaml = '--- hello'
9
- assert_equal 3, Psych.parse_stream(yaml).to_a.length
10
- end
11
-
12
- def test_returns_enumerator
13
- yaml = '--- hello'
14
- assert_equal 3, Psych.parse_stream(yaml).each.map { |x| x }.length
15
- end
16
-
17
- def test_scalar
18
- assert_equal 3, calls('--- hello').length
19
- end
20
-
21
- def test_sequence
22
- assert_equal 4, calls("---\n- hello").length
23
- end
24
-
25
- def test_mapping
26
- assert_equal 5, calls("---\nhello: world").length
27
- end
28
-
29
- def test_alias
30
- assert_equal 5, calls("--- &yay\n- foo\n- *yay\n").length
31
- end
32
-
33
- private
34
-
35
- def calls yaml
36
- calls = []
37
- Psych.parse_stream(yaml).each do |node|
38
- calls << node
39
- end
40
- calls
41
- end
42
- end
43
- end
44
- end
@@ -1,97 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- class ObjectWithInstanceVariables
5
- attr_accessor :var1, :var2
6
- end
7
-
8
- class SubStringWithInstanceVariables < String
9
- attr_accessor :var1
10
- end
11
-
12
- module Psych
13
- class TestAliasAndAnchor < TestCase
14
- def test_mri_compatibility
15
- yaml = <<EOYAML
16
- ---
17
- - &id001 !ruby/object {}
18
-
19
- - *id001
20
- - *id001
21
- EOYAML
22
- result = Psych.load yaml
23
- result.each {|el| assert_same(result[0], el) }
24
- end
25
-
26
- def test_mri_compatibility_object_with_ivars
27
- yaml = <<EOYAML
28
- ---
29
- - &id001 !ruby/object:ObjectWithInstanceVariables
30
- var1: test1
31
- var2: test2
32
- - *id001
33
- - *id001
34
- EOYAML
35
-
36
- result = Psych.load yaml
37
- result.each do |el|
38
- assert_same(result[0], el)
39
- assert_equal('test1', el.var1)
40
- assert_equal('test2', el.var2)
41
- end
42
- end
43
-
44
- def test_mri_compatibility_substring_with_ivars
45
- yaml = <<EOYAML
46
- ---
47
- - &id001 !str:SubStringWithInstanceVariables
48
- str: test
49
- "@var1": test
50
- - *id001
51
- - *id001
52
- EOYAML
53
- result = Psych.load yaml
54
- result.each do |el|
55
- assert_same(result[0], el)
56
- assert_equal('test', el.var1)
57
- end
58
- end
59
-
60
- def test_anchor_alias_round_trip
61
- o = Object.new
62
- original = [o,o,o]
63
-
64
- yaml = Psych.dump original
65
- result = Psych.load yaml
66
- result.each {|el| assert_same(result[0], el) }
67
- end
68
-
69
- def test_anchor_alias_round_trip_object_with_ivars
70
- o = ObjectWithInstanceVariables.new
71
- o.var1 = 'test1'
72
- o.var2 = 'test2'
73
- original = [o,o,o]
74
-
75
- yaml = Psych.dump original
76
- result = Psych.load yaml
77
- result.each do |el|
78
- assert_same(result[0], el)
79
- assert_equal('test1', el.var1)
80
- assert_equal('test2', el.var2)
81
- end
82
- end
83
-
84
- def test_anchor_alias_round_trip_substring_with_ivars
85
- o = SubStringWithInstanceVariables.new
86
- o.var1 = 'test'
87
- original = [o,o,o]
88
-
89
- yaml = Psych.dump original
90
- result = Psych.load yaml
91
- result.each do |el|
92
- assert_same(result[0], el)
93
- assert_equal('test', el.var1)
94
- end
95
- end
96
- end
97
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestArray < TestCase
6
- class X < Array
7
- end
8
-
9
- class Y < Array
10
- attr_accessor :val
11
- end
12
-
13
- def setup
14
- super
15
- @list = [{ :a => 'b' }, 'foo']
16
- end
17
-
18
- def test_another_subclass_with_attributes
19
- y = Y.new.tap {|y| y.val = 1}
20
- y << "foo" << "bar"
21
- y = Psych.load Psych.dump y
22
-
23
- assert_equal %w{foo bar}, y
24
- assert_equal Y, y.class
25
- assert_equal 1, y.val
26
- end
27
-
28
- def test_subclass
29
- yaml = Psych.dump X.new
30
- assert_match X.name, yaml
31
-
32
- list = X.new
33
- list << 1
34
- assert_equal X, list.class
35
- assert_equal 1, list.first
36
- end
37
-
38
- def test_subclass_with_attributes
39
- y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
40
- assert_equal Y, y.class
41
- assert_equal 1, y.val
42
- end
43
-
44
- def test_backwards_with_syck
45
- x = Psych.load "--- !seq:#{X.name} []\n\n"
46
- assert_equal X, x.class
47
- end
48
-
49
- def test_self_referential
50
- @list << @list
51
- assert_cycle(@list)
52
- end
53
-
54
- def test_cycle
55
- assert_cycle(@list)
56
- end
57
- end
58
- end
@@ -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