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.
- checksums.yaml +4 -4
- data/.gitignore +14 -0
- data/Gemfile +3 -0
- data/Mavenfile +7 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/ext/java/PsychEmitter.java +345 -0
- data/ext/java/PsychLibrary.java +93 -0
- data/ext/java/PsychParser.java +399 -0
- data/ext/java/PsychToRuby.java +79 -0
- data/ext/java/PsychYamlTree.java +55 -0
- data/ext/psych/.gitignore +11 -0
- data/lib/psych.rb +2 -2
- data/lib/psych/visitors/to_ruby.rb +2 -2
- data/psych.gemspec +39 -0
- metadata +19 -53
- data/test/psych/handlers/test_recorder.rb +0 -26
- data/test/psych/helper.rb +0 -122
- data/test/psych/json/test_stream.rb +0 -110
- data/test/psych/nodes/test_enumerable.rb +0 -44
- data/test/psych/test_alias_and_anchor.rb +0 -97
- data/test/psych/test_array.rb +0 -58
- data/test/psych/test_boolean.rb +0 -37
- data/test/psych/test_class.rb +0 -37
- data/test/psych/test_coder.rb +0 -207
- data/test/psych/test_date_time.rb +0 -39
- data/test/psych/test_deprecated.rb +0 -215
- data/test/psych/test_document.rb +0 -47
- data/test/psych/test_emitter.rb +0 -112
- data/test/psych/test_encoding.rb +0 -269
- data/test/psych/test_exception.rb +0 -158
- data/test/psych/test_hash.rb +0 -95
- data/test/psych/test_json_tree.rb +0 -66
- data/test/psych/test_merge_keys.rb +0 -181
- data/test/psych/test_nil.rb +0 -19
- data/test/psych/test_null.rb +0 -20
- data/test/psych/test_numeric.rb +0 -46
- data/test/psych/test_object.rb +0 -45
- data/test/psych/test_object_references.rb +0 -72
- data/test/psych/test_omap.rb +0 -76
- data/test/psych/test_parser.rb +0 -340
- data/test/psych/test_psych.rb +0 -184
- data/test/psych/test_safe_load.rb +0 -98
- data/test/psych/test_scalar.rb +0 -12
- data/test/psych/test_scalar_scanner.rb +0 -111
- data/test/psych/test_serialize_subclasses.rb +0 -39
- data/test/psych/test_set.rb +0 -50
- data/test/psych/test_stream.rb +0 -94
- data/test/psych/test_string.rb +0 -231
- data/test/psych/test_struct.rb +0 -50
- data/test/psych/test_symbol.rb +0 -26
- data/test/psych/test_tainted.rb +0 -131
- data/test/psych/test_to_yaml_properties.rb +0 -64
- data/test/psych/test_tree_builder.rb +0 -80
- data/test/psych/test_yaml.rb +0 -1293
- data/test/psych/test_yamldbm.rb +0 -193
- data/test/psych/test_yamlstore.rb +0 -86
- data/test/psych/visitors/test_depth_first.rb +0 -50
- data/test/psych/visitors/test_emitter.rb +0 -145
- data/test/psych/visitors/test_to_ruby.rb +0 -332
- data/test/psych/visitors/test_yaml_tree.rb +0 -180
@@ -1,158 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
module Psych
|
5
|
-
class TestException < TestCase
|
6
|
-
class Wups < Exception
|
7
|
-
attr_reader :foo, :bar
|
8
|
-
def initialize *args
|
9
|
-
super
|
10
|
-
@foo = 1
|
11
|
-
@bar = 2
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def setup
|
16
|
-
super
|
17
|
-
@wups = Wups.new
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_naming_exception
|
21
|
-
err = String.xxx rescue $!
|
22
|
-
new_err = Psych.load(Psych.dump(err))
|
23
|
-
assert_equal err.message, new_err.message
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_load_takes_file
|
27
|
-
ex = assert_raises(Psych::SyntaxError) do
|
28
|
-
Psych.load '--- `'
|
29
|
-
end
|
30
|
-
assert_nil ex.file
|
31
|
-
|
32
|
-
ex = assert_raises(Psych::SyntaxError) do
|
33
|
-
Psych.load '--- `', 'meow'
|
34
|
-
end
|
35
|
-
assert_equal 'meow', ex.file
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_psych_parse_stream_takes_file
|
39
|
-
ex = assert_raises(Psych::SyntaxError) do
|
40
|
-
Psych.parse_stream '--- `'
|
41
|
-
end
|
42
|
-
assert_nil ex.file
|
43
|
-
assert_match '(<unknown>)', ex.message
|
44
|
-
|
45
|
-
ex = assert_raises(Psych::SyntaxError) do
|
46
|
-
Psych.parse_stream '--- `', 'omg!'
|
47
|
-
end
|
48
|
-
assert_equal 'omg!', ex.file
|
49
|
-
assert_match 'omg!', ex.message
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_load_stream_takes_file
|
53
|
-
ex = assert_raises(Psych::SyntaxError) do
|
54
|
-
Psych.load_stream '--- `'
|
55
|
-
end
|
56
|
-
assert_nil ex.file
|
57
|
-
assert_match '(<unknown>)', ex.message
|
58
|
-
|
59
|
-
ex = assert_raises(Psych::SyntaxError) do
|
60
|
-
Psych.load_stream '--- `', 'omg!'
|
61
|
-
end
|
62
|
-
assert_equal 'omg!', ex.file
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_parse_file_exception
|
66
|
-
Tempfile.create(['parsefile', 'yml']) {|t|
|
67
|
-
t.binmode
|
68
|
-
t.write '--- `'
|
69
|
-
t.close
|
70
|
-
ex = assert_raises(Psych::SyntaxError) do
|
71
|
-
Psych.parse_file t.path
|
72
|
-
end
|
73
|
-
assert_equal t.path, ex.file
|
74
|
-
}
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_load_file_exception
|
78
|
-
Tempfile.create(['loadfile', 'yml']) {|t|
|
79
|
-
t.binmode
|
80
|
-
t.write '--- `'
|
81
|
-
t.close
|
82
|
-
ex = assert_raises(Psych::SyntaxError) do
|
83
|
-
Psych.load_file t.path
|
84
|
-
end
|
85
|
-
assert_equal t.path, ex.file
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
def test_psych_parse_takes_file
|
90
|
-
ex = assert_raises(Psych::SyntaxError) do
|
91
|
-
Psych.parse '--- `'
|
92
|
-
end
|
93
|
-
assert_match '(<unknown>)', ex.message
|
94
|
-
assert_nil ex.file
|
95
|
-
|
96
|
-
ex = assert_raises(Psych::SyntaxError) do
|
97
|
-
Psych.parse '--- `', 'omg!'
|
98
|
-
end
|
99
|
-
assert_match 'omg!', ex.message
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_attributes
|
103
|
-
e = assert_raises(Psych::SyntaxError) {
|
104
|
-
Psych.load '--- `foo'
|
105
|
-
}
|
106
|
-
|
107
|
-
assert_nil e.file
|
108
|
-
assert_equal 1, e.line
|
109
|
-
assert_equal 5, e.column
|
110
|
-
# FIXME: offset isn't being set correctly by libyaml
|
111
|
-
# assert_equal 5, e.offset
|
112
|
-
|
113
|
-
assert e.problem
|
114
|
-
assert e.context
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_convert
|
118
|
-
w = Psych.load(Psych.dump(@wups))
|
119
|
-
assert_equal @wups, w
|
120
|
-
assert_equal 1, w.foo
|
121
|
-
assert_equal 2, w.bar
|
122
|
-
end
|
123
|
-
|
124
|
-
def test_to_yaml_properties
|
125
|
-
class << @wups
|
126
|
-
def to_yaml_properties
|
127
|
-
[:@foo]
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
w = Psych.load(Psych.dump(@wups))
|
132
|
-
assert_equal @wups, w
|
133
|
-
assert_equal 1, w.foo
|
134
|
-
assert_nil w.bar
|
135
|
-
end
|
136
|
-
|
137
|
-
def test_psych_syntax_error
|
138
|
-
Tempfile.create(['parsefile', 'yml']) do |t|
|
139
|
-
t.binmode
|
140
|
-
t.write '--- `'
|
141
|
-
t.close
|
142
|
-
|
143
|
-
begin
|
144
|
-
Psych.parse_file t.path
|
145
|
-
rescue StandardError
|
146
|
-
assert true # count assertion
|
147
|
-
ensure
|
148
|
-
return unless $!
|
149
|
-
|
150
|
-
ancestors = $!.class.ancestors.inspect
|
151
|
-
|
152
|
-
flunk "Psych::SyntaxError not rescued by StandardError: #{ancestors}"
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
end
|
158
|
-
end
|
data/test/psych/test_hash.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
module Psych
|
5
|
-
class TestHash < TestCase
|
6
|
-
class X < Hash
|
7
|
-
end
|
8
|
-
|
9
|
-
class HashWithCustomInit < Hash
|
10
|
-
attr_reader :obj
|
11
|
-
def initialize(obj)
|
12
|
-
@obj = obj
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class HashWithCustomInitNoIvar < Hash
|
17
|
-
def initialize(obj)
|
18
|
-
# *shrug*
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def setup
|
23
|
-
super
|
24
|
-
@hash = { :a => 'b' }
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_referenced_hash_with_ivar
|
28
|
-
a = [1,2,3,4,5]
|
29
|
-
t1 = [HashWithCustomInit.new(a)]
|
30
|
-
t1 << t1.first
|
31
|
-
assert_cycle t1
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_custom_initialized
|
35
|
-
a = [1,2,3,4,5]
|
36
|
-
t1 = HashWithCustomInit.new(a)
|
37
|
-
t2 = Psych.load(Psych.dump(t1))
|
38
|
-
assert_equal t1, t2
|
39
|
-
assert_cycle t1
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_custom_initialize_no_ivar
|
43
|
-
t1 = HashWithCustomInitNoIvar.new(nil)
|
44
|
-
t2 = Psych.load(Psych.dump(t1))
|
45
|
-
assert_equal t1, t2
|
46
|
-
assert_cycle t1
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_hash_subclass_with_ivars
|
50
|
-
x = X.new
|
51
|
-
x[:a] = 'b'
|
52
|
-
x.instance_variable_set :@foo, 'bar'
|
53
|
-
dup = Psych.load Psych.dump x
|
54
|
-
assert_cycle x
|
55
|
-
assert_equal 'bar', dup.instance_variable_get(:@foo)
|
56
|
-
assert_equal X, dup.class
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_load_with_class_syck_compatibility
|
60
|
-
hash = Psych.load "--- !ruby/object:Hash\n:user_id: 7\n:username: Lucas\n"
|
61
|
-
assert_equal({ user_id: 7, username: 'Lucas'}, hash)
|
62
|
-
end
|
63
|
-
|
64
|
-
def test_empty_subclass
|
65
|
-
assert_match "!ruby/hash:#{X}", Psych.dump(X.new)
|
66
|
-
x = Psych.load Psych.dump X.new
|
67
|
-
assert_equal X, x.class
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_map
|
71
|
-
x = Psych.load "--- !map:#{X} { }\n"
|
72
|
-
assert_equal X, x.class
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_self_referential
|
76
|
-
@hash['self'] = @hash
|
77
|
-
assert_cycle(@hash)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_cycles
|
81
|
-
assert_cycle(@hash)
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_ref_append
|
85
|
-
hash = Psych.load(<<-eoyml)
|
86
|
-
---
|
87
|
-
foo: &foo
|
88
|
-
hello: world
|
89
|
-
bar:
|
90
|
-
<<: *foo
|
91
|
-
eoyml
|
92
|
-
assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
module Psych
|
5
|
-
class TestJSONTree < TestCase
|
6
|
-
def test_string
|
7
|
-
assert_match(/"foo"/, Psych.to_json("foo"))
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_symbol
|
11
|
-
assert_match(/"foo"/, Psych.to_json(:foo))
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_nil
|
15
|
-
assert_match(/^null/, Psych.to_json(nil))
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_int
|
19
|
-
assert_match(/^10/, Psych.to_json(10))
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_float
|
23
|
-
assert_match(/^1.2/, Psych.to_json(1.2))
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_hash
|
27
|
-
hash = { 'one' => 'two' }
|
28
|
-
json = Psych.to_json(hash)
|
29
|
-
assert_match(/}$/, json)
|
30
|
-
assert_match(/^\{/, json)
|
31
|
-
assert_match(/['"]one['"]/, json)
|
32
|
-
assert_match(/['"]two['"]/, json)
|
33
|
-
end
|
34
|
-
|
35
|
-
class Bar
|
36
|
-
def encode_with coder
|
37
|
-
coder.represent_seq 'omg', %w{ a b c }
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_json_list_dump_exclude_tag
|
42
|
-
json = Psych.to_json Bar.new
|
43
|
-
refute_match('omg', json)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_list_to_json
|
47
|
-
list = %w{ one two }
|
48
|
-
json = Psych.to_json(list)
|
49
|
-
assert_match(/\]$/, json)
|
50
|
-
assert_match(/^\[/, json)
|
51
|
-
assert_match(/"one"/, json)
|
52
|
-
assert_match(/"two"/, json)
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_time
|
56
|
-
time = Time.utc(2010, 10, 10)
|
57
|
-
assert_equal "{\"a\": \"2010-10-10 00:00:00.000000000 Z\"}\n",
|
58
|
-
Psych.to_json({'a' => time })
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_datetime
|
62
|
-
time = Time.new(2010, 10, 10).to_datetime
|
63
|
-
assert_equal "{\"a\": \"#{time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")}\"}\n", Psych.to_json({'a' => time })
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
@@ -1,181 +0,0 @@
|
|
1
|
-
# frozen_string_literal: false
|
2
|
-
require_relative 'helper'
|
3
|
-
|
4
|
-
module Psych
|
5
|
-
class TestMergeKeys < TestCase
|
6
|
-
class Product
|
7
|
-
attr_reader :bar
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_merge_key_with_bare_hash
|
11
|
-
doc = Psych.load <<-eodoc
|
12
|
-
map:
|
13
|
-
<<:
|
14
|
-
hello: world
|
15
|
-
eodoc
|
16
|
-
hash = { "map" => { "hello" => "world" } }
|
17
|
-
assert_equal hash, doc
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_roundtrip_with_chevron_key
|
21
|
-
h = {}
|
22
|
-
v = { 'a' => h, '<<' => h }
|
23
|
-
assert_cycle v
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_explicit_string
|
27
|
-
doc = Psych.load <<-eoyml
|
28
|
-
a: &me { hello: world }
|
29
|
-
b: { !!str '<<': *me }
|
30
|
-
eoyml
|
31
|
-
expected = {
|
32
|
-
"a" => { "hello" => "world" },
|
33
|
-
"b" => {
|
34
|
-
"<<" => { "hello" => "world" }
|
35
|
-
}
|
36
|
-
}
|
37
|
-
assert_equal expected, doc
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_mergekey_with_object
|
41
|
-
s = <<-eoyml
|
42
|
-
foo: &foo
|
43
|
-
bar: 10
|
44
|
-
product:
|
45
|
-
!ruby/object:#{Product.name}
|
46
|
-
<<: *foo
|
47
|
-
eoyml
|
48
|
-
hash = Psych.load s
|
49
|
-
assert_equal({"bar" => 10}, hash["foo"])
|
50
|
-
product = hash["product"]
|
51
|
-
assert_equal 10, product.bar
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_merge_nil
|
55
|
-
yaml = <<-eoyml
|
56
|
-
defaults: &defaults
|
57
|
-
development:
|
58
|
-
<<: *defaults
|
59
|
-
eoyml
|
60
|
-
assert_equal({'<<' => nil }, Psych.load(yaml)['development'])
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_merge_array
|
64
|
-
yaml = <<-eoyml
|
65
|
-
foo: &hello
|
66
|
-
- 1
|
67
|
-
baz:
|
68
|
-
<<: *hello
|
69
|
-
eoyml
|
70
|
-
assert_equal({'<<' => [1]}, Psych.load(yaml)['baz'])
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_merge_is_not_partial
|
74
|
-
yaml = <<-eoyml
|
75
|
-
default: &default
|
76
|
-
hello: world
|
77
|
-
foo: &hello
|
78
|
-
- 1
|
79
|
-
baz:
|
80
|
-
<<: [*hello, *default]
|
81
|
-
eoyml
|
82
|
-
doc = Psych.load yaml
|
83
|
-
refute doc['baz'].key? 'hello'
|
84
|
-
assert_equal({'<<' => [[1], {"hello"=>"world"}]}, Psych.load(yaml)['baz'])
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_merge_seq_nil
|
88
|
-
yaml = <<-eoyml
|
89
|
-
foo: &hello
|
90
|
-
baz:
|
91
|
-
<<: [*hello]
|
92
|
-
eoyml
|
93
|
-
assert_equal({'<<' => [nil]}, Psych.load(yaml)['baz'])
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_bad_seq_merge
|
97
|
-
yaml = <<-eoyml
|
98
|
-
defaults: &defaults [1, 2, 3]
|
99
|
-
development:
|
100
|
-
<<: *defaults
|
101
|
-
eoyml
|
102
|
-
assert_equal({'<<' => [1,2,3]}, Psych.load(yaml)['development'])
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_missing_merge_key
|
106
|
-
yaml = <<-eoyml
|
107
|
-
bar:
|
108
|
-
<< : *foo
|
109
|
-
eoyml
|
110
|
-
exp = assert_raises(Psych::BadAlias) { Psych.load yaml }
|
111
|
-
assert_match 'foo', exp.message
|
112
|
-
end
|
113
|
-
|
114
|
-
# [ruby-core:34679]
|
115
|
-
def test_merge_key
|
116
|
-
yaml = <<-eoyml
|
117
|
-
foo: &foo
|
118
|
-
hello: world
|
119
|
-
bar:
|
120
|
-
<< : *foo
|
121
|
-
baz: boo
|
122
|
-
eoyml
|
123
|
-
|
124
|
-
hash = {
|
125
|
-
"foo" => { "hello" => "world"},
|
126
|
-
"bar" => { "hello" => "world", "baz" => "boo" } }
|
127
|
-
assert_equal hash, Psych.load(yaml)
|
128
|
-
end
|
129
|
-
|
130
|
-
def test_multiple_maps
|
131
|
-
yaml = <<-eoyaml
|
132
|
-
---
|
133
|
-
- &CENTER { x: 1, y: 2 }
|
134
|
-
- &LEFT { x: 0, y: 2 }
|
135
|
-
- &BIG { r: 10 }
|
136
|
-
- &SMALL { r: 1 }
|
137
|
-
|
138
|
-
# All the following maps are equal:
|
139
|
-
|
140
|
-
- # Merge multiple maps
|
141
|
-
<< : [ *CENTER, *BIG ]
|
142
|
-
label: center/big
|
143
|
-
eoyaml
|
144
|
-
|
145
|
-
hash = {
|
146
|
-
'x' => 1,
|
147
|
-
'y' => 2,
|
148
|
-
'r' => 10,
|
149
|
-
'label' => 'center/big'
|
150
|
-
}
|
151
|
-
|
152
|
-
assert_equal hash, Psych.load(yaml)[4]
|
153
|
-
end
|
154
|
-
|
155
|
-
def test_override
|
156
|
-
yaml = <<-eoyaml
|
157
|
-
---
|
158
|
-
- &CENTER { x: 1, y: 2 }
|
159
|
-
- &LEFT { x: 0, y: 2 }
|
160
|
-
- &BIG { r: 10 }
|
161
|
-
- &SMALL { r: 1 }
|
162
|
-
|
163
|
-
# All the following maps are equal:
|
164
|
-
|
165
|
-
- # Override
|
166
|
-
<< : [ *BIG, *LEFT, *SMALL ]
|
167
|
-
x: 1
|
168
|
-
label: center/big
|
169
|
-
eoyaml
|
170
|
-
|
171
|
-
hash = {
|
172
|
-
'x' => 1,
|
173
|
-
'y' => 2,
|
174
|
-
'r' => 10,
|
175
|
-
'label' => 'center/big'
|
176
|
-
}
|
177
|
-
|
178
|
-
assert_equal hash, Psych.load(yaml)[4]
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|