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,46 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestDocument < TestCase
5
+ def setup
6
+ super
7
+ @stream = Psych.parse_stream(<<-eoyml)
8
+ %YAML 1.1
9
+ %TAG ! tag:tenderlovemaking.com,2009:
10
+ --- !fun
11
+ eoyml
12
+ @doc = @stream.children.first
13
+ end
14
+
15
+ def test_parse_tag
16
+ assert_equal([['!', 'tag:tenderlovemaking.com,2009:']],
17
+ @doc.tag_directives)
18
+ end
19
+
20
+ def test_emit_tag
21
+ assert_match('%TAG ! tag:tenderlovemaking.com,2009:', @stream.yaml)
22
+ end
23
+
24
+ def test_emit_multitag
25
+ @doc.tag_directives << ['!!', 'foo.com,2009:']
26
+ yaml = @stream.yaml
27
+ assert_match('%TAG ! tag:tenderlovemaking.com,2009:', yaml)
28
+ assert_match('%TAG !! foo.com,2009:', yaml)
29
+ end
30
+
31
+ def test_emit_bad_tag
32
+ assert_raises(RuntimeError) do
33
+ @doc.tag_directives = [['!']]
34
+ @stream.yaml
35
+ end
36
+ end
37
+
38
+ def test_parse_version
39
+ assert_equal([1,1], @doc.version)
40
+ end
41
+
42
+ def test_emit_version
43
+ assert_match('%YAML 1.1', @stream.yaml)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,94 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require_relative 'helper'
4
+
5
+ module Psych
6
+ class TestEmitter < TestCase
7
+ def setup
8
+ super
9
+ @out = StringIO.new('')
10
+ @emitter = Psych::Emitter.new @out
11
+ end
12
+
13
+ def test_line_width
14
+ assert_equal 0, @emitter.line_width
15
+ assert_equal 10, @emitter.line_width = 10
16
+ assert_equal 10, @emitter.line_width
17
+ end
18
+
19
+ def test_set_canonical
20
+ @emitter.canonical = true
21
+ assert_equal true, @emitter.canonical
22
+
23
+ @emitter.canonical = false
24
+ assert_equal false, @emitter.canonical
25
+ end
26
+
27
+ def test_indentation_set
28
+ assert_equal 2, @emitter.indentation
29
+ @emitter.indentation = 5
30
+ assert_equal 5, @emitter.indentation
31
+ end
32
+
33
+ def test_emit_utf_8
34
+ @emitter.start_stream Psych::Nodes::Stream::UTF8
35
+ @emitter.start_document [], [], false
36
+ @emitter.scalar '日本語', nil, nil, false, true, 1
37
+ @emitter.end_document true
38
+ @emitter.end_stream
39
+ assert_match('日本語', @out.string)
40
+ end
41
+
42
+ def test_start_stream_arg_error
43
+ assert_raises(TypeError) do
44
+ @emitter.start_stream 'asdfasdf'
45
+ end
46
+ end
47
+
48
+ def test_start_doc_arg_error
49
+ @emitter.start_stream Psych::Nodes::Stream::UTF8
50
+
51
+ [
52
+ [nil, [], false],
53
+ [[nil, nil], [], false],
54
+ [[], 'foo', false],
55
+ [[], ['foo'], false],
56
+ [[], [nil,nil], false],
57
+ ].each do |args|
58
+ assert_raises(TypeError) do
59
+ @emitter.start_document(*args)
60
+ end
61
+ end
62
+ end
63
+
64
+ def test_scalar_arg_error
65
+ @emitter.start_stream Psych::Nodes::Stream::UTF8
66
+ @emitter.start_document [], [], false
67
+
68
+ [
69
+ [:foo, nil, nil, false, true, 1],
70
+ ['foo', Object.new, nil, false, true, 1],
71
+ ['foo', nil, Object.new, false, true, 1],
72
+ ['foo', nil, nil, false, true, :foo],
73
+ [nil, nil, nil, false, true, 1],
74
+ ].each do |args|
75
+ assert_raises(TypeError) do
76
+ @emitter.scalar(*args)
77
+ end
78
+ end
79
+ end
80
+
81
+ def test_start_sequence_arg_error
82
+ @emitter.start_stream Psych::Nodes::Stream::UTF8
83
+ @emitter.start_document [], [], false
84
+
85
+ assert_raises(TypeError) do
86
+ @emitter.start_sequence(nil, Object.new, true, 1)
87
+ end
88
+
89
+ assert_raises(TypeError) do
90
+ @emitter.start_sequence(nil, nil, true, :foo)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,254 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require_relative 'helper'
4
+
5
+ module Psych
6
+ class TestEncoding < TestCase
7
+ class EncodingCatcher < Handler
8
+ attr_reader :strings
9
+ def initialize
10
+ @strings = []
11
+ end
12
+
13
+ (Handler.instance_methods(true) -
14
+ Object.instance_methods).each do |m|
15
+ class_eval %{
16
+ def #{m} *args
17
+ @strings += args.flatten.find_all { |a|
18
+ String === a
19
+ }
20
+ end
21
+ }
22
+ end
23
+ end
24
+
25
+ def setup
26
+ super
27
+ @buffer = StringIO.new
28
+ @handler = EncodingCatcher.new
29
+ @parser = Psych::Parser.new @handler
30
+ @utf8 = Encoding.find('UTF-8')
31
+ @emitter = Psych::Emitter.new @buffer
32
+ end
33
+
34
+ def test_transcode_shiftjis
35
+ str = "こんにちは!"
36
+ loaded = Psych.load("--- こんにちは!".encode('SHIFT_JIS'))
37
+ assert_equal str, loaded
38
+ end
39
+
40
+ def test_transcode_utf16le
41
+ str = "こんにちは!"
42
+ loaded = Psych.load("--- こんにちは!".encode('UTF-16LE'))
43
+ assert_equal str, loaded
44
+ end
45
+
46
+ def test_transcode_utf16be
47
+ str = "こんにちは!"
48
+ loaded = Psych.load("--- こんにちは!".encode('UTF-16BE'))
49
+ assert_equal str, loaded
50
+ end
51
+
52
+ def test_io_shiftjis
53
+ Tempfile.create(['shiftjis', 'yml'], :encoding => 'SHIFT_JIS') {|t|
54
+ t.write '--- こんにちは!'
55
+ t.close
56
+
57
+ # If the external encoding isn't utf8, utf16le, or utf16be, we cannot
58
+ # process the file.
59
+ File.open(t.path, 'r', :encoding => 'SHIFT_JIS') do |f|
60
+ assert_raises Psych::SyntaxError do
61
+ Psych.load(f)
62
+ end
63
+ end
64
+ }
65
+ end
66
+
67
+ def test_io_utf16le
68
+ Tempfile.create(['utf16le', 'yml']) {|t|
69
+ t.binmode
70
+ t.write '--- こんにちは!'.encode('UTF-16LE')
71
+ t.close
72
+
73
+ File.open(t.path, 'rb', :encoding => 'UTF-16LE') do |f|
74
+ assert_equal "こんにちは!", Psych.load(f)
75
+ end
76
+ }
77
+ end
78
+
79
+ def test_io_utf16be
80
+ Tempfile.create(['utf16be', 'yml']) {|t|
81
+ t.binmode
82
+ t.write '--- こんにちは!'.encode('UTF-16BE')
83
+ t.close
84
+
85
+ File.open(t.path, 'rb', :encoding => 'UTF-16BE') do |f|
86
+ assert_equal "こんにちは!", Psych.load(f)
87
+ end
88
+ }
89
+ end
90
+
91
+ def test_io_utf8
92
+ Tempfile.create(['utf8', 'yml']) {|t|
93
+ t.binmode
94
+ t.write '--- こんにちは!'.encode('UTF-8')
95
+ t.close
96
+
97
+ File.open(t.path, 'rb', :encoding => 'UTF-8') do |f|
98
+ assert_equal "こんにちは!", Psych.load(f)
99
+ end
100
+ }
101
+ end
102
+
103
+ def test_emit_alias
104
+ @emitter.start_stream Psych::Parser::UTF8
105
+ @emitter.start_document [], [], true
106
+ e = assert_raises(RuntimeError) do
107
+ @emitter.alias 'ドラえもん'.encode('EUC-JP')
108
+ end
109
+ assert_match(/alias value/, e.message)
110
+ end
111
+
112
+ def test_to_yaml_is_valid
113
+ with_default_external(Encoding::US_ASCII) do
114
+ with_default_internal(nil) do
115
+ s = "こんにちは!"
116
+ # If no encoding is specified, use UTF-8
117
+ assert_equal Encoding::UTF_8, Psych.dump(s).encoding
118
+ assert_equal s, Psych.load(Psych.dump(s))
119
+ end
120
+ end
121
+ end
122
+
123
+ def test_start_mapping
124
+ foo = 'foo'
125
+ bar = 'バー'
126
+
127
+ @emitter.start_stream Psych::Parser::UTF8
128
+ @emitter.start_document [], [], true
129
+ @emitter.start_mapping(
130
+ foo.encode('Shift_JIS'),
131
+ bar.encode('UTF-16LE'),
132
+ false, Nodes::Sequence::ANY)
133
+ @emitter.end_mapping
134
+ @emitter.end_document false
135
+ @emitter.end_stream
136
+
137
+ @parser.parse @buffer.string
138
+ assert_encodings @utf8, @handler.strings
139
+ assert_equal [foo, bar], @handler.strings
140
+ end
141
+
142
+ def test_start_sequence
143
+ foo = 'foo'
144
+ bar = 'バー'
145
+
146
+ @emitter.start_stream Psych::Parser::UTF8
147
+ @emitter.start_document [], [], true
148
+ @emitter.start_sequence(
149
+ foo.encode('Shift_JIS'),
150
+ bar.encode('UTF-16LE'),
151
+ false, Nodes::Sequence::ANY)
152
+ @emitter.end_sequence
153
+ @emitter.end_document false
154
+ @emitter.end_stream
155
+
156
+ @parser.parse @buffer.string
157
+ assert_encodings @utf8, @handler.strings
158
+ assert_equal [foo, bar], @handler.strings
159
+ end
160
+
161
+ def test_doc_tag_encoding
162
+ key = '鍵'
163
+ @emitter.start_stream Psych::Parser::UTF8
164
+ @emitter.start_document(
165
+ [1, 1],
166
+ [['!'.encode('EUC-JP'), key.encode('EUC-JP')]],
167
+ true
168
+ )
169
+ @emitter.scalar 'foo', nil, nil, true, false, Nodes::Scalar::ANY
170
+ @emitter.end_document false
171
+ @emitter.end_stream
172
+
173
+ @parser.parse @buffer.string
174
+ assert_encodings @utf8, @handler.strings
175
+ assert_equal key, @handler.strings[1]
176
+ end
177
+
178
+ def test_emitter_encoding
179
+ str = "壁に耳あり、障子に目あり"
180
+ thing = Psych.load Psych.dump str.encode('EUC-JP')
181
+ assert_equal str, thing
182
+ end
183
+
184
+ def test_default_internal
185
+ with_default_internal(Encoding::EUC_JP) do
186
+ str = "壁に耳あり、障子に目あり"
187
+ assert_equal @utf8, str.encoding
188
+
189
+ @parser.parse str
190
+ assert_encodings Encoding::EUC_JP, @handler.strings
191
+ assert_equal str, @handler.strings.first.encode('UTF-8')
192
+ end
193
+ end
194
+
195
+ def test_scalar
196
+ @parser.parse("--- a")
197
+ assert_encodings @utf8, @handler.strings
198
+ end
199
+
200
+ def test_alias
201
+ @parser.parse(<<-eoyml)
202
+ %YAML 1.1
203
+ ---
204
+ !!seq [
205
+ !!str "Without properties",
206
+ &A !!str "Anchored",
207
+ !!str "Tagged",
208
+ *A,
209
+ !!str "",
210
+ ]
211
+ eoyml
212
+ assert_encodings @utf8, @handler.strings
213
+ end
214
+
215
+ def test_list_anchor
216
+ list = %w{ a b }
217
+ list << list
218
+ @parser.parse(Psych.dump(list))
219
+ assert_encodings @utf8, @handler.strings
220
+ end
221
+
222
+ def test_map_anchor
223
+ h = {}
224
+ h['a'] = h
225
+ @parser.parse(Psych.dump(h))
226
+ assert_encodings @utf8, @handler.strings
227
+ end
228
+
229
+ def test_map_tag
230
+ @parser.parse(<<-eoyml)
231
+ %YAML 1.1
232
+ ---
233
+ !!map { a : b }
234
+ eoyml
235
+ assert_encodings @utf8, @handler.strings
236
+ end
237
+
238
+ def test_doc_tag
239
+ @parser.parse(<<-eoyml)
240
+ %YAML 1.1
241
+ %TAG ! tag:tenderlovemaking.com,2009:
242
+ --- !fun
243
+ eoyml
244
+ assert_encodings @utf8, @handler.strings
245
+ end
246
+
247
+ private
248
+ def assert_encodings encoding, strings
249
+ strings.each do |str|
250
+ assert_equal encoding, str.encoding, str
251
+ end
252
+ end
253
+ end
254
+ end
@@ -0,0 +1,47 @@
1
+ require_relative 'helper'
2
+ require 'yaml'
3
+
4
+ module Psych
5
+ class TestEngineManager < TestCase
6
+ def test_bad_engine
7
+ assert_raises(ArgumentError) do
8
+ YAML::ENGINE.yamler = 'foooo'
9
+ end
10
+ end
11
+
12
+ def test_set_psych
13
+ YAML::ENGINE.yamler = 'psych'
14
+ assert_equal Psych, YAML
15
+ assert_equal 'psych', YAML::ENGINE.yamler
16
+ end
17
+
18
+ A = Struct.new(:name)
19
+
20
+ def test_dump_types
21
+ YAML::ENGINE.yamler = 'psych'
22
+
23
+ assert_to_yaml ::Object.new
24
+ assert_to_yaml Time.now
25
+ assert_to_yaml Date.today
26
+ assert_to_yaml('a' => 'b')
27
+ assert_to_yaml A.new('foo')
28
+ assert_to_yaml %w{a b}
29
+ assert_to_yaml Exception.new('foo')
30
+ assert_to_yaml "hello!"
31
+ assert_to_yaml :fooo
32
+ assert_to_yaml(1..10)
33
+ assert_to_yaml(/hello!~/)
34
+ assert_to_yaml 1
35
+ assert_to_yaml 1.2
36
+ assert_to_yaml Rational(1, 2)
37
+ assert_to_yaml Complex(1, 2)
38
+ assert_to_yaml true
39
+ assert_to_yaml false
40
+ assert_to_yaml nil
41
+ end
42
+
43
+ def assert_to_yaml obj
44
+ assert obj.to_yaml, "#{obj.class} to_yaml works"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,151 @@
1
+ require_relative 'helper'
2
+
3
+ module Psych
4
+ class TestException < TestCase
5
+ class Wups < Exception
6
+ attr_reader :foo, :bar
7
+ def initialize *args
8
+ super
9
+ @foo = 1
10
+ @bar = 2
11
+ end
12
+ end
13
+
14
+ def setup
15
+ super
16
+ @wups = Wups.new
17
+ end
18
+
19
+ def test_load_takes_file
20
+ ex = assert_raises(Psych::SyntaxError) do
21
+ Psych.load '--- `'
22
+ end
23
+ assert_nil ex.file
24
+
25
+ ex = assert_raises(Psych::SyntaxError) do
26
+ Psych.load '--- `', 'meow'
27
+ end
28
+ assert_equal 'meow', ex.file
29
+ end
30
+
31
+ def test_psych_parse_stream_takes_file
32
+ ex = assert_raises(Psych::SyntaxError) do
33
+ Psych.parse_stream '--- `'
34
+ end
35
+ assert_nil ex.file
36
+ assert_match '(<unknown>)', ex.message
37
+
38
+ ex = assert_raises(Psych::SyntaxError) do
39
+ Psych.parse_stream '--- `', 'omg!'
40
+ end
41
+ assert_equal 'omg!', ex.file
42
+ assert_match 'omg!', ex.message
43
+ end
44
+
45
+ def test_load_stream_takes_file
46
+ ex = assert_raises(Psych::SyntaxError) do
47
+ Psych.load_stream '--- `'
48
+ end
49
+ assert_nil ex.file
50
+ assert_match '(<unknown>)', ex.message
51
+
52
+ ex = assert_raises(Psych::SyntaxError) do
53
+ Psych.load_stream '--- `', 'omg!'
54
+ end
55
+ assert_equal 'omg!', ex.file
56
+ end
57
+
58
+ def test_parse_file_exception
59
+ Tempfile.create(['parsefile', 'yml']) {|t|
60
+ t.binmode
61
+ t.write '--- `'
62
+ t.close
63
+ ex = assert_raises(Psych::SyntaxError) do
64
+ Psych.parse_file t.path
65
+ end
66
+ assert_equal t.path, ex.file
67
+ }
68
+ end
69
+
70
+ def test_load_file_exception
71
+ Tempfile.create(['loadfile', 'yml']) {|t|
72
+ t.binmode
73
+ t.write '--- `'
74
+ t.close
75
+ ex = assert_raises(Psych::SyntaxError) do
76
+ Psych.load_file t.path
77
+ end
78
+ assert_equal t.path, ex.file
79
+ }
80
+ end
81
+
82
+ def test_psych_parse_takes_file
83
+ ex = assert_raises(Psych::SyntaxError) do
84
+ Psych.parse '--- `'
85
+ end
86
+ assert_match '(<unknown>)', ex.message
87
+ assert_nil ex.file
88
+
89
+ ex = assert_raises(Psych::SyntaxError) do
90
+ Psych.parse '--- `', 'omg!'
91
+ end
92
+ assert_match 'omg!', ex.message
93
+ end
94
+
95
+ def test_attributes
96
+ e = assert_raises(Psych::SyntaxError) {
97
+ Psych.load '--- `foo'
98
+ }
99
+
100
+ assert_nil e.file
101
+ assert_equal 1, e.line
102
+ assert_equal 5, e.column
103
+ # FIXME: offset isn't being set correctly by libyaml
104
+ # assert_equal 5, e.offset
105
+
106
+ assert e.problem
107
+ assert e.context
108
+ end
109
+
110
+ def test_convert
111
+ w = Psych.load(Psych.dump(@wups))
112
+ assert_equal @wups, w
113
+ assert_equal 1, w.foo
114
+ assert_equal 2, w.bar
115
+ end
116
+
117
+ def test_to_yaml_properties
118
+ class << @wups
119
+ def to_yaml_properties
120
+ [:@foo]
121
+ end
122
+ end
123
+
124
+ w = Psych.load(Psych.dump(@wups))
125
+ assert_equal @wups, w
126
+ assert_equal 1, w.foo
127
+ assert_nil w.bar
128
+ end
129
+
130
+ def test_psych_syntax_error
131
+ Tempfile.create(['parsefile', 'yml']) do |t|
132
+ t.binmode
133
+ t.write '--- `'
134
+ t.close
135
+
136
+ begin
137
+ Psych.parse_file t.path
138
+ rescue StandardError
139
+ assert true # count assertion
140
+ ensure
141
+ return unless $!
142
+
143
+ ancestors = $!.class.ancestors.inspect
144
+
145
+ flunk "Psych::SyntaxError not rescued by StandardError: #{ancestors}"
146
+ end
147
+ end
148
+ end
149
+
150
+ end
151
+ end