psych-shopifork 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +15 -0
  2. data/.autotest +18 -0
  3. data/.gemtest +0 -0
  4. data/.travis.yml +9 -0
  5. data/CHANGELOG.rdoc +414 -0
  6. data/Manifest.txt +113 -0
  7. data/README.rdoc +71 -0
  8. data/Rakefile +72 -0
  9. data/ext/psych/depend +3 -0
  10. data/ext/psych/extconf.rb +36 -0
  11. data/ext/psych/psych.c +34 -0
  12. data/ext/psych/psych.h +20 -0
  13. data/ext/psych/psych_emitter.c +538 -0
  14. data/ext/psych/psych_emitter.h +8 -0
  15. data/ext/psych/psych_parser.c +579 -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 +1392 -0
  23. data/ext/psych/yaml/config.h +11 -0
  24. data/ext/psych/yaml/dumper.c +394 -0
  25. data/ext/psych/yaml/emitter.c +2335 -0
  26. data/ext/psych/yaml/loader.c +432 -0
  27. data/ext/psych/yaml/parser.c +1374 -0
  28. data/ext/psych/yaml/reader.c +465 -0
  29. data/ext/psych/yaml/scanner.c +3570 -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 +643 -0
  33. data/lib/psych.rb +497 -0
  34. data/lib/psych/class_loader.rb +101 -0
  35. data/lib/psych/coder.rb +94 -0
  36. data/lib/psych/core_ext.rb +35 -0
  37. data/lib/psych/deprecated.rb +85 -0
  38. data/lib/psych/exception.rb +13 -0
  39. data/lib/psych/handler.rb +249 -0
  40. data/lib/psych/handlers/document_stream.rb +22 -0
  41. data/lib/psych/handlers/recorder.rb +39 -0
  42. data/lib/psych/json/ruby_events.rb +19 -0
  43. data/lib/psych/json/stream.rb +16 -0
  44. data/lib/psych/json/tree_builder.rb +12 -0
  45. data/lib/psych/json/yaml_events.rb +29 -0
  46. data/lib/psych/nodes.rb +77 -0
  47. data/lib/psych/nodes/alias.rb +18 -0
  48. data/lib/psych/nodes/document.rb +60 -0
  49. data/lib/psych/nodes/mapping.rb +56 -0
  50. data/lib/psych/nodes/node.rb +55 -0
  51. data/lib/psych/nodes/scalar.rb +67 -0
  52. data/lib/psych/nodes/sequence.rb +81 -0
  53. data/lib/psych/nodes/stream.rb +37 -0
  54. data/lib/psych/omap.rb +4 -0
  55. data/lib/psych/parser.rb +51 -0
  56. data/lib/psych/scalar_scanner.rb +149 -0
  57. data/lib/psych/set.rb +4 -0
  58. data/lib/psych/stream.rb +37 -0
  59. data/lib/psych/streaming.rb +27 -0
  60. data/lib/psych/syntax_error.rb +21 -0
  61. data/lib/psych/tree_builder.rb +96 -0
  62. data/lib/psych/visitors.rb +6 -0
  63. data/lib/psych/visitors/depth_first.rb +26 -0
  64. data/lib/psych/visitors/emitter.rb +51 -0
  65. data/lib/psych/visitors/json_tree.rb +24 -0
  66. data/lib/psych/visitors/to_ruby.rb +372 -0
  67. data/lib/psych/visitors/visitor.rb +19 -0
  68. data/lib/psych/visitors/yaml_tree.rb +507 -0
  69. data/lib/psych/y.rb +9 -0
  70. data/test/psych/handlers/test_recorder.rb +25 -0
  71. data/test/psych/helper.rb +114 -0
  72. data/test/psych/json/test_stream.rb +109 -0
  73. data/test/psych/nodes/test_enumerable.rb +43 -0
  74. data/test/psych/test_alias_and_anchor.rb +96 -0
  75. data/test/psych/test_array.rb +57 -0
  76. data/test/psych/test_boolean.rb +36 -0
  77. data/test/psych/test_class.rb +36 -0
  78. data/test/psych/test_coder.rb +184 -0
  79. data/test/psych/test_date_time.rb +25 -0
  80. data/test/psych/test_deprecated.rb +214 -0
  81. data/test/psych/test_document.rb +46 -0
  82. data/test/psych/test_emitter.rb +94 -0
  83. data/test/psych/test_encoding.rb +254 -0
  84. data/test/psych/test_engine_manager.rb +47 -0
  85. data/test/psych/test_exception.rb +151 -0
  86. data/test/psych/test_hash.rb +44 -0
  87. data/test/psych/test_json_tree.rb +65 -0
  88. data/test/psych/test_merge_keys.rb +132 -0
  89. data/test/psych/test_nil.rb +18 -0
  90. data/test/psych/test_null.rb +19 -0
  91. data/test/psych/test_numeric.rb +45 -0
  92. data/test/psych/test_object.rb +44 -0
  93. data/test/psych/test_object_references.rb +67 -0
  94. data/test/psych/test_omap.rb +75 -0
  95. data/test/psych/test_parser.rb +339 -0
  96. data/test/psych/test_psych.rb +168 -0
  97. data/test/psych/test_safe_load.rb +97 -0
  98. data/test/psych/test_scalar.rb +11 -0
  99. data/test/psych/test_scalar_scanner.rb +106 -0
  100. data/test/psych/test_serialize_subclasses.rb +38 -0
  101. data/test/psych/test_set.rb +49 -0
  102. data/test/psych/test_stream.rb +93 -0
  103. data/test/psych/test_string.rb +153 -0
  104. data/test/psych/test_struct.rb +49 -0
  105. data/test/psych/test_symbol.rb +17 -0
  106. data/test/psych/test_tainted.rb +130 -0
  107. data/test/psych/test_to_yaml_properties.rb +63 -0
  108. data/test/psych/test_tree_builder.rb +79 -0
  109. data/test/psych/test_yaml.rb +1289 -0
  110. data/test/psych/test_yamldbm.rb +197 -0
  111. data/test/psych/test_yamlstore.rb +87 -0
  112. data/test/psych/visitors/test_depth_first.rb +49 -0
  113. data/test/psych/visitors/test_emitter.rb +144 -0
  114. data/test/psych/visitors/test_to_ruby.rb +326 -0
  115. data/test/psych/visitors/test_yaml_tree.rb +173 -0
  116. metadata +257 -0
@@ -0,0 +1,36 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ ###
5
+ # Test booleans from YAML spec:
6
+ # http://yaml.org/type/bool.html
7
+ class TestBoolean < TestCase
8
+ %w{ yes Yes YES true True TRUE on On ON }.each do |truth|
9
+ define_method(:"test_#{truth}") do
10
+ assert_equal true, Psych.load("--- #{truth}")
11
+ end
12
+ end
13
+
14
+ %w{ no No NO false False FALSE off Off OFF }.each do |truth|
15
+ define_method(:"test_#{truth}") do
16
+ assert_equal false, Psych.load("--- #{truth}")
17
+ end
18
+ end
19
+
20
+ ###
21
+ # YAML spec says "y" and "Y" may be used as true, but Syck treats them
22
+ # as literal strings
23
+ def test_y
24
+ assert_equal "y", Psych.load("--- y")
25
+ assert_equal "Y", Psych.load("--- Y")
26
+ end
27
+
28
+ ###
29
+ # YAML spec says "n" and "N" may be used as false, but Syck treats them
30
+ # as literal strings
31
+ def test_n
32
+ assert_equal "n", Psych.load("--- n")
33
+ assert_equal "N", Psych.load("--- N")
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestClass < TestCase
5
+ module Foo
6
+ end
7
+
8
+ def test_cycle_anonymous_class
9
+ assert_raises(::TypeError) do
10
+ assert_cycle(Class.new)
11
+ end
12
+ end
13
+
14
+ def test_cycle_anonymous_module
15
+ assert_raises(::TypeError) do
16
+ assert_cycle(Module.new)
17
+ end
18
+ end
19
+
20
+ def test_cycle
21
+ assert_cycle(TestClass)
22
+ end
23
+
24
+ def test_dump
25
+ Psych.dump TestClass
26
+ end
27
+
28
+ def test_cycle_module
29
+ assert_cycle(Foo)
30
+ end
31
+
32
+ def test_dump_module
33
+ Psych.dump Foo
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,184 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestCoder < TestCase
5
+ class InitApi
6
+ attr_accessor :implicit
7
+ attr_accessor :style
8
+ attr_accessor :tag
9
+ attr_accessor :a, :b, :c
10
+
11
+ def initialize
12
+ @a = 1
13
+ @b = 2
14
+ @c = 3
15
+ end
16
+
17
+ def init_with coder
18
+ @a = coder['aa']
19
+ @b = coder['bb']
20
+ @implicit = coder.implicit
21
+ @tag = coder.tag
22
+ @style = coder.style
23
+ end
24
+
25
+ def encode_with coder
26
+ coder['aa'] = @a
27
+ coder['bb'] = @b
28
+ end
29
+ end
30
+
31
+ class TaggingCoder < InitApi
32
+ def encode_with coder
33
+ super
34
+ coder.tag = coder.tag.sub(/!/, '!hello')
35
+ coder.implicit = false
36
+ coder.style = Psych::Nodes::Mapping::FLOW
37
+ end
38
+ end
39
+
40
+ class ScalarCoder
41
+ def encode_with coder
42
+ coder.scalar = "foo"
43
+ end
44
+ end
45
+
46
+ class Represent
47
+ yaml_tag 'foo'
48
+ def encode_with coder
49
+ coder.represent_scalar 'foo', 'bar'
50
+ end
51
+ end
52
+
53
+ class RepresentWithInit
54
+ yaml_tag name
55
+ attr_accessor :str
56
+
57
+ def init_with coder
58
+ @str = coder.scalar
59
+ end
60
+
61
+ def encode_with coder
62
+ coder.represent_scalar self.class.name, 'bar'
63
+ end
64
+ end
65
+
66
+ class RepresentWithSeq
67
+ yaml_tag name
68
+ attr_accessor :seq
69
+
70
+ def init_with coder
71
+ @seq = coder.seq
72
+ end
73
+
74
+ def encode_with coder
75
+ coder.represent_seq self.class.name, %w{ foo bar }
76
+ end
77
+ end
78
+
79
+ class RepresentWithMap
80
+ yaml_tag name
81
+ attr_accessor :map
82
+
83
+ def init_with coder
84
+ @map = coder.map
85
+ end
86
+
87
+ def encode_with coder
88
+ coder.represent_map self.class.name, { "string" => 'a', :symbol => 'b' }
89
+ end
90
+ end
91
+
92
+ class RepresentWithObject
93
+ def encode_with coder
94
+ coder.represent_object self.class.name, 20
95
+ end
96
+ end
97
+
98
+ def test_represent_with_object
99
+ thing = Psych.load(Psych.dump(RepresentWithObject.new))
100
+ assert_equal 20, thing
101
+ end
102
+
103
+ def test_json_dump_exclude_tag
104
+ refute_match('TestCoder::InitApi', Psych.to_json(InitApi.new))
105
+ end
106
+
107
+ def test_map_takes_block
108
+ coder = Psych::Coder.new 'foo'
109
+ tag = coder.tag
110
+ style = coder.style
111
+ coder.map { |map| map.add 'foo', 'bar' }
112
+ assert_equal 'bar', coder['foo']
113
+ assert_equal tag, coder.tag
114
+ assert_equal style, coder.style
115
+ end
116
+
117
+ def test_map_with_tag
118
+ coder = Psych::Coder.new 'foo'
119
+ coder.map('hello') { |map| map.add 'foo', 'bar' }
120
+ assert_equal 'bar', coder['foo']
121
+ assert_equal 'hello', coder.tag
122
+ end
123
+
124
+ def test_map_with_tag_and_style
125
+ coder = Psych::Coder.new 'foo'
126
+ coder.map('hello', 'world') { |map| map.add 'foo', 'bar' }
127
+ assert_equal 'bar', coder['foo']
128
+ assert_equal 'hello', coder.tag
129
+ assert_equal 'world', coder.style
130
+ end
131
+
132
+ def test_represent_map
133
+ thing = Psych.load(Psych.dump(RepresentWithMap.new))
134
+ assert_equal({ "string" => 'a', :symbol => 'b' }, thing.map)
135
+ end
136
+
137
+ def test_represent_sequence
138
+ thing = Psych.load(Psych.dump(RepresentWithSeq.new))
139
+ assert_equal %w{ foo bar }, thing.seq
140
+ end
141
+
142
+ def test_represent_with_init
143
+ thing = Psych.load(Psych.dump(RepresentWithInit.new))
144
+ assert_equal 'bar', thing.str
145
+ end
146
+
147
+ def test_represent!
148
+ assert_match(/foo/, Psych.dump(Represent.new))
149
+ assert_instance_of(Represent, Psych.load(Psych.dump(Represent.new)))
150
+ end
151
+
152
+ def test_scalar_coder
153
+ foo = Psych.load(Psych.dump(ScalarCoder.new))
154
+ assert_equal 'foo', foo
155
+ end
156
+
157
+ def test_load_dumped_tagging
158
+ foo = InitApi.new
159
+ bar = Psych.load(Psych.dump(foo))
160
+ assert_equal false, bar.implicit
161
+ assert_equal "!ruby/object:Psych::TestCoder::InitApi", bar.tag
162
+ assert_equal Psych::Nodes::Mapping::BLOCK, bar.style
163
+ end
164
+
165
+ def test_dump_with_tag
166
+ foo = TaggingCoder.new
167
+ assert_match(/hello/, Psych.dump(foo))
168
+ assert_match(/\{aa/, Psych.dump(foo))
169
+ end
170
+
171
+ def test_dump_encode_with
172
+ foo = InitApi.new
173
+ assert_match(/aa/, Psych.dump(foo))
174
+ end
175
+
176
+ def test_dump_init_with
177
+ foo = InitApi.new
178
+ bar = Psych.load(Psych.dump(foo))
179
+ assert_equal foo.a, bar.a
180
+ assert_equal foo.b, bar.b
181
+ assert_nil bar.c
182
+ end
183
+ end
184
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'helper'
2
+ require 'date'
3
+
4
+ module Psych
5
+ class TestDateTime < TestCase
6
+ def test_string_tag
7
+ dt = DateTime.now
8
+ yaml = Psych.dump dt
9
+ assert_match(/DateTime/, yaml)
10
+ end
11
+
12
+ def test_round_trip
13
+ dt = DateTime.now
14
+ assert_cycle dt
15
+ end
16
+
17
+ def test_alias_with_time
18
+ t = Time.now
19
+ h = {:a => t, :b => t}
20
+ yaml = Psych.dump h
21
+ assert_match('&', yaml)
22
+ assert_match('*', yaml)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,214 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestDeprecated < TestCase
5
+ def teardown
6
+ $VERBOSE = @orig_verbose
7
+ Psych.domain_types.clear
8
+ end
9
+
10
+ class QuickEmitter
11
+ attr_reader :name
12
+ attr_reader :value
13
+
14
+ def initialize
15
+ @name = 'hello!!'
16
+ @value = 'Friday!'
17
+ end
18
+
19
+ def to_yaml opts = {}
20
+ Psych.quick_emit object_id, opts do |out|
21
+ out.map taguri, to_yaml_style do |map|
22
+ map.add 'name', @name
23
+ map.add 'value', nil
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def setup
30
+ @qe = QuickEmitter.new
31
+ @orig_verbose, $VERBOSE = $VERBOSE, false
32
+ end
33
+
34
+ def test_quick_emit
35
+ qe2 = Psych.load @qe.to_yaml
36
+ assert_equal @qe.name, qe2.name
37
+ assert_instance_of QuickEmitter, qe2
38
+ assert_nil qe2.value
39
+ end
40
+
41
+ def test_recursive_quick_emit
42
+ hash = { :qe => @qe }
43
+ hash2 = Psych.load Psych.dump hash
44
+ qe = hash2[:qe]
45
+
46
+ assert_equal @qe.name, qe.name
47
+ assert_instance_of QuickEmitter, qe
48
+ assert_nil qe.value
49
+ end
50
+
51
+ class QuickEmitterEncodeWith
52
+ attr_reader :name
53
+ attr_reader :value
54
+
55
+ def initialize
56
+ @name = 'hello!!'
57
+ @value = 'Friday!'
58
+ end
59
+
60
+ def encode_with coder
61
+ coder.map do |map|
62
+ map.add 'name', @name
63
+ map.add 'value', nil
64
+ end
65
+ end
66
+
67
+ def to_yaml opts = {}
68
+ raise
69
+ end
70
+ end
71
+
72
+ ###
73
+ # An object that defines both to_yaml and encode_with should only call
74
+ # encode_with.
75
+ def test_recursive_quick_emit_encode_with
76
+ qeew = QuickEmitterEncodeWith.new
77
+ hash = { :qe => qeew }
78
+ hash2 = Psych.load Psych.dump hash
79
+ qe = hash2[:qe]
80
+
81
+ assert_equal qeew.name, qe.name
82
+ assert_instance_of QuickEmitterEncodeWith, qe
83
+ assert_nil qe.value
84
+ end
85
+
86
+ class YamlInit
87
+ attr_reader :name
88
+ attr_reader :value
89
+
90
+ def initialize
91
+ @name = 'hello!!'
92
+ @value = 'Friday!'
93
+ end
94
+
95
+ def yaml_initialize tag, vals
96
+ vals.each { |ivar, val| instance_variable_set "@#{ivar}", 'TGIF!' }
97
+ end
98
+ end
99
+
100
+ def test_yaml_initialize
101
+ hash = { :yi => YamlInit.new }
102
+ hash2 = Psych.load Psych.dump hash
103
+ yi = hash2[:yi]
104
+
105
+ assert_equal 'TGIF!', yi.name
106
+ assert_equal 'TGIF!', yi.value
107
+ assert_instance_of YamlInit, yi
108
+ end
109
+
110
+ class YamlInitAndInitWith
111
+ attr_reader :name
112
+ attr_reader :value
113
+
114
+ def initialize
115
+ @name = 'shaners'
116
+ @value = 'Friday!'
117
+ end
118
+
119
+ def init_with coder
120
+ coder.map.each { |ivar, val| instance_variable_set "@#{ivar}", 'TGIF!' }
121
+ end
122
+
123
+ def yaml_initialize tag, vals
124
+ raise
125
+ end
126
+ end
127
+
128
+ ###
129
+ # An object that implements both yaml_initialize and init_with should not
130
+ # receive the yaml_initialize call.
131
+ def test_yaml_initialize_and_init_with
132
+ hash = { :yi => YamlInitAndInitWith.new }
133
+ hash2 = Psych.load Psych.dump hash
134
+ yi = hash2[:yi]
135
+
136
+ assert_equal 'TGIF!', yi.name
137
+ assert_equal 'TGIF!', yi.value
138
+ assert_instance_of YamlInitAndInitWith, yi
139
+ end
140
+
141
+ def test_coder_scalar
142
+ coder = Psych::Coder.new 'foo'
143
+ coder.scalar('tag', 'some string', :plain)
144
+ assert_equal 'tag', coder.tag
145
+ assert_equal 'some string', coder.scalar
146
+ assert_equal :scalar, coder.type
147
+ end
148
+
149
+ class YamlAs
150
+ TestCase.suppress_warning do
151
+ psych_yaml_as 'helloworld' # this should be yaml_as but to avoid syck
152
+ end
153
+ end
154
+
155
+ def test_yaml_as
156
+ assert_match(/helloworld/, Psych.dump(YamlAs.new))
157
+ end
158
+
159
+ def test_ruby_type
160
+ types = []
161
+ appender = lambda { |*args| types << args }
162
+
163
+ Psych.add_ruby_type('foo', &appender)
164
+ Psych.load <<-eoyml
165
+ - !ruby.yaml.org,2002/foo bar
166
+ eoyml
167
+
168
+ assert_equal [["tag:ruby.yaml.org,2002:foo", "bar"]], types
169
+ end
170
+
171
+ def test_detect_implicit
172
+ assert_equal '', Psych.detect_implicit(nil)
173
+ assert_equal '', Psych.detect_implicit(Object.new)
174
+ assert_equal '', Psych.detect_implicit(1.2)
175
+ assert_equal 'null', Psych.detect_implicit('')
176
+ assert_equal 'string', Psych.detect_implicit('foo')
177
+ end
178
+
179
+ def test_private_type
180
+ types = []
181
+ Psych.add_private_type('foo') { |*args| types << args }
182
+ Psych.load <<-eoyml
183
+ - !x-private:foo bar
184
+ eoyml
185
+
186
+ assert_equal [["x-private:foo", "bar"]], types
187
+ end
188
+
189
+ def test_tagurize
190
+ assert_nil Psych.tagurize nil
191
+ assert_equal Psych, Psych.tagurize(Psych)
192
+ assert_equal 'tag:yaml.org,2002:foo', Psych.tagurize('foo')
193
+ end
194
+
195
+ def test_read_type_class
196
+ things = Psych.read_type_class 'tag:yaml.org,2002:int:Psych::TestDeprecated::QuickEmitter', Object
197
+ assert_equal 'int', things.first
198
+ assert_equal Psych::TestDeprecated::QuickEmitter, things.last
199
+ end
200
+
201
+ def test_read_type_class_no_class
202
+ things = Psych.read_type_class 'tag:yaml.org,2002:int', Object
203
+ assert_equal 'int', things.first
204
+ assert_equal Object, things.last
205
+ end
206
+
207
+ def test_object_maker
208
+ thing = Psych.object_maker(Object, { 'a' => 'b', 'c' => 'd' })
209
+ assert_instance_of(Object, thing)
210
+ assert_equal 'b', thing.instance_variable_get(:@a)
211
+ assert_equal 'd', thing.instance_variable_get(:@c)
212
+ end
213
+ end
214
+ end