psych 2.1.0-java → 2.1.1-java

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 (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,94 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestStream < TestCase
6
- def test_parse_partial
7
- rb = Psych.parse("--- foo\n...\n--- `").to_ruby
8
- assert_equal 'foo', rb
9
- end
10
-
11
- def test_load_partial
12
- rb = Psych.load("--- foo\n...\n--- `")
13
- assert_equal 'foo', rb
14
- end
15
-
16
- def test_parse_stream_yields_documents
17
- list = []
18
- Psych.parse_stream("--- foo\n...\n--- bar") do |doc|
19
- list << doc.to_ruby
20
- end
21
- assert_equal %w{ foo bar }, list
22
- end
23
-
24
- def test_parse_stream_break
25
- list = []
26
- Psych.parse_stream("--- foo\n...\n--- `") do |doc|
27
- list << doc.to_ruby
28
- break
29
- end
30
- assert_equal %w{ foo }, list
31
- end
32
-
33
- def test_load_stream_yields_documents
34
- list = []
35
- Psych.load_stream("--- foo\n...\n--- bar") do |ruby|
36
- list << ruby
37
- end
38
- assert_equal %w{ foo bar }, list
39
- end
40
-
41
- def test_load_stream_break
42
- list = []
43
- Psych.load_stream("--- foo\n...\n--- `") do |ruby|
44
- list << ruby
45
- break
46
- end
47
- assert_equal %w{ foo }, list
48
- end
49
-
50
- def test_explicit_documents
51
- io = StringIO.new
52
- stream = Psych::Stream.new(io)
53
- stream.start
54
- stream.push({ 'foo' => 'bar' })
55
-
56
- assert !stream.finished?, 'stream not finished'
57
- stream.finish
58
- assert stream.finished?, 'stream finished'
59
-
60
- assert_match(/^---/, io.string)
61
- assert_match(/\.\.\.$/, io.string)
62
- end
63
-
64
- def test_start_takes_block
65
- io = StringIO.new
66
- stream = Psych::Stream.new(io)
67
- stream.start do |emitter|
68
- emitter.push({ 'foo' => 'bar' })
69
- end
70
-
71
- assert stream.finished?, 'stream finished'
72
- assert_match(/^---/, io.string)
73
- assert_match(/\.\.\.$/, io.string)
74
- end
75
-
76
- def test_no_backreferences
77
- io = StringIO.new
78
- stream = Psych::Stream.new(io)
79
- stream.start do |emitter|
80
- x = { 'foo' => 'bar' }
81
- emitter.push x
82
- emitter.push x
83
- end
84
-
85
- assert stream.finished?, 'stream finished'
86
- assert_match(/^---/, io.string)
87
- assert_match(/\.\.\.$/, io.string)
88
- assert_equal 2, io.string.scan('---').length
89
- assert_equal 2, io.string.scan('...').length
90
- assert_equal 2, io.string.scan('foo').length
91
- assert_equal 2, io.string.scan('bar').length
92
- end
93
- end
94
- end
@@ -1,231 +0,0 @@
1
- # encoding: UTF-8
2
- # frozen_string_literal: false
3
- require_relative 'helper'
4
-
5
- module Psych
6
- class TestString < TestCase
7
- class X < String
8
- end
9
-
10
- class Y < String
11
- attr_accessor :val
12
- end
13
-
14
- class Z < String
15
- def initialize
16
- force_encoding Encoding::US_ASCII
17
- end
18
- end
19
-
20
- def test_string_with_newline
21
- assert_equal "1\n2", Psych.load("--- ! '1\n\n 2'\n")
22
- end
23
-
24
- def test_no_doublequotes_with_special_characters
25
- assert_equal 2, Psych.dump(%Q{<%= ENV["PATH"] %>}).count('"')
26
- end
27
-
28
- def test_no_quotes_when_start_with_non_ascii_character
29
- yaml = Psych.dump 'Český non-ASCII'.encode(Encoding::UTF_8)
30
- assert_match(/---\s*[^"'!]+$/, yaml)
31
- end
32
-
33
- def test_doublequotes_when_there_is_a_single
34
- str = "@123'abc"
35
- yaml = Psych.dump str
36
- assert_match /---\s*"/, yaml
37
- assert_equal str, Psych.load(yaml)
38
- end
39
-
40
- def test_plain_when_shorten_than_line_width_and_no_final_line_break
41
- str = "Lorem ipsum"
42
- yaml = Psych.dump str, line_width: 12
43
- assert_match /---\s*[^>|]+\n/, yaml
44
- assert_equal str, Psych.load(yaml)
45
- end
46
-
47
- def test_plain_when_shorten_than_line_width_and_with_final_line_break
48
- str = "Lorem ipsum\n"
49
- yaml = Psych.dump str, line_width: 12
50
- assert_match /---\s*[^>|]+\n/, yaml
51
- assert_equal str, Psych.load(yaml)
52
- end
53
-
54
- def test_folded_when_longer_than_line_width_and_with_final_line_break
55
- str = "Lorem ipsum dolor sit\n"
56
- yaml = Psych.dump str, line_width: 12
57
- assert_match /---\s*>\n(.*\n){2}\Z/, yaml
58
- assert_equal str, Psych.load(yaml)
59
- end
60
-
61
- # http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651
62
- def test_folded_strip_when_longer_than_line_width_and_no_newlines
63
- str = "Lorem ipsum dolor sit amet, consectetur"
64
- yaml = Psych.dump str, line_width: 12
65
- assert_match /---\s*>-\n(.*\n){3}\Z/, yaml
66
- assert_equal str, Psych.load(yaml)
67
- end
68
-
69
- def test_literal_when_inner_and_final_line_break
70
- [
71
- "Lorem ipsum\ndolor\n",
72
- "Lorem ipsum\nZolor\n",
73
- ].each do |str|
74
- yaml = Psych.dump str, line_width: 12
75
- assert_match /---\s*\|\n(.*\n){2}\Z/, yaml
76
- assert_equal str, Psych.load(yaml)
77
- end
78
- end
79
-
80
- # http://yaml.org/spec/1.2/2009-07-21/spec.html#id2593651
81
- def test_literal_strip_when_inner_line_break_and_no_final_line_break
82
- [
83
- "Lorem ipsum\ndolor",
84
- "Lorem ipsum\nZolor",
85
- ].each do |str|
86
- yaml = Psych.dump str, line_width: 12
87
- assert_match /---\s*\|-\n(.*\n){2}\Z/, yaml
88
- assert_equal str, Psych.load(yaml)
89
- end
90
- end
91
-
92
- def test_cycle_x
93
- str = X.new 'abc'
94
- assert_cycle str
95
- end
96
-
97
- def test_dash_dot
98
- assert_cycle '-.'
99
- assert_cycle '+.'
100
- end
101
-
102
- def test_float_with_no_fractional_before_exponent
103
- assert_cycle '0.E+0'
104
- end
105
-
106
- def test_string_subclass_with_anchor
107
- y = Psych.load <<-eoyml
108
- ---
109
- body:
110
- string: &70121654388580 !ruby/string
111
- str: ! 'foo'
112
- x:
113
- body: *70121654388580
114
- eoyml
115
- assert_equal({"body"=>{"string"=>"foo", "x"=>{"body"=>"foo"}}}, y)
116
- end
117
-
118
- def test_self_referential_string
119
- y = Psych.load <<-eoyml
120
- ---
121
- string: &70121654388580 !ruby/string
122
- str: ! 'foo'
123
- body: *70121654388580
124
- eoyml
125
-
126
- assert_equal({"string"=>"foo"}, y)
127
- value = y['string']
128
- assert_equal value, value.instance_variable_get(:@body)
129
- end
130
-
131
- def test_another_subclass_with_attributes
132
- y = Psych.load Psych.dump Y.new("foo").tap {|y| y.val = 1}
133
- assert_equal "foo", y
134
- assert_equal Y, y.class
135
- assert_equal 1, y.val
136
- end
137
-
138
- def test_backwards_with_syck
139
- x = Psych.load "--- !str:#{X.name} foo\n\n"
140
- assert_equal X, x.class
141
- assert_equal 'foo', x
142
- end
143
-
144
- def test_empty_subclass
145
- assert_match "!ruby/string:#{X}", Psych.dump(X.new)
146
- x = Psych.load Psych.dump X.new
147
- assert_equal X, x.class
148
- end
149
-
150
- def test_empty_character_subclass
151
- assert_match "!ruby/string:#{Z}", Psych.dump(Z.new)
152
- x = Psych.load Psych.dump Z.new
153
- assert_equal Z, x.class
154
- end
155
-
156
- def test_subclass_with_attributes
157
- y = Psych.load Psych.dump Y.new.tap {|y| y.val = 1}
158
- assert_equal Y, y.class
159
- assert_equal 1, y.val
160
- end
161
-
162
- def test_string_with_base_60
163
- yaml = Psych.dump '01:03:05'
164
- assert_match "'01:03:05'", yaml
165
- assert_equal '01:03:05', Psych.load(yaml)
166
- end
167
-
168
- def test_nonascii_string_as_binary
169
- string = "hello \x80 world!"
170
- string.force_encoding 'ascii-8bit'
171
- yml = Psych.dump string
172
- assert_match(/binary/, yml)
173
- assert_equal string, Psych.load(yml)
174
- end
175
-
176
- def test_binary_string_null
177
- string = "\x00"
178
- yml = Psych.dump string
179
- assert_match(/binary/, yml)
180
- assert_equal string, Psych.load(yml)
181
- end
182
-
183
- def test_binary_string
184
- string = binary_string
185
- yml = Psych.dump string
186
- assert_match(/binary/, yml)
187
- assert_equal string, Psych.load(yml)
188
- end
189
-
190
- def test_non_binary_string
191
- string = binary_string(0.29)
192
- yml = Psych.dump string
193
- refute_match(/binary/, yml)
194
- assert_equal string, Psych.load(yml)
195
- end
196
-
197
- def test_ascii_only_8bit_string
198
- string = "abc".encode(Encoding::ASCII_8BIT)
199
- yml = Psych.dump string
200
- refute_match(/binary/, yml)
201
- assert_equal string, Psych.load(yml)
202
- end
203
-
204
- def test_string_with_ivars
205
- food = "is delicious"
206
- ivar = "on rock and roll"
207
- food.instance_variable_set(:@we_built_this_city, ivar)
208
-
209
- Psych.load Psych.dump food
210
- assert_equal ivar, food.instance_variable_get(:@we_built_this_city)
211
- end
212
-
213
- def test_binary
214
- string = [0, 123,22, 44, 9, 32, 34, 39].pack('C*')
215
- assert_cycle string
216
- end
217
-
218
- def test_float_confusion
219
- assert_cycle '1.'
220
- end
221
-
222
- def binary_string percentage = 0.31, length = 100
223
- string = ''
224
- (percentage * length).to_i.times do |i|
225
- string << "\b"
226
- end
227
- string << 'a' * (length - string.length)
228
- string
229
- end
230
- end
231
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- class PsychStructWithIvar < Struct.new(:foo)
5
- attr_reader :bar
6
- def initialize *args
7
- super
8
- @bar = 'hello'
9
- end
10
- end
11
-
12
- module Psych
13
- class TestStruct < TestCase
14
- class StructSubclass < Struct.new(:foo)
15
- def initialize foo, bar
16
- super(foo)
17
- @bar = bar
18
- end
19
- end
20
-
21
- def test_self_referential_struct
22
- ss = StructSubclass.new(nil, 'foo')
23
- ss.foo = ss
24
-
25
- loaded = Psych.load(Psych.dump(ss))
26
- assert_instance_of(StructSubclass, loaded.foo)
27
-
28
- assert_equal(ss, loaded)
29
- end
30
-
31
- def test_roundtrip
32
- thing = PsychStructWithIvar.new('bar')
33
- struct = Psych.load(Psych.dump(thing))
34
-
35
- assert_equal 'hello', struct.bar
36
- assert_equal 'bar', struct.foo
37
- end
38
-
39
- def test_load
40
- obj = Psych.load(<<-eoyml)
41
- --- !ruby/struct:PsychStructWithIvar
42
- :foo: bar
43
- :@bar: hello
44
- eoyml
45
-
46
- assert_equal 'hello', obj.bar
47
- assert_equal 'bar', obj.foo
48
- end
49
- end
50
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestSymbol < TestCase
6
- def test_cycle_empty
7
- assert_cycle :''
8
- end
9
-
10
- def test_cycle_colon
11
- assert_cycle :':'
12
- end
13
-
14
- def test_cycle
15
- assert_cycle :a
16
- end
17
-
18
- def test_stringy
19
- assert_cycle :"1"
20
- end
21
-
22
- def test_load_quoted
23
- assert_equal :"1", Psych.load("--- :'1'\n")
24
- end
25
- end
26
- end
@@ -1,131 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestStringTainted < TestCase
6
- class Tainted < Handler
7
- attr_reader :tc
8
-
9
- def initialize tc
10
- @tc = tc
11
- end
12
-
13
- def start_document version, tags, implicit
14
- tags.flatten.each do |tag|
15
- assert_taintedness tag
16
- end
17
- end
18
-
19
- def alias name
20
- assert_taintedness name
21
- end
22
-
23
- def scalar value, anchor, tag, plain, quoted, style
24
- assert_taintedness value
25
- assert_taintedness tag if tag
26
- assert_taintedness anchor if anchor
27
- end
28
-
29
- def start_sequence anchor, tag, implicit, style
30
- assert_taintedness tag if tag
31
- assert_taintedness anchor if anchor
32
- end
33
-
34
- def start_mapping anchor, tag, implicit, style
35
- assert_taintedness tag if tag
36
- assert_taintedness anchor if anchor
37
- end
38
-
39
- def assert_taintedness thing, message = "'#{thing}' should be tainted"
40
- tc.assert thing.tainted?, message
41
- end
42
- end
43
-
44
- class Untainted < Tainted
45
- def assert_taintedness thing, message = "'#{thing}' should not be tainted"
46
- tc.assert !thing.tainted?, message
47
- end
48
- end
49
-
50
-
51
- def setup
52
- handler = Tainted.new self
53
- @parser = Psych::Parser.new handler
54
- end
55
-
56
- def test_tags_are_tainted
57
- assert_taintedness "%TAG !yaml! tag:yaml.org,2002:\n---\n!yaml!str \"foo\""
58
- end
59
-
60
- def test_alias
61
- assert_taintedness "--- &ponies\n- foo\n- *ponies"
62
- end
63
-
64
- def test_scalar
65
- assert_taintedness "--- ponies"
66
- end
67
-
68
- def test_anchor
69
- assert_taintedness "--- &hi ponies"
70
- end
71
-
72
- def test_scalar_tag
73
- assert_taintedness "--- !str ponies"
74
- end
75
-
76
- def test_seq_start_tag
77
- assert_taintedness "--- !!seq [ a ]"
78
- end
79
-
80
- def test_seq_start_anchor
81
- assert_taintedness "--- &zomg [ a ]"
82
- end
83
-
84
- def test_seq_mapping_tag
85
- assert_taintedness "--- !!map { a: b }"
86
- end
87
-
88
- def test_seq_mapping_anchor
89
- assert_taintedness "--- &himom { a: b }"
90
- end
91
-
92
- def assert_taintedness string
93
- @parser.parse string.taint
94
- end
95
- end
96
-
97
- class TestStringUntainted < TestStringTainted
98
- def setup
99
- handler = Untainted.new self
100
- @parser = Psych::Parser.new handler
101
- end
102
-
103
- def assert_taintedness string
104
- @parser.parse string
105
- end
106
- end
107
-
108
- class TestStringIOUntainted < TestStringTainted
109
- def setup
110
- handler = Untainted.new self
111
- @parser = Psych::Parser.new handler
112
- end
113
-
114
- def assert_taintedness string
115
- @parser.parse StringIO.new(string)
116
- end
117
- end
118
-
119
- class TestIOTainted < TestStringTainted
120
- def assert_taintedness string
121
- Tempfile.create(['something', 'yml']) {|t|
122
- t.binmode
123
- t.write string
124
- t.close
125
- File.open(t.path, 'r:bom|utf-8') { |f|
126
- @parser.parse f
127
- }
128
- }
129
- end
130
- end
131
- end