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