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,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
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class TestNil < TestCase
6
- def test_nil
7
- yml = Psych.dump nil
8
- assert_match(/--- \n(?:\.\.\.\n)?/, yml)
9
- assert_nil Psych.load(yml)
10
- end
11
-
12
- def test_array_nil
13
- yml = Psych.dump [nil]
14
- assert_equal "---\n- \n", yml
15
- assert_equal [nil], Psych.load(yml)
16
- end
17
-
18
- end
19
- end
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- ###
6
- # Test null from YAML spec:
7
- # http://yaml.org/type/null.html
8
- class TestNull < TestCase
9
- def test_null_list
10
- assert_equal [nil] * 5, Psych.load(<<-eoyml)
11
- ---
12
- - ~
13
- - null
14
- -
15
- - Null
16
- - NULL
17
- eoyml
18
- end
19
- end
20
- end
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
- require 'bigdecimal'
4
-
5
- module Psych
6
- ###
7
- # Test numerics from YAML spec:
8
- # http://yaml.org/type/float.html
9
- # http://yaml.org/type/int.html
10
- class TestNumeric < TestCase
11
- def setup
12
- @old_debug = $DEBUG
13
- $DEBUG = true
14
- end
15
-
16
- def teardown
17
- $DEBUG = @old_debug
18
- end
19
-
20
- def test_load_float_with_dot
21
- assert_equal 1.0, Psych.load('--- 1.')
22
- end
23
-
24
- def test_non_float_with_0
25
- str = Psych.load('--- 090')
26
- assert_equal '090', str
27
- end
28
-
29
- def test_big_decimal_tag
30
- decimal = BigDecimal("12.34")
31
- assert_match "!ruby/object:BigDecimal", Psych.dump(decimal)
32
- end
33
-
34
- def test_big_decimal_round_trip
35
- decimal = BigDecimal("12.34")
36
- assert_cycle decimal
37
- end
38
-
39
- def test_does_not_attempt_numeric
40
- str = Psych.load('--- 4 roses')
41
- assert_equal '4 roses', str
42
- str = Psych.load('--- 1.1.1')
43
- assert_equal '1.1.1', str
44
- end
45
- end
46
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'helper'
3
-
4
- module Psych
5
- class Tagged
6
- yaml_tag '!foo'
7
-
8
- attr_accessor :baz
9
-
10
- def initialize
11
- @baz = 'bar'
12
- end
13
- end
14
-
15
- class Foo
16
- attr_accessor :parent
17
-
18
- def initialize parent
19
- @parent = parent
20
- end
21
- end
22
-
23
- class TestObject < TestCase
24
- def test_dump_with_tag
25
- tag = Tagged.new
26
- assert_match('foo', Psych.dump(tag))
27
- end
28
-
29
- def test_tag_round_trip
30
- tag = Tagged.new
31
- tag2 = Psych.load(Psych.dump(tag))
32
- assert_equal tag.baz, tag2.baz
33
- assert_instance_of(Tagged, tag2)
34
- end
35
-
36
- def test_cyclic_references
37
- foo = Foo.new(nil)
38
- foo.parent = foo
39
- loaded = Psych.load Psych.dump foo
40
-
41
- assert_instance_of(Foo, loaded)
42
- assert_equal loaded, loaded.parent
43
- end
44
- end
45
- end