psych 2.0.14-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 (118) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +18 -0
  3. data/.gemtest +0 -0
  4. data/.travis.yml +16 -0
  5. data/CHANGELOG.rdoc +576 -0
  6. data/Manifest.txt +114 -0
  7. data/README.rdoc +71 -0
  8. data/Rakefile +123 -0
  9. data/ext/psych/depend +3 -0
  10. data/ext/psych/extconf.rb +38 -0
  11. data/ext/psych/psych.c +34 -0
  12. data/ext/psych/psych.h +20 -0
  13. data/ext/psych/psych_emitter.c +555 -0
  14. data/ext/psych/psych_emitter.h +8 -0
  15. data/ext/psych/psych_parser.c +597 -0
  16. data/ext/psych/psych_parser.h +6 -0
  17. data/ext/psych/psych_to_ruby.c +43 -0
  18. data/ext/psych/psych_to_ruby.h +8 -0
  19. data/ext/psych/psych_yaml_tree.c +24 -0
  20. data/ext/psych/psych_yaml_tree.h +8 -0
  21. data/ext/psych/yaml/LICENSE +19 -0
  22. data/ext/psych/yaml/api.c +1415 -0
  23. data/ext/psych/yaml/config.h +10 -0
  24. data/ext/psych/yaml/dumper.c +394 -0
  25. data/ext/psych/yaml/emitter.c +2329 -0
  26. data/ext/psych/yaml/loader.c +459 -0
  27. data/ext/psych/yaml/parser.c +1370 -0
  28. data/ext/psych/yaml/reader.c +469 -0
  29. data/ext/psych/yaml/scanner.c +3576 -0
  30. data/ext/psych/yaml/writer.c +141 -0
  31. data/ext/psych/yaml/yaml.h +1971 -0
  32. data/ext/psych/yaml/yaml_private.h +664 -0
  33. data/lib/psych.jar +0 -0
  34. data/lib/psych.rb +504 -0
  35. data/lib/psych/class_loader.rb +101 -0
  36. data/lib/psych/coder.rb +94 -0
  37. data/lib/psych/core_ext.rb +35 -0
  38. data/lib/psych/deprecated.rb +85 -0
  39. data/lib/psych/exception.rb +13 -0
  40. data/lib/psych/handler.rb +249 -0
  41. data/lib/psych/handlers/document_stream.rb +22 -0
  42. data/lib/psych/handlers/recorder.rb +39 -0
  43. data/lib/psych/json/ruby_events.rb +19 -0
  44. data/lib/psych/json/stream.rb +16 -0
  45. data/lib/psych/json/tree_builder.rb +12 -0
  46. data/lib/psych/json/yaml_events.rb +29 -0
  47. data/lib/psych/nodes.rb +77 -0
  48. data/lib/psych/nodes/alias.rb +18 -0
  49. data/lib/psych/nodes/document.rb +60 -0
  50. data/lib/psych/nodes/mapping.rb +56 -0
  51. data/lib/psych/nodes/node.rb +55 -0
  52. data/lib/psych/nodes/scalar.rb +67 -0
  53. data/lib/psych/nodes/sequence.rb +81 -0
  54. data/lib/psych/nodes/stream.rb +37 -0
  55. data/lib/psych/omap.rb +4 -0
  56. data/lib/psych/parser.rb +51 -0
  57. data/lib/psych/scalar_scanner.rb +149 -0
  58. data/lib/psych/set.rb +4 -0
  59. data/lib/psych/stream.rb +37 -0
  60. data/lib/psych/streaming.rb +27 -0
  61. data/lib/psych/syntax_error.rb +21 -0
  62. data/lib/psych/tree_builder.rb +96 -0
  63. data/lib/psych/versions.rb +3 -0
  64. data/lib/psych/visitors.rb +6 -0
  65. data/lib/psych/visitors/depth_first.rb +26 -0
  66. data/lib/psych/visitors/emitter.rb +51 -0
  67. data/lib/psych/visitors/json_tree.rb +24 -0
  68. data/lib/psych/visitors/to_ruby.rb +404 -0
  69. data/lib/psych/visitors/visitor.rb +19 -0
  70. data/lib/psych/visitors/yaml_tree.rb +605 -0
  71. data/lib/psych/y.rb +9 -0
  72. data/lib/psych_jars.rb +5 -0
  73. data/test/psych/handlers/test_recorder.rb +25 -0
  74. data/test/psych/helper.rb +121 -0
  75. data/test/psych/json/test_stream.rb +109 -0
  76. data/test/psych/nodes/test_enumerable.rb +43 -0
  77. data/test/psych/test_alias_and_anchor.rb +96 -0
  78. data/test/psych/test_array.rb +57 -0
  79. data/test/psych/test_boolean.rb +36 -0
  80. data/test/psych/test_class.rb +36 -0
  81. data/test/psych/test_coder.rb +206 -0
  82. data/test/psych/test_date_time.rb +38 -0
  83. data/test/psych/test_deprecated.rb +214 -0
  84. data/test/psych/test_document.rb +46 -0
  85. data/test/psych/test_emitter.rb +93 -0
  86. data/test/psych/test_encoding.rb +259 -0
  87. data/test/psych/test_exception.rb +157 -0
  88. data/test/psych/test_hash.rb +94 -0
  89. data/test/psych/test_json_tree.rb +65 -0
  90. data/test/psych/test_merge_keys.rb +180 -0
  91. data/test/psych/test_nil.rb +18 -0
  92. data/test/psych/test_null.rb +19 -0
  93. data/test/psych/test_numeric.rb +45 -0
  94. data/test/psych/test_object.rb +44 -0
  95. data/test/psych/test_object_references.rb +71 -0
  96. data/test/psych/test_omap.rb +75 -0
  97. data/test/psych/test_parser.rb +339 -0
  98. data/test/psych/test_psych.rb +168 -0
  99. data/test/psych/test_safe_load.rb +97 -0
  100. data/test/psych/test_scalar.rb +11 -0
  101. data/test/psych/test_scalar_scanner.rb +106 -0
  102. data/test/psych/test_serialize_subclasses.rb +38 -0
  103. data/test/psych/test_set.rb +49 -0
  104. data/test/psych/test_stream.rb +93 -0
  105. data/test/psych/test_string.rb +226 -0
  106. data/test/psych/test_struct.rb +49 -0
  107. data/test/psych/test_symbol.rb +25 -0
  108. data/test/psych/test_tainted.rb +130 -0
  109. data/test/psych/test_to_yaml_properties.rb +63 -0
  110. data/test/psych/test_tree_builder.rb +79 -0
  111. data/test/psych/test_yaml.rb +1292 -0
  112. data/test/psych/test_yamldbm.rb +193 -0
  113. data/test/psych/test_yamlstore.rb +85 -0
  114. data/test/psych/visitors/test_depth_first.rb +49 -0
  115. data/test/psych/visitors/test_emitter.rb +144 -0
  116. data/test/psych/visitors/test_to_ruby.rb +333 -0
  117. data/test/psych/visitors/test_yaml_tree.rb +173 -0
  118. metadata +240 -0
@@ -0,0 +1,94 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestHash < TestCase
5
+ class X < Hash
6
+ end
7
+
8
+ class HashWithCustomInit < Hash
9
+ attr_reader :obj
10
+ def initialize(obj)
11
+ @obj = obj
12
+ end
13
+ end
14
+
15
+ class HashWithCustomInitNoIvar < Hash
16
+ def initialize(obj)
17
+ # *shrug*
18
+ end
19
+ end
20
+
21
+ def setup
22
+ super
23
+ @hash = { :a => 'b' }
24
+ end
25
+
26
+ def test_referenced_hash_with_ivar
27
+ a = [1,2,3,4,5]
28
+ t1 = [HashWithCustomInit.new(a)]
29
+ t1 << t1.first
30
+ assert_cycle t1
31
+ end
32
+
33
+ def test_custom_initialized
34
+ a = [1,2,3,4,5]
35
+ t1 = HashWithCustomInit.new(a)
36
+ t2 = Psych.load(Psych.dump(t1))
37
+ assert_equal t1, t2
38
+ assert_cycle t1
39
+ end
40
+
41
+ def test_custom_initialize_no_ivar
42
+ t1 = HashWithCustomInitNoIvar.new(nil)
43
+ t2 = Psych.load(Psych.dump(t1))
44
+ assert_equal t1, t2
45
+ assert_cycle t1
46
+ end
47
+
48
+ def test_hash_subclass_with_ivars
49
+ x = X.new
50
+ x[:a] = 'b'
51
+ x.instance_variable_set :@foo, 'bar'
52
+ dup = Psych.load Psych.dump x
53
+ assert_cycle x
54
+ assert_equal 'bar', dup.instance_variable_get(:@foo)
55
+ assert_equal X, dup.class
56
+ end
57
+
58
+ def test_load_with_class_syck_compatibility
59
+ hash = Psych.load "--- !ruby/object:Hash\n:user_id: 7\n:username: Lucas\n"
60
+ assert_equal({ user_id: 7, username: 'Lucas'}, hash)
61
+ end
62
+
63
+ def test_empty_subclass
64
+ assert_match "!ruby/hash:#{X}", Psych.dump(X.new)
65
+ x = Psych.load Psych.dump X.new
66
+ assert_equal X, x.class
67
+ end
68
+
69
+ def test_map
70
+ x = Psych.load "--- !map:#{X} { }\n"
71
+ assert_equal X, x.class
72
+ end
73
+
74
+ def test_self_referential
75
+ @hash['self'] = @hash
76
+ assert_cycle(@hash)
77
+ end
78
+
79
+ def test_cycles
80
+ assert_cycle(@hash)
81
+ end
82
+
83
+ def test_ref_append
84
+ hash = Psych.load(<<-eoyml)
85
+ ---
86
+ foo: &foo
87
+ hello: world
88
+ bar:
89
+ <<: *foo
90
+ eoyml
91
+ assert_equal({"foo"=>{"hello"=>"world"}, "bar"=>{"hello"=>"world"}}, hash)
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,65 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestJSONTree < TestCase
5
+ def test_string
6
+ assert_match(/"foo"/, Psych.to_json("foo"))
7
+ end
8
+
9
+ def test_symbol
10
+ assert_match(/"foo"/, Psych.to_json(:foo))
11
+ end
12
+
13
+ def test_nil
14
+ assert_match(/^null/, Psych.to_json(nil))
15
+ end
16
+
17
+ def test_int
18
+ assert_match(/^10/, Psych.to_json(10))
19
+ end
20
+
21
+ def test_float
22
+ assert_match(/^1.2/, Psych.to_json(1.2))
23
+ end
24
+
25
+ def test_hash
26
+ hash = { 'one' => 'two' }
27
+ json = Psych.to_json(hash)
28
+ assert_match(/}$/, json)
29
+ assert_match(/^\{/, json)
30
+ assert_match(/['"]one['"]/, json)
31
+ assert_match(/['"]two['"]/, json)
32
+ end
33
+
34
+ class Bar
35
+ def encode_with coder
36
+ coder.represent_seq 'omg', %w{ a b c }
37
+ end
38
+ end
39
+
40
+ def test_json_list_dump_exclude_tag
41
+ json = Psych.to_json Bar.new
42
+ refute_match('omg', json)
43
+ end
44
+
45
+ def test_list_to_json
46
+ list = %w{ one two }
47
+ json = Psych.to_json(list)
48
+ assert_match(/\]$/, json)
49
+ assert_match(/^\[/, json)
50
+ assert_match(/"one"/, json)
51
+ assert_match(/"two"/, json)
52
+ end
53
+
54
+ def test_time
55
+ time = Time.utc(2010, 10, 10)
56
+ assert_equal "{\"a\": \"2010-10-10 00:00:00.000000000 Z\"}\n",
57
+ Psych.to_json({'a' => time })
58
+ end
59
+
60
+ def test_datetime
61
+ time = Time.new(2010, 10, 10).to_datetime
62
+ assert_equal "{\"a\": \"#{time.strftime("%Y-%m-%d %H:%M:%S.%9N %:z")}\"}\n", Psych.to_json({'a' => time })
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,180 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestMergeKeys < TestCase
5
+ class Product
6
+ attr_reader :bar
7
+ end
8
+
9
+ def test_merge_key_with_bare_hash
10
+ doc = Psych.load <<-eodoc
11
+ map:
12
+ <<:
13
+ hello: world
14
+ eodoc
15
+ hash = { "map" => { "hello" => "world" } }
16
+ assert_equal hash, doc
17
+ end
18
+
19
+ def test_roundtrip_with_chevron_key
20
+ h = {}
21
+ v = { 'a' => h, '<<' => h }
22
+ assert_cycle v
23
+ end
24
+
25
+ def test_explicit_string
26
+ doc = Psych.load <<-eoyml
27
+ a: &me { hello: world }
28
+ b: { !!str '<<': *me }
29
+ eoyml
30
+ expected = {
31
+ "a" => { "hello" => "world" },
32
+ "b" => {
33
+ "<<" => { "hello" => "world" }
34
+ }
35
+ }
36
+ assert_equal expected, doc
37
+ end
38
+
39
+ def test_mergekey_with_object
40
+ s = <<-eoyml
41
+ foo: &foo
42
+ bar: 10
43
+ product:
44
+ !ruby/object:#{Product.name}
45
+ <<: *foo
46
+ eoyml
47
+ hash = Psych.load s
48
+ assert_equal({"bar" => 10}, hash["foo"])
49
+ product = hash["product"]
50
+ assert_equal 10, product.bar
51
+ end
52
+
53
+ def test_merge_nil
54
+ yaml = <<-eoyml
55
+ defaults: &defaults
56
+ development:
57
+ <<: *defaults
58
+ eoyml
59
+ assert_equal({'<<' => nil }, Psych.load(yaml)['development'])
60
+ end
61
+
62
+ def test_merge_array
63
+ yaml = <<-eoyml
64
+ foo: &hello
65
+ - 1
66
+ baz:
67
+ <<: *hello
68
+ eoyml
69
+ assert_equal({'<<' => [1]}, Psych.load(yaml)['baz'])
70
+ end
71
+
72
+ def test_merge_is_not_partial
73
+ yaml = <<-eoyml
74
+ default: &default
75
+ hello: world
76
+ foo: &hello
77
+ - 1
78
+ baz:
79
+ <<: [*hello, *default]
80
+ eoyml
81
+ doc = Psych.load yaml
82
+ refute doc['baz'].key? 'hello'
83
+ assert_equal({'<<' => [[1], {"hello"=>"world"}]}, Psych.load(yaml)['baz'])
84
+ end
85
+
86
+ def test_merge_seq_nil
87
+ yaml = <<-eoyml
88
+ foo: &hello
89
+ baz:
90
+ <<: [*hello]
91
+ eoyml
92
+ assert_equal({'<<' => [nil]}, Psych.load(yaml)['baz'])
93
+ end
94
+
95
+ def test_bad_seq_merge
96
+ yaml = <<-eoyml
97
+ defaults: &defaults [1, 2, 3]
98
+ development:
99
+ <<: *defaults
100
+ eoyml
101
+ assert_equal({'<<' => [1,2,3]}, Psych.load(yaml)['development'])
102
+ end
103
+
104
+ def test_missing_merge_key
105
+ yaml = <<-eoyml
106
+ bar:
107
+ << : *foo
108
+ eoyml
109
+ exp = assert_raises(Psych::BadAlias) { Psych.load yaml }
110
+ assert_match 'foo', exp.message
111
+ end
112
+
113
+ # [ruby-core:34679]
114
+ def test_merge_key
115
+ yaml = <<-eoyml
116
+ foo: &foo
117
+ hello: world
118
+ bar:
119
+ << : *foo
120
+ baz: boo
121
+ eoyml
122
+
123
+ hash = {
124
+ "foo" => { "hello" => "world"},
125
+ "bar" => { "hello" => "world", "baz" => "boo" } }
126
+ assert_equal hash, Psych.load(yaml)
127
+ end
128
+
129
+ def test_multiple_maps
130
+ yaml = <<-eoyaml
131
+ ---
132
+ - &CENTER { x: 1, y: 2 }
133
+ - &LEFT { x: 0, y: 2 }
134
+ - &BIG { r: 10 }
135
+ - &SMALL { r: 1 }
136
+
137
+ # All the following maps are equal:
138
+
139
+ - # Merge multiple maps
140
+ << : [ *CENTER, *BIG ]
141
+ label: center/big
142
+ eoyaml
143
+
144
+ hash = {
145
+ 'x' => 1,
146
+ 'y' => 2,
147
+ 'r' => 10,
148
+ 'label' => 'center/big'
149
+ }
150
+
151
+ assert_equal hash, Psych.load(yaml)[4]
152
+ end
153
+
154
+ def test_override
155
+ yaml = <<-eoyaml
156
+ ---
157
+ - &CENTER { x: 1, y: 2 }
158
+ - &LEFT { x: 0, y: 2 }
159
+ - &BIG { r: 10 }
160
+ - &SMALL { r: 1 }
161
+
162
+ # All the following maps are equal:
163
+
164
+ - # Override
165
+ << : [ *BIG, *LEFT, *SMALL ]
166
+ x: 1
167
+ label: center/big
168
+ eoyaml
169
+
170
+ hash = {
171
+ 'x' => 1,
172
+ 'y' => 2,
173
+ 'r' => 10,
174
+ 'label' => 'center/big'
175
+ }
176
+
177
+ assert_equal hash, Psych.load(yaml)[4]
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestNil < TestCase
5
+ def test_nil
6
+ yml = Psych.dump nil
7
+ assert_match(/--- \n(?:\.\.\.\n)?/, yml)
8
+ assert_nil Psych.load(yml)
9
+ end
10
+
11
+ def test_array_nil
12
+ yml = Psych.dump [nil]
13
+ assert_equal "---\n- \n", yml
14
+ assert_equal [nil], Psych.load(yml)
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ ###
5
+ # Test null from YAML spec:
6
+ # http://yaml.org/type/null.html
7
+ class TestNull < TestCase
8
+ def test_null_list
9
+ assert_equal [nil] * 5, Psych.load(<<-eoyml)
10
+ ---
11
+ - ~
12
+ - null
13
+ -
14
+ - Null
15
+ - NULL
16
+ eoyml
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,45 @@
1
+ require_relative 'helper'
2
+ require 'bigdecimal'
3
+
4
+ module Psych
5
+ ###
6
+ # Test numerics from YAML spec:
7
+ # http://yaml.org/type/float.html
8
+ # http://yaml.org/type/int.html
9
+ class TestNumeric < TestCase
10
+ def setup
11
+ @old_debug = $DEBUG
12
+ $DEBUG = true
13
+ end
14
+
15
+ def teardown
16
+ $DEBUG = @old_debug
17
+ end
18
+
19
+ def test_load_float_with_dot
20
+ assert_equal 1.0, Psych.load('--- 1.')
21
+ end
22
+
23
+ def test_non_float_with_0
24
+ str = Psych.load('--- 090')
25
+ assert_equal '090', str
26
+ end
27
+
28
+ def test_big_decimal_tag
29
+ decimal = BigDecimal("12.34")
30
+ assert_match "!ruby/object:BigDecimal", Psych.dump(decimal)
31
+ end
32
+
33
+ def test_big_decimal_round_trip
34
+ decimal = BigDecimal("12.34")
35
+ assert_cycle decimal
36
+ end
37
+
38
+ def test_does_not_attempt_numeric
39
+ str = Psych.load('--- 4 roses')
40
+ assert_equal '4 roses', str
41
+ str = Psych.load('--- 1.1.1')
42
+ assert_equal '1.1.1', str
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,44 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class Tagged
5
+ yaml_tag '!foo'
6
+
7
+ attr_accessor :baz
8
+
9
+ def initialize
10
+ @baz = 'bar'
11
+ end
12
+ end
13
+
14
+ class Foo
15
+ attr_accessor :parent
16
+
17
+ def initialize parent
18
+ @parent = parent
19
+ end
20
+ end
21
+
22
+ class TestObject < TestCase
23
+ def test_dump_with_tag
24
+ tag = Tagged.new
25
+ assert_match('foo', Psych.dump(tag))
26
+ end
27
+
28
+ def test_tag_round_trip
29
+ tag = Tagged.new
30
+ tag2 = Psych.load(Psych.dump(tag))
31
+ assert_equal tag.baz, tag2.baz
32
+ assert_instance_of(Tagged, tag2)
33
+ end
34
+
35
+ def test_cyclic_references
36
+ foo = Foo.new(nil)
37
+ foo.parent = foo
38
+ loaded = Psych.load Psych.dump foo
39
+
40
+ assert_instance_of(Foo, loaded)
41
+ assert_equal loaded, loaded.parent
42
+ end
43
+ end
44
+ end