libxml-ruby 2.8.0 → 3.2.3

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 (205) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY +859 -775
  3. data/LICENSE +20 -20
  4. data/MANIFEST +166 -166
  5. data/README.rdoc +217 -184
  6. data/Rakefile +98 -78
  7. data/ext/libxml/extconf.rb +61 -116
  8. data/ext/libxml/libxml.c +80 -76
  9. data/ext/libxml/ruby_libxml.h +67 -75
  10. data/ext/libxml/ruby_xml.c +937 -893
  11. data/ext/libxml/ruby_xml.h +10 -10
  12. data/ext/libxml/ruby_xml_attr.c +333 -333
  13. data/ext/libxml/ruby_xml_attr.h +12 -12
  14. data/ext/libxml/ruby_xml_attr_decl.c +153 -153
  15. data/ext/libxml/ruby_xml_attr_decl.h +11 -11
  16. data/ext/libxml/ruby_xml_attributes.c +275 -275
  17. data/ext/libxml/ruby_xml_attributes.h +15 -15
  18. data/ext/libxml/ruby_xml_cbg.c +85 -85
  19. data/ext/libxml/ruby_xml_document.c +1123 -1147
  20. data/ext/libxml/ruby_xml_document.h +11 -11
  21. data/ext/libxml/ruby_xml_dtd.c +248 -268
  22. data/ext/libxml/ruby_xml_dtd.h +9 -9
  23. data/ext/libxml/ruby_xml_encoding.c +250 -260
  24. data/ext/libxml/ruby_xml_encoding.h +16 -19
  25. data/ext/libxml/ruby_xml_error.c +996 -996
  26. data/ext/libxml/ruby_xml_error.h +12 -12
  27. data/ext/libxml/ruby_xml_html_parser.c +89 -92
  28. data/ext/libxml/ruby_xml_html_parser.h +10 -10
  29. data/ext/libxml/ruby_xml_html_parser_context.c +337 -338
  30. data/ext/libxml/ruby_xml_html_parser_context.h +10 -10
  31. data/ext/libxml/ruby_xml_html_parser_options.c +46 -46
  32. data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
  33. data/ext/libxml/ruby_xml_input_cbg.c +191 -191
  34. data/ext/libxml/ruby_xml_input_cbg.h +20 -20
  35. data/ext/libxml/ruby_xml_io.c +47 -50
  36. data/ext/libxml/ruby_xml_io.h +10 -10
  37. data/ext/libxml/ruby_xml_namespace.c +154 -153
  38. data/ext/libxml/ruby_xml_namespace.h +10 -10
  39. data/ext/libxml/ruby_xml_namespaces.c +293 -293
  40. data/ext/libxml/ruby_xml_namespaces.h +9 -9
  41. data/ext/libxml/ruby_xml_node.c +1406 -1452
  42. data/ext/libxml/ruby_xml_node.h +13 -11
  43. data/ext/libxml/ruby_xml_parser.c +91 -94
  44. data/ext/libxml/ruby_xml_parser.h +12 -12
  45. data/ext/libxml/ruby_xml_parser_context.c +999 -1001
  46. data/ext/libxml/ruby_xml_parser_context.h +10 -10
  47. data/ext/libxml/ruby_xml_parser_options.c +66 -66
  48. data/ext/libxml/ruby_xml_parser_options.h +12 -12
  49. data/ext/libxml/ruby_xml_reader.c +1239 -1228
  50. data/ext/libxml/ruby_xml_reader.h +17 -17
  51. data/ext/libxml/ruby_xml_relaxng.c +110 -111
  52. data/ext/libxml/ruby_xml_relaxng.h +10 -10
  53. data/ext/libxml/ruby_xml_sax2_handler.c +326 -328
  54. data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
  55. data/ext/libxml/ruby_xml_sax_parser.c +116 -120
  56. data/ext/libxml/ruby_xml_sax_parser.h +10 -10
  57. data/ext/libxml/ruby_xml_schema.c +350 -301
  58. data/ext/libxml/ruby_xml_schema.h +806 -809
  59. data/ext/libxml/ruby_xml_schema_attribute.c +61 -109
  60. data/ext/libxml/ruby_xml_schema_attribute.h +15 -15
  61. data/ext/libxml/ruby_xml_schema_element.c +69 -94
  62. data/ext/libxml/ruby_xml_schema_element.h +14 -14
  63. data/ext/libxml/ruby_xml_schema_facet.c +46 -52
  64. data/ext/libxml/ruby_xml_schema_facet.h +13 -13
  65. data/ext/libxml/ruby_xml_schema_type.c +214 -259
  66. data/ext/libxml/ruby_xml_schema_type.h +9 -9
  67. data/ext/libxml/ruby_xml_version.h +9 -9
  68. data/ext/libxml/ruby_xml_writer.c +1133 -1137
  69. data/ext/libxml/ruby_xml_writer.h +10 -10
  70. data/ext/libxml/ruby_xml_xinclude.c +16 -16
  71. data/ext/libxml/ruby_xml_xinclude.h +11 -11
  72. data/ext/libxml/ruby_xml_xpath.c +194 -188
  73. data/ext/libxml/ruby_xml_xpath.h +13 -13
  74. data/ext/libxml/ruby_xml_xpath_context.c +360 -361
  75. data/ext/libxml/ruby_xml_xpath_context.h +9 -9
  76. data/ext/libxml/ruby_xml_xpath_expression.c +81 -81
  77. data/ext/libxml/ruby_xml_xpath_expression.h +10 -10
  78. data/ext/libxml/ruby_xml_xpath_object.c +338 -335
  79. data/ext/libxml/ruby_xml_xpath_object.h +17 -17
  80. data/ext/libxml/ruby_xml_xpointer.c +99 -99
  81. data/ext/libxml/ruby_xml_xpointer.h +11 -11
  82. data/ext/vc/libxml_ruby.sln +17 -15
  83. data/lib/libxml/node.rb +2 -78
  84. data/lib/libxml/parser.rb +0 -266
  85. data/lib/libxml/sax_parser.rb +0 -17
  86. data/lib/libxml/schema/attribute.rb +19 -19
  87. data/lib/libxml/schema/element.rb +19 -27
  88. data/lib/libxml/schema/type.rb +21 -29
  89. data/lib/libxml/schema.rb +47 -66
  90. data/lib/libxml-ruby.rb +30 -0
  91. data/lib/libxml.rb +3 -33
  92. data/libxml-ruby.gemspec +48 -44
  93. data/script/benchmark/depixelate +634 -634
  94. data/script/benchmark/hamlet.xml +9054 -9054
  95. data/script/benchmark/parsecount +170 -170
  96. data/script/benchmark/throughput +41 -41
  97. data/script/test +6 -6
  98. data/setup.rb +0 -1
  99. data/test/c14n/given/example-1.xml +14 -14
  100. data/test/c14n/given/example-2.xml +11 -11
  101. data/test/c14n/given/example-3.xml +18 -18
  102. data/test/c14n/given/example-4.xml +9 -9
  103. data/test/c14n/given/example-5.xml +12 -12
  104. data/test/c14n/given/example-6.xml +2 -2
  105. data/test/c14n/given/example-7.xml +11 -11
  106. data/test/c14n/given/example-8.xml +11 -11
  107. data/test/c14n/given/example-8.xpath +9 -9
  108. data/test/c14n/result/1-1-without-comments/example-1 +3 -3
  109. data/test/c14n/result/1-1-without-comments/example-2 +10 -10
  110. data/test/c14n/result/1-1-without-comments/example-3 +13 -13
  111. data/test/c14n/result/1-1-without-comments/example-4 +8 -8
  112. data/test/c14n/result/1-1-without-comments/example-5 +2 -2
  113. data/test/c14n/result/with-comments/example-1 +5 -5
  114. data/test/c14n/result/with-comments/example-2 +10 -10
  115. data/test/c14n/result/with-comments/example-3 +13 -13
  116. data/test/c14n/result/with-comments/example-4 +8 -8
  117. data/test/c14n/result/with-comments/example-5 +3 -3
  118. data/test/c14n/result/without-comments/example-1 +3 -3
  119. data/test/c14n/result/without-comments/example-2 +10 -10
  120. data/test/c14n/result/without-comments/example-3 +13 -13
  121. data/test/c14n/result/without-comments/example-4 +8 -8
  122. data/test/c14n/result/without-comments/example-5 +2 -2
  123. data/test/model/atom.xml +12 -12
  124. data/test/model/bands.iso-8859-1.xml +4 -4
  125. data/test/model/bands.utf-8.xml +4 -4
  126. data/test/model/bands.xml +4 -4
  127. data/test/model/books.xml +153 -153
  128. data/test/model/cwm_1_0.xml +11336 -0
  129. data/test/model/merge_bug_data.xml +58 -58
  130. data/test/model/ruby-lang.html +238 -238
  131. data/test/model/rubynet.xml +79 -79
  132. data/test/model/shiporder.rnc +28 -28
  133. data/test/model/shiporder.rng +86 -86
  134. data/test/model/shiporder.xml +22 -22
  135. data/test/model/shiporder.xsd +44 -40
  136. data/test/model/shiporder_bad.xsd +40 -0
  137. data/test/model/shiporder_import.xsd +45 -0
  138. data/test/model/soap.xml +27 -27
  139. data/test/model/xinclude.xml +4 -4
  140. data/test/{tc_attr.rb → test_attr.rb} +23 -25
  141. data/test/{tc_attr_decl.rb → test_attr_decl.rb} +13 -14
  142. data/test/{tc_attributes.rb → test_attributes.rb} +11 -18
  143. data/test/{tc_canonicalize.rb → test_canonicalize.rb} +36 -41
  144. data/test/test_deprecated_require.rb +12 -0
  145. data/test/{tc_document.rb → test_document.rb} +33 -27
  146. data/test/test_document_write.rb +146 -0
  147. data/test/{tc_dtd.rb → test_dtd.rb} +29 -29
  148. data/test/{tc_encoding.rb → test_encoding.rb} +129 -126
  149. data/test/{tc_encoding_sax.rb → test_encoding_sax.rb} +7 -6
  150. data/test/test_error.rb +178 -0
  151. data/test/test_helper.rb +4 -9
  152. data/test/test_html_parser.rb +162 -0
  153. data/test/test_html_parser_context.rb +23 -0
  154. data/test/test_namespace.rb +60 -0
  155. data/test/{tc_namespaces.rb → test_namespaces.rb} +34 -44
  156. data/test/{tc_node.rb → test_node.rb} +68 -47
  157. data/test/{tc_node_cdata.rb → test_node_cdata.rb} +12 -13
  158. data/test/{tc_node_comment.rb → test_node_comment.rb} +7 -8
  159. data/test/{tc_node_copy.rb → test_node_copy.rb} +4 -6
  160. data/test/{tc_node_edit.rb → test_node_edit.rb} +23 -41
  161. data/test/{tc_node_pi.rb → test_node_pi.rb} +37 -40
  162. data/test/{tc_node_text.rb → test_node_text.rb} +10 -12
  163. data/test/{tc_node_write.rb → test_node_write.rb} +18 -29
  164. data/test/test_node_xlink.rb +28 -0
  165. data/test/test_parser.rb +324 -0
  166. data/test/{tc_parser_context.rb → test_parser_context.rb} +42 -49
  167. data/test/{tc_properties.rb → test_properties.rb} +6 -7
  168. data/test/test_reader.rb +364 -0
  169. data/test/test_relaxng.rb +53 -0
  170. data/test/{tc_sax_parser.rb → test_sax_parser.rb} +44 -38
  171. data/test/test_schema.rb +231 -0
  172. data/test/test_suite.rb +38 -40
  173. data/test/{tc_traversal.rb → test_traversal.rb} +5 -6
  174. data/test/{tc_writer.rb → test_writer.rb} +468 -448
  175. data/test/{tc_xinclude.rb → test_xinclude.rb} +4 -5
  176. data/test/test_xml.rb +263 -0
  177. data/test/{tc_xpath.rb → test_xpath.rb} +31 -32
  178. data/test/{tc_xpath_context.rb → test_xpath_context.rb} +8 -9
  179. data/test/test_xpath_expression.rb +37 -0
  180. data/test/{tc_xpointer.rb → test_xpointer.rb} +16 -18
  181. metadata +122 -100
  182. data/lib/libxml/ns.rb +0 -22
  183. data/lib/libxml/properties.rb +0 -23
  184. data/lib/libxml/reader.rb +0 -29
  185. data/lib/libxml/xpath_object.rb +0 -16
  186. data/test/etc_doc_to_s.rb +0 -21
  187. data/test/ets_doc_file.rb +0 -17
  188. data/test/ets_doc_to_s.rb +0 -23
  189. data/test/ets_gpx.rb +0 -28
  190. data/test/ets_node_gc.rb +0 -23
  191. data/test/ets_test.xml +0 -2
  192. data/test/ets_tsr.rb +0 -11
  193. data/test/tc_deprecated_require.rb +0 -13
  194. data/test/tc_document_write.rb +0 -196
  195. data/test/tc_error.rb +0 -180
  196. data/test/tc_html_parser.rb +0 -153
  197. data/test/tc_html_parser_context.rb +0 -24
  198. data/test/tc_namespace.rb +0 -62
  199. data/test/tc_node_xlink.rb +0 -29
  200. data/test/tc_parser.rb +0 -381
  201. data/test/tc_reader.rb +0 -400
  202. data/test/tc_relaxng.rb +0 -54
  203. data/test/tc_schema.rb +0 -162
  204. data/test/tc_xml.rb +0 -226
  205. data/test/tc_xpath_expression.rb +0 -38
@@ -0,0 +1,324 @@
1
+ # encoding: UTF-8
2
+
3
+ require_relative './test_helper'
4
+ require 'stringio'
5
+
6
+ class TestParser < Minitest::Test
7
+ def setup
8
+ LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
9
+ end
10
+
11
+ # ----- Sources -------
12
+ def test_document
13
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
14
+ parser = LibXML::XML::Parser.file(file)
15
+ doc = parser.parse
16
+
17
+ parser = LibXML::XML::Parser.document(doc)
18
+
19
+ doc = parser.parse
20
+
21
+ assert_instance_of(LibXML::XML::Document, doc)
22
+ assert_instance_of(LibXML::XML::Parser::Context, parser.context)
23
+ end
24
+
25
+ def test_nil_document
26
+ error = assert_raises(TypeError) do
27
+ LibXML::XML::Parser.document(nil)
28
+ end
29
+
30
+ assert_equal("Must pass an LibXML::XML::Document object", error.to_s)
31
+ end
32
+
33
+ def test_file
34
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
35
+
36
+ parser = LibXML::XML::Parser.file(file)
37
+ doc = parser.parse
38
+ assert_instance_of(LibXML::XML::Document, doc)
39
+ assert_instance_of(LibXML::XML::Parser::Context, parser.context)
40
+ end
41
+
42
+ def test_noexistent_file
43
+ error = assert_raises(LibXML::XML::Error) do
44
+ LibXML::XML::Parser.file('i_dont_exist.xml')
45
+ end
46
+
47
+ assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
48
+ end
49
+
50
+ def test_nil_file
51
+ error = assert_raises(TypeError) do
52
+ LibXML::XML::Parser.file(nil)
53
+ end
54
+
55
+ assert_match(/nil into String/, error.to_s)
56
+ end
57
+
58
+ def test_file_encoding
59
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
60
+ parser = LibXML::XML::Parser.file(file, :encoding => LibXML::XML::Encoding::ISO_8859_1)
61
+
62
+ error = assert_raises(LibXML::XML::Error) do
63
+ parser.parse
64
+ end
65
+
66
+ assert(error.to_s.match(/Fatal error: Extra content at the end of the document/))
67
+
68
+ parser = LibXML::XML::Parser.file(file, :encoding => LibXML::XML::Encoding::UTF_8)
69
+ doc = parser.parse
70
+ refute_nil(doc)
71
+ end
72
+
73
+ def test_file_base_uri
74
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
75
+
76
+ parser = LibXML::XML::Parser.file(file)
77
+ doc = parser.parse
78
+ assert(doc.child.base_uri.match(/test\/model\/bands.utf-8.xml/))
79
+
80
+ parser = LibXML::XML::Parser.file(file, :base_uri => "http://libxml.org")
81
+ doc = parser.parse
82
+ assert(doc.child.base_uri.match(/test\/model\/bands.utf-8.xml/))
83
+ end
84
+
85
+ def test_io
86
+ File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
87
+ parser = LibXML::XML::Parser.io(io)
88
+ assert_instance_of(LibXML::XML::Parser, parser)
89
+
90
+ doc = parser.parse
91
+ assert_instance_of(LibXML::XML::Document, doc)
92
+ assert_instance_of(LibXML::XML::Parser::Context, parser.context)
93
+ end
94
+ end
95
+
96
+ def test_io_gc
97
+ # Test that the reader keeps a reference
98
+ # to the io object
99
+ file = File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
100
+ parser = LibXML::XML::Parser.io(file)
101
+ file = nil
102
+ GC.start
103
+ assert(parser.parse)
104
+ end
105
+
106
+ def test_nil_io
107
+ error = assert_raises(TypeError) do
108
+ LibXML::XML::Parser.io(nil)
109
+ end
110
+
111
+ assert_equal("Must pass in an IO object", error.to_s)
112
+ end
113
+
114
+ def test_string_io
115
+ data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
116
+ string_io = StringIO.new(data)
117
+ parser = LibXML::XML::Parser.io(string_io)
118
+
119
+ doc = parser.parse
120
+ assert_instance_of(LibXML::XML::Document, doc)
121
+ assert_instance_of(LibXML::XML::Parser::Context, parser.context)
122
+ end
123
+
124
+ def test_string_io_thread
125
+ thread = Thread.new do
126
+ data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
127
+ string_io = StringIO.new(data)
128
+ parser = LibXML::XML::Parser.io(string_io)
129
+
130
+ doc = parser.parse
131
+ assert_instance_of(LibXML::XML::Document, doc)
132
+ assert_instance_of(LibXML::XML::Parser::Context, parser.context)
133
+ end
134
+
135
+ thread.join
136
+ assert(true)
137
+ puts 'Thread completed'
138
+ end
139
+
140
+ def test_string
141
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
142
+
143
+ parser = LibXML::XML::Parser.string(str)
144
+ assert_instance_of(LibXML::XML::Parser, parser)
145
+
146
+ doc = parser.parse
147
+ assert_instance_of(LibXML::XML::Document, doc)
148
+ assert_instance_of(LibXML::XML::Parser::Context, parser.context)
149
+ end
150
+
151
+ def test_nil_string
152
+ error = assert_raises(TypeError) do
153
+ LibXML::XML::Parser.string(nil)
154
+ end
155
+
156
+ assert_equal("wrong argument type nil (expected String)", error.to_s)
157
+ end
158
+
159
+ def test_string_options
160
+ xml = <<-EOS
161
+ <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
162
+ <test>
163
+ <cdata><![CDATA[something]]></cdata>
164
+ <entity>&foo;</entity>
165
+ </test>
166
+ EOS
167
+
168
+ LibXML::XML::default_substitute_entities = false
169
+
170
+ # Parse normally
171
+ parser = LibXML::XML::Parser.string(xml)
172
+ doc = parser.parse
173
+ assert_nil(doc.child.base_uri)
174
+
175
+ # Cdata section should be cdata nodes
176
+ node = doc.find_first('/test/cdata').child
177
+ assert_equal(LibXML::XML::Node::CDATA_SECTION_NODE, node.node_type)
178
+
179
+ # Entities should not be subtituted
180
+ node = doc.find_first('/test/entity')
181
+ assert_equal('&foo;', node.child.to_s)
182
+
183
+ # Parse with options
184
+ parser = LibXML::XML::Parser.string(xml, :base_uri => 'http://libxml.rubyforge.org',
185
+ :options => LibXML::XML::Parser::Options::NOCDATA | LibXML::XML::Parser::Options::NOENT)
186
+ doc = parser.parse
187
+ assert_equal(doc.child.base_uri, 'http://libxml.rubyforge.org')
188
+
189
+ # Cdata section should be text nodes
190
+ node = doc.find_first('/test/cdata').child
191
+ assert_equal(LibXML::XML::Node::TEXT_NODE, node.node_type)
192
+
193
+ # Entities should be subtituted
194
+ node = doc.find_first('/test/entity')
195
+ assert_equal('bar', node.child.to_s)
196
+ end
197
+
198
+ def test_string_encoding
199
+ # ISO_8859_1:
200
+ # ö - f6 in hex, \366 in octal
201
+ # ü - fc in hex, \374 in octal
202
+
203
+ xml = <<-EOS
204
+ <bands>
205
+ <metal>m\366tley_cr\374e</metal>
206
+ </bands>
207
+ EOS
208
+
209
+ # Parse as UTF_8
210
+ parser = LibXML::XML::Parser.string(xml, :encoding => LibXML::XML::Encoding::UTF_8)
211
+
212
+ error = assert_raises(LibXML::XML::Error) do
213
+ parser.parse
214
+ end
215
+
216
+ assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
217
+ error.to_s)
218
+
219
+ # Parse as ISO_8859_1:
220
+ parser = LibXML::XML::Parser.string(xml, :encoding => LibXML::XML::Encoding::ISO_8859_1)
221
+ doc = parser.parse
222
+ node = doc.find_first('//metal')
223
+ assert_equal(Encoding::UTF_8, node.content.encoding)
224
+ assert_equal("m\303\266tley_cr\303\274e", node.content)
225
+ end
226
+
227
+ def test_fd_gc
228
+ # Test opening # of documents up to the file limit for the OS.
229
+ # Ideally it should run until libxml emits a warning,
230
+ # thereby knowing we've done a GC sweep. For the time being,
231
+ # re-open the same doc `limit descriptors` times.
232
+ # If we make it to the end, then we've succeeded,
233
+ # otherwise an exception will be thrown.
234
+ LibXML::XML::Error.set_handler {|error|}
235
+
236
+ max_fd = if RUBY_PLATFORM.match(/mswin32|mswin64|mingw/i)
237
+ 500
238
+ else
239
+ Process.getrlimit(Process::RLIMIT_NOFILE)[0] + 1
240
+ end
241
+
242
+ file = File.join(File.dirname(__FILE__), 'model/rubynet.xml')
243
+ max_fd.times do
244
+ LibXML::XML::Parser.file(file).parse
245
+ end
246
+ LibXML::XML::Error.reset_handler {|error|}
247
+ end
248
+
249
+ def test_open_many_files
250
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/atom.xml'))
251
+ 1000.times do
252
+ LibXML::XML::Parser.file(file).parse
253
+ end
254
+ end
255
+
256
+ # ----- Errors ------
257
+ def test_error
258
+ error = assert_raises(LibXML::XML::Error) do
259
+ LibXML::XML::Parser.string('<foo><bar/></foz>').parse
260
+ end
261
+
262
+ refute_nil(error)
263
+ assert_kind_of(LibXML::XML::Error, error)
264
+ assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", error.message)
265
+ assert_equal(LibXML::XML::Error::PARSER, error.domain)
266
+ assert_equal(LibXML::XML::Error::TAG_NAME_MISMATCH, error.code)
267
+ assert_equal(LibXML::XML::Error::FATAL, error.level)
268
+ assert_nil(error.file)
269
+ assert_equal(1, error.line)
270
+ assert_equal('foo', error.str1)
271
+ assert_equal('foz', error.str2)
272
+ assert_nil(error.str3)
273
+ assert_equal(1, error.int1)
274
+ assert([18, 20].include?(error.int2))
275
+ assert_nil(error.node)
276
+ end
277
+
278
+ def test_bad_xml
279
+ parser = LibXML::XML::Parser.string('<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
280
+ error = assert_raises(LibXML::XML::Error) do
281
+ refute_nil(parser.parse)
282
+ end
283
+
284
+ refute_nil(error)
285
+ assert_kind_of(LibXML::XML::Error, error)
286
+ assert_equal("Fatal error: Extra content at the end of the document at :1.", error.message)
287
+ assert_equal(LibXML::XML::Error::PARSER, error.domain)
288
+ assert_equal(LibXML::XML::Error::DOCUMENT_END, error.code)
289
+ assert_equal(LibXML::XML::Error::FATAL, error.level)
290
+ assert_nil(error.file)
291
+ assert_equal(1, error.line)
292
+ assert_nil(error.str1)
293
+ assert_nil(error.str2)
294
+ assert_nil(error.str3)
295
+ assert_equal(0, error.int1)
296
+ assert_equal(34, error.int2)
297
+ assert_nil(error.node)
298
+ end
299
+
300
+ def test_errors_from_background_thread
301
+ errors = []
302
+ background_errors = []
303
+
304
+ begin
305
+ LibXML::XML::Error.set_handler do |error|
306
+ errors << error
307
+ end
308
+ parser = LibXML::XML::Parser.string("<moo>")
309
+
310
+ thread = Thread.new do
311
+ LibXML::XML::Error.set_handler do |error|
312
+ background_errors << error
313
+ end
314
+ parser.parse rescue nil
315
+ end
316
+ thread.join
317
+ ensure
318
+ LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
319
+ end
320
+
321
+ assert_equal(errors.size, 0)
322
+ assert_equal(background_errors.size, 1)
323
+ end
324
+ end
@@ -1,10 +1,9 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require './test_helper'
3
+ require_relative './test_helper'
4
4
 
5
- require 'test/unit'
6
5
 
7
- class TestParserContext < Test::Unit::TestCase
6
+ class TestParserContext < Minitest::Test
8
7
  def test_string
9
8
  # UTF8
10
9
  xml = <<-EOS
@@ -13,9 +12,9 @@ class TestParserContext < Test::Unit::TestCase
13
12
  </bands>
14
13
  EOS
15
14
 
16
- context = XML::Parser::Context.string(xml)
17
- assert_instance_of(XML::Parser::Context, context)
18
- assert_equal(XML::Encoding::NONE, context.encoding)
15
+ context = LibXML::XML::Parser::Context.string(xml)
16
+ assert_instance_of(LibXML::XML::Parser::Context, context)
17
+ assert_equal(LibXML::XML::Encoding::NONE, context.encoding)
19
18
  assert_nil(context.base_uri)
20
19
  end
21
20
 
@@ -27,11 +26,11 @@ class TestParserContext < Test::Unit::TestCase
27
26
  </bands>
28
27
  EOS
29
28
 
30
- context = XML::Parser::Context.string(xml)
31
- assert_equal(XML::Encoding::NONE, context.encoding)
29
+ context = LibXML::XML::Parser::Context.string(xml)
30
+ assert_equal(LibXML::XML::Encoding::NONE, context.encoding)
32
31
 
33
- context.encoding = XML::Encoding::ISO_8859_1
34
- assert_equal(XML::Encoding::ISO_8859_1, context.encoding)
32
+ context.encoding = LibXML::XML::Encoding::ISO_8859_1
33
+ assert_equal(LibXML::XML::Encoding::ISO_8859_1, context.encoding)
35
34
  end
36
35
 
37
36
  def test_invalid_encoding
@@ -42,9 +41,9 @@ class TestParserContext < Test::Unit::TestCase
42
41
  </bands>
43
42
  EOS
44
43
 
45
- context = XML::Parser::Context.string(xml)
44
+ context = LibXML::XML::Parser::Context.string(xml)
46
45
 
47
- error = assert_raise(ArgumentError) do
46
+ error = assert_raises(ArgumentError) do
48
47
  context.encoding = -999
49
48
  end
50
49
  assert_equal("Unknown encoding: -999", error.to_s)
@@ -58,7 +57,7 @@ class TestParserContext < Test::Unit::TestCase
58
57
  </bands>
59
58
  EOS
60
59
 
61
- context = XML::Parser::Context.string(xml)
60
+ context = LibXML::XML::Parser::Context.string(xml)
62
61
  assert_nil(context.base_uri)
63
62
 
64
63
  context.base_uri = 'http://libxml.rubyforge.org'
@@ -66,26 +65,26 @@ class TestParserContext < Test::Unit::TestCase
66
65
  end
67
66
 
68
67
  def test_string_empty
69
- error = assert_raise(TypeError) do
70
- XML::Parser::Context.string(nil)
68
+ error = assert_raises(TypeError) do
69
+ LibXML::XML::Parser::Context.string(nil)
71
70
  end
72
71
  assert_equal("wrong argument type nil (expected String)", error.to_s)
73
72
 
74
- error = assert_raise(ArgumentError) do
75
- XML::Parser::Context.string('')
73
+ error = assert_raises(ArgumentError) do
74
+ LibXML::XML::Parser::Context.string('')
76
75
  end
77
76
  assert_equal("Must specify a string with one or more characters", error.to_s)
78
77
  end
79
78
 
80
79
  def test_well_formed
81
- parser = XML::Parser.string("<abc/>")
80
+ parser = LibXML::XML::Parser.string("<abc/>")
82
81
  parser.parse
83
82
  assert(parser.context.well_formed?)
84
83
  end
85
84
 
86
85
  def test_not_well_formed
87
- parser = XML::Parser.string("<abc>")
88
- assert_raise(XML::Error) do
86
+ parser = LibXML::XML::Parser.string("<abc>")
87
+ assert_raises(LibXML::XML::Error) do
89
88
  parser.parse
90
89
  end
91
90
  assert(!parser.context.well_formed?)
@@ -93,34 +92,34 @@ class TestParserContext < Test::Unit::TestCase
93
92
 
94
93
  def test_version_info
95
94
  file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
96
- parser = XML::Parser.file(file)
95
+ parser = LibXML::XML::Parser.file(file)
97
96
  assert_nil(parser.context.version)
98
97
  parser.parse
99
98
  assert_equal("1.0", parser.context.version)
100
99
  end
101
100
 
102
101
  def test_depth
103
- context = XML::Parser::Context.new
104
- assert_instance_of(Fixnum, context.depth)
102
+ context = LibXML::XML::Parser::Context.new
103
+ assert_instance_of(Integer, context.depth)
105
104
  end
106
105
 
107
106
  def test_disable_sax
108
- context = XML::Parser::Context.new
107
+ context = LibXML::XML::Parser::Context.new
109
108
  assert(!context.disable_sax?)
110
109
  end
111
110
 
112
111
  def test_docbook
113
- context = XML::Parser::Context.new
112
+ context = LibXML::XML::Parser::Context.new
114
113
  assert(!context.docbook?)
115
114
  end
116
115
 
117
116
  def test_html
118
- context = XML::Parser::Context.new
117
+ context = LibXML::XML::Parser::Context.new
119
118
  assert(!context.html?)
120
119
  end
121
120
 
122
121
  def test_keep_blanks
123
- context = XML::Parser::Context.new
122
+ context = LibXML::XML::Parser::Context.new
124
123
  if context.keep_blanks?
125
124
  assert_instance_of(TrueClass, context.keep_blanks?)
126
125
  else
@@ -128,18 +127,12 @@ class TestParserContext < Test::Unit::TestCase
128
127
  end
129
128
  end
130
129
 
131
- if ENV['NOTWORKING']
132
- def test_num_chars
133
- assert_equal(17, context.num_chars)
134
- end
135
- end
136
-
137
130
  def test_replace_entities
138
- context = XML::Parser::Context.new
131
+ context = LibXML::XML::Parser::Context.new
139
132
  assert(!context.replace_entities?)
140
133
 
141
- # context.options = 1
142
- # assert(context.replace_entities?)
134
+ context.options = LibXML::XML::Parser::Options::NOENT
135
+ assert(context.replace_entities?)
143
136
 
144
137
  context.options = 0
145
138
  assert(!context.replace_entities?)
@@ -149,52 +142,52 @@ class TestParserContext < Test::Unit::TestCase
149
142
  end
150
143
 
151
144
  def test_space_depth
152
- context = XML::Parser::Context.new
145
+ context = LibXML::XML::Parser::Context.new
153
146
  assert_equal(1, context.space_depth)
154
147
  end
155
148
 
156
149
  def test_subset_external
157
- context = XML::Parser::Context.new
150
+ context = LibXML::XML::Parser::Context.new
158
151
  assert(!context.subset_external?)
159
152
  end
160
153
 
161
154
  def test_data_directory_get
162
- context = XML::Parser::Context.new
155
+ context = LibXML::XML::Parser::Context.new
163
156
  assert_nil(context.data_directory)
164
157
  end
165
158
 
166
159
  def test_parse_error
167
- xp = XML::Parser.string('<foo><bar/></foz>')
160
+ xp = LibXML::XML::Parser.string('<foo><bar/></foz>')
168
161
 
169
- assert_raise(XML::Error) do
162
+ assert_raises(LibXML::XML::Error) do
170
163
  xp.parse
171
164
  end
172
165
 
173
166
  # Now check context
174
167
  context = xp.context
175
- assert_equal(nil, context.data_directory)
168
+ assert_nil(context.data_directory)
176
169
  assert_equal(0, context.depth)
177
170
  assert_equal(true, context.disable_sax?)
178
171
  assert_equal(false, context.docbook?)
179
- assert_equal(XML::Encoding::NONE, context.encoding)
172
+ assert_equal(LibXML::XML::Encoding::NONE, context.encoding)
180
173
  assert_equal(76, context.errno)
181
174
  assert_equal(false, context.html?)
182
175
  assert_equal(5, context.io_max_num_streams)
183
176
  assert_equal(1, context.io_num_streams)
184
177
  assert_equal(true, context.keep_blanks?)
185
178
  assert_equal(1, context.io_num_streams)
186
- assert_equal(nil, context.name_node)
179
+ assert_nil(context.name_node)
187
180
  assert_equal(0, context.name_depth)
188
181
  assert_equal(10, context.name_depth_max)
189
- assert_equal(17, context.num_chars)
182
+ assert([0, 17].include?(context.num_chars))
190
183
  assert_equal(false, context.replace_entities?)
191
184
  assert_equal(1, context.space_depth)
192
185
  assert_equal(10, context.space_depth_max)
193
186
  assert_equal(false, context.subset_external?)
194
- assert_equal(nil, context.subset_external_system_id)
195
- assert_equal(nil, context.subset_external_uri)
187
+ assert_nil(context.subset_external_system_id)
188
+ assert_nil(context.subset_external_uri)
196
189
  assert_equal(false, context.subset_internal?)
197
- assert_equal(nil, context.subset_internal_name)
190
+ assert_nil(context.subset_internal_name)
198
191
  assert_equal(false, context.stats?)
199
192
  assert_equal(true, context.standalone?)
200
193
  assert_equal(false, context.valid)
@@ -202,4 +195,4 @@ class TestParserContext < Test::Unit::TestCase
202
195
  assert_equal('1.0', context.version)
203
196
  assert_equal(false, context.well_formed?)
204
197
  end
205
- end
198
+ end
@@ -1,15 +1,14 @@
1
1
  # encoding: UTF-8
2
2
 
3
- require './test_helper'
3
+ require_relative './test_helper'
4
4
 
5
- require 'test/unit'
6
5
 
7
6
  # attributes is deprecated - use attributes instead.
8
7
  # Tests for backwards compatibility
9
8
 
10
- class Testattributes < Test::Unit::TestCase
9
+ class Testattributes < Minitest::Test
11
10
  def setup()
12
- xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
11
+ xp = LibXML::XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
13
12
  @doc = xp.parse
14
13
  end
15
14
 
@@ -20,20 +19,20 @@ class Testattributes < Test::Unit::TestCase
20
19
  def test_traversal
21
20
  attributes = @doc.root.attributes
22
21
 
23
- assert_instance_of(XML::Attributes, attributes)
22
+ assert_instance_of(LibXML::XML::Attributes, attributes)
24
23
  attribute = attributes.first
25
24
  assert_equal('uga', attribute.name)
26
25
  assert_equal('booga', attribute.value)
27
26
 
28
27
  attribute = attribute.next
29
- assert_instance_of(XML::Attr, attribute)
28
+ assert_instance_of(LibXML::XML::Attr, attribute)
30
29
  assert_equal('foo', attribute.name)
31
30
  assert_equal('bar', attribute.value)
32
31
  end
33
32
 
34
33
  def test_no_attributes
35
34
  attributes = @doc.root.child.attributes
36
- assert_instance_of(XML::Attributes, attributes)
35
+ assert_instance_of(LibXML::XML::Attributes, attributes)
37
36
  assert_equal(0, attributes.length)
38
37
  end
39
38
  end