libxml-ruby 2.7.0 → 2.9.0
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.
- checksums.yaml +6 -14
- data/HISTORY +33 -11
- data/README.rdoc +7 -7
- data/Rakefile +80 -77
- data/ext/libxml/extconf.h +4 -5
- data/ext/libxml/extconf.rb +57 -118
- data/ext/libxml/libxml.c +4 -0
- data/ext/libxml/ruby_xml.c +977 -893
- data/ext/libxml/ruby_xml.h +20 -10
- data/ext/libxml/ruby_xml_attr.c +333 -333
- data/ext/libxml/ruby_xml_attr_decl.c +2 -2
- data/ext/libxml/ruby_xml_cbg.c +85 -85
- data/ext/libxml/ruby_xml_document.c +1133 -1147
- data/ext/libxml/ruby_xml_dtd.c +261 -268
- data/ext/libxml/ruby_xml_encoding.c +262 -260
- data/ext/libxml/ruby_xml_encoding.h +19 -19
- data/ext/libxml/ruby_xml_html_parser_context.c +337 -338
- data/ext/libxml/ruby_xml_input_cbg.c +191 -191
- data/ext/libxml/ruby_xml_io.c +52 -50
- data/ext/libxml/ruby_xml_namespace.c +2 -2
- data/ext/libxml/ruby_xml_node.c +1446 -1452
- data/ext/libxml/ruby_xml_parser_context.c +999 -1001
- data/ext/libxml/ruby_xml_reader.c +1226 -1228
- data/ext/libxml/ruby_xml_relaxng.c +110 -111
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -328
- data/ext/libxml/ruby_xml_schema.c +300 -301
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/ext/libxml/ruby_xml_writer.c +34 -16
- data/ext/libxml/ruby_xml_xpath.c +188 -187
- data/ext/libxml/ruby_xml_xpath_context.c +360 -361
- data/ext/libxml/ruby_xml_xpath_object.c +335 -335
- data/libxml-ruby.gemspec +47 -44
- data/test/tc_attr.rb +5 -7
- data/test/tc_attr_decl.rb +5 -6
- data/test/tc_attributes.rb +1 -2
- data/test/tc_canonicalize.rb +1 -2
- data/test/tc_deprecated_require.rb +1 -2
- data/test/tc_document.rb +4 -5
- data/test/tc_document_write.rb +2 -3
- data/test/tc_dtd.rb +4 -5
- data/test/tc_encoding.rb +126 -126
- data/test/tc_encoding_sax.rb +4 -3
- data/test/tc_error.rb +14 -15
- data/test/tc_html_parser.rb +15 -7
- data/test/tc_html_parser_context.rb +1 -2
- data/test/tc_namespace.rb +2 -3
- data/test/tc_namespaces.rb +5 -6
- data/test/tc_node.rb +2 -3
- data/test/tc_node_cdata.rb +2 -3
- data/test/tc_node_comment.rb +1 -2
- data/test/tc_node_copy.rb +1 -2
- data/test/tc_node_edit.rb +5 -7
- data/test/tc_node_pi.rb +1 -2
- data/test/tc_node_text.rb +2 -3
- data/test/tc_node_write.rb +2 -3
- data/test/tc_node_xlink.rb +1 -2
- data/test/tc_parser.rb +18 -24
- data/test/tc_parser_context.rb +6 -7
- data/test/tc_properties.rb +1 -2
- data/test/tc_reader.rb +9 -10
- data/test/tc_relaxng.rb +4 -5
- data/test/tc_sax_parser.rb +9 -10
- data/test/tc_schema.rb +4 -5
- data/test/tc_traversal.rb +1 -2
- data/test/tc_writer.rb +1 -2
- data/test/tc_xinclude.rb +1 -2
- data/test/tc_xml.rb +1 -2
- data/test/tc_xpath.rb +8 -9
- data/test/tc_xpath_context.rb +3 -4
- data/test/tc_xpath_expression.rb +3 -4
- data/test/tc_xpointer.rb +1 -3
- data/test/test_helper.rb +3 -1
- data/test/test_suite.rb +0 -1
- metadata +90 -72
- data/test/etc_doc_to_s.rb +0 -21
- data/test/ets_doc_file.rb +0 -17
- data/test/ets_doc_to_s.rb +0 -23
- data/test/ets_gpx.rb +0 -28
- data/test/ets_node_gc.rb +0 -23
- data/test/ets_test.xml +0 -2
- data/test/ets_tsr.rb +0 -11
- data/test/model/kml_sample.xml +0 -915
- data/test/remove_test.rb +0 -9
- data/test/tc_gc.rb +0 -86
- data/test/tc_parser.rb.orig +0 -384
data/test/tc_error.rb
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require './test_helper'
|
4
|
-
require 'test/unit'
|
5
4
|
require 'stringio'
|
6
5
|
|
7
|
-
class TestError < Test
|
6
|
+
class TestError < Minitest::Test
|
8
7
|
def test_error_codes
|
9
8
|
assert_equal(4, XML::Error::DTD)
|
10
9
|
assert_equal(4, XML::Error.const_get('DTD'))
|
@@ -14,7 +13,7 @@ class TestError < Test::Unit::TestCase
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def test_invalid_handler
|
17
|
-
|
16
|
+
assert_raises(RuntimeError) do
|
18
17
|
XML::Error.set_handler
|
19
18
|
end
|
20
19
|
end
|
@@ -26,13 +25,13 @@ class TestError < Test::Unit::TestCase
|
|
26
25
|
end
|
27
26
|
|
28
27
|
# Raise the error
|
29
|
-
error =
|
28
|
+
error = assert_raises(XML::Error) do
|
30
29
|
XML::Reader.string('<foo').read
|
31
30
|
end
|
32
31
|
assert_equal(exception, error)
|
33
32
|
|
34
33
|
# Check the handler worked
|
35
|
-
|
34
|
+
refute_nil(exception)
|
36
35
|
assert_kind_of(XML::Error, exception)
|
37
36
|
assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", exception.message)
|
38
37
|
assert_equal(XML::Error::PARSER, exception.domain)
|
@@ -65,7 +64,7 @@ class TestError < Test::Unit::TestCase
|
|
65
64
|
|
66
65
|
saved_handler = XML::Error.get_handler
|
67
66
|
XML::Error.set_handler{ puts "New handler" }
|
68
|
-
|
67
|
+
refute_equal(XML::Error.get_handler, saved_handler)
|
69
68
|
|
70
69
|
XML::Error.set_handler(&saved_handler)
|
71
70
|
assert_equal(XML::Error.get_handler, saved_handler)
|
@@ -78,7 +77,7 @@ class TestError < Test::Unit::TestCase
|
|
78
77
|
|
79
78
|
Object.const_set(:STDERR, output)
|
80
79
|
begin
|
81
|
-
|
80
|
+
assert_raises(XML::Error) do
|
82
81
|
XML::Parser.string('<foo><bar/></foz>').parse
|
83
82
|
end
|
84
83
|
ensure
|
@@ -94,7 +93,7 @@ class TestError < Test::Unit::TestCase
|
|
94
93
|
|
95
94
|
Object.const_set(:STDERR, output)
|
96
95
|
begin
|
97
|
-
|
96
|
+
assert_raises(XML::Error) do
|
98
97
|
XML::Parser.string('<foo><bar/></foz>').parse
|
99
98
|
end
|
100
99
|
ensure
|
@@ -104,7 +103,7 @@ class TestError < Test::Unit::TestCase
|
|
104
103
|
end
|
105
104
|
|
106
105
|
def test_parse_error
|
107
|
-
exception =
|
106
|
+
exception = assert_raises(XML::Error) do
|
108
107
|
XML::Parser.string('<foo><bar/></foz>').parse
|
109
108
|
end
|
110
109
|
|
@@ -120,7 +119,7 @@ class TestError < Test::Unit::TestCase
|
|
120
119
|
def test_xpath_error
|
121
120
|
doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
|
122
121
|
|
123
|
-
exception =
|
122
|
+
exception = assert_raises(XML::Error) do
|
124
123
|
doc.find('/foo[bar=test')
|
125
124
|
end
|
126
125
|
|
@@ -138,7 +137,7 @@ class TestError < Test::Unit::TestCase
|
|
138
137
|
parser = XML::Parser.string("<test>something</test>")
|
139
138
|
parser.parse
|
140
139
|
|
141
|
-
error =
|
140
|
+
error = assert_raises(XML::Error) do
|
142
141
|
# Try parsing a second time
|
143
142
|
parser.parse
|
144
143
|
end
|
@@ -149,19 +148,19 @@ class TestError < Test::Unit::TestCase
|
|
149
148
|
def test_libxml_parser_empty_string
|
150
149
|
xp = XML::Parser.new
|
151
150
|
|
152
|
-
error =
|
151
|
+
error = assert_raises(TypeError) do
|
153
152
|
xp.string = nil
|
154
153
|
end
|
155
154
|
assert_equal('wrong argument type nil (expected String)', error.to_s)
|
156
155
|
|
157
|
-
error =
|
156
|
+
error = assert_raises(ArgumentError) do
|
158
157
|
xp.string = ''
|
159
158
|
end
|
160
159
|
assert_equal('Must specify a string with one or more characters', error.to_s)
|
161
160
|
end
|
162
161
|
|
163
162
|
def test_error_domain_to_s
|
164
|
-
exception =
|
163
|
+
exception = assert_raises(XML::Error) do
|
165
164
|
XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
|
166
165
|
end
|
167
166
|
|
@@ -170,7 +169,7 @@ class TestError < Test::Unit::TestCase
|
|
170
169
|
end
|
171
170
|
|
172
171
|
def test_error_code_to_s
|
173
|
-
exception =
|
172
|
+
exception = assert_raises(XML::Error) do
|
174
173
|
XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
|
175
174
|
end
|
176
175
|
assert_equal(XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code)
|
data/test/tc_html_parser.rb
CHANGED
@@ -2,9 +2,8 @@
|
|
2
2
|
|
3
3
|
require './test_helper'
|
4
4
|
require 'stringio'
|
5
|
-
require 'test/unit'
|
6
5
|
|
7
|
-
class HTMLParserTest < Test
|
6
|
+
class HTMLParserTest < Minitest::Test
|
8
7
|
def html_file
|
9
8
|
File.expand_path(File.join(File.dirname(__FILE__), 'model/ruby-lang.html'))
|
10
9
|
end
|
@@ -14,11 +13,11 @@ class HTMLParserTest < Test::Unit::TestCase
|
|
14
13
|
xp = XML::HTMLParser.file(html_file)
|
15
14
|
assert_instance_of(XML::HTMLParser, xp)
|
16
15
|
doc = xp.parse
|
17
|
-
|
16
|
+
refute_nil(doc)
|
18
17
|
end
|
19
18
|
|
20
19
|
def test_noexistent_file
|
21
|
-
error =
|
20
|
+
error = assert_raises(XML::Error) do
|
22
21
|
XML::HTMLParser.file('i_dont_exist.xml')
|
23
22
|
end
|
24
23
|
|
@@ -26,7 +25,7 @@ class HTMLParserTest < Test::Unit::TestCase
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def test_nil_file
|
29
|
-
error =
|
28
|
+
error = assert_raises(TypeError) do
|
30
29
|
XML::HTMLParser.file(nil)
|
31
30
|
end
|
32
31
|
|
@@ -54,7 +53,7 @@ class HTMLParserTest < Test::Unit::TestCase
|
|
54
53
|
end
|
55
54
|
|
56
55
|
def test_nil_io
|
57
|
-
error =
|
56
|
+
error = assert_raises(TypeError) do
|
58
57
|
XML::HTMLParser.io(nil)
|
59
58
|
end
|
60
59
|
|
@@ -83,7 +82,7 @@ class HTMLParserTest < Test::Unit::TestCase
|
|
83
82
|
end
|
84
83
|
|
85
84
|
def test_nil_string
|
86
|
-
error =
|
85
|
+
error = assert_raises(TypeError) do
|
87
86
|
XML::HTMLParser.string(nil)
|
88
87
|
end
|
89
88
|
|
@@ -145,6 +144,15 @@ class HTMLParserTest < Test::Unit::TestCase
|
|
145
144
|
assert_equal("<p>#{html}</p>", doc.root.to_s)
|
146
145
|
end
|
147
146
|
|
147
|
+
def test_comment
|
148
|
+
doc = LibXML::XML::HTMLParser.string('<!-- stuff -->', :options => LibXML::XML::HTMLParser::Options::NOIMPLIED |
|
149
|
+
LibXML::XML::HTMLParser::Options::NOERROR |
|
150
|
+
LibXML::XML::HTMLParser::Options::NOWARNING |
|
151
|
+
LibXML::XML::HTMLParser::Options::RECOVER |
|
152
|
+
LibXML::XML::HTMLParser::Options::NONET)
|
153
|
+
assert(doc)
|
154
|
+
end
|
155
|
+
|
148
156
|
def test_open_many_files
|
149
157
|
1000.times do
|
150
158
|
doc = XML::HTMLParser.file('model/ruby-lang.html').parse
|
data/test/tc_namespace.rb
CHANGED
@@ -2,9 +2,8 @@
|
|
2
2
|
|
3
3
|
require './test_helper'
|
4
4
|
|
5
|
-
require 'test/unit'
|
6
5
|
|
7
|
-
class TestNS < Test
|
6
|
+
class TestNS < Minitest::Test
|
8
7
|
def setup
|
9
8
|
file = File.join(File.dirname(__FILE__), 'model/soap.xml')
|
10
9
|
@doc = XML::Document.file(file)
|
@@ -29,7 +28,7 @@ class TestNS < Test::Unit::TestCase
|
|
29
28
|
end
|
30
29
|
|
31
30
|
def test_create_unbound_ns
|
32
|
-
error =
|
31
|
+
error = assert_raises(TypeError) do
|
33
32
|
XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com')
|
34
33
|
end
|
35
34
|
assert_equal('wrong argument type nil (expected Data)', error.to_s)
|
data/test/tc_namespaces.rb
CHANGED
@@ -2,9 +2,8 @@
|
|
2
2
|
|
3
3
|
require './test_helper'
|
4
4
|
|
5
|
-
require 'test/unit'
|
6
5
|
|
7
|
-
class TestNamespaces < Test
|
6
|
+
class TestNamespaces < Minitest::Test
|
8
7
|
def setup
|
9
8
|
file = File.join(File.dirname(__FILE__), 'model/soap.xml')
|
10
9
|
@doc = XML::Document.file(file)
|
@@ -38,7 +37,7 @@ class TestNamespaces < Test::Unit::TestCase
|
|
38
37
|
|
39
38
|
# Now put the node in the soap namespace
|
40
39
|
node.namespaces.namespace = ns
|
41
|
-
|
40
|
+
refute_nil(node.namespaces.namespace)
|
42
41
|
assert_equal("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
43
42
|
end
|
44
43
|
|
@@ -60,13 +59,13 @@ class TestNamespaces < Test::Unit::TestCase
|
|
60
59
|
|
61
60
|
# Now put the node in the soap namespace
|
62
61
|
node.namespaces.namespace = ns
|
63
|
-
|
62
|
+
refute_nil(node.namespaces.namespace)
|
64
63
|
assert_equal('<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://www.w3.org/2001/12/soap-encoding"/>',
|
65
64
|
node.to_s)
|
66
65
|
|
67
66
|
# Now put the attribute in the soap namespace
|
68
67
|
attr.namespaces.namespace = ns
|
69
|
-
|
68
|
+
refute_nil(node.namespaces.namespace)
|
70
69
|
assert_equal('<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"/>',
|
71
70
|
node.to_s)
|
72
71
|
end
|
@@ -205,6 +204,6 @@ class TestNamespaces < Test::Unit::TestCase
|
|
205
204
|
doc.root.namespaces.default_prefix = 'soap'
|
206
205
|
|
207
206
|
node = doc.root.find_first('/soap:Envelope')
|
208
|
-
|
207
|
+
refute_nil(node)
|
209
208
|
end
|
210
209
|
end
|
data/test/tc_node.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require './test_helper'
|
4
|
-
require 'test/unit'
|
5
4
|
|
6
|
-
class TestNode < Test
|
5
|
+
class TestNode < Minitest::Test
|
7
6
|
def setup
|
8
7
|
@file_name = "model/bands.utf-8.xml"
|
9
8
|
|
@@ -112,7 +111,7 @@ class TestNode < Test::Unit::TestCase
|
|
112
111
|
def test_equality_wrong_type
|
113
112
|
node = @doc.root
|
114
113
|
|
115
|
-
|
114
|
+
assert_raises(TypeError) do
|
116
115
|
assert(node != 'abc')
|
117
116
|
end
|
118
117
|
end
|
data/test/tc_node_cdata.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require './test_helper'
|
4
|
-
require 'test/unit'
|
5
4
|
|
6
|
-
class CDataCommentTest < Test
|
5
|
+
class CDataCommentTest < Minitest::Test
|
7
6
|
def setup
|
8
7
|
xp = XML::Parser.string('<root></root>')
|
9
8
|
@doc = xp.parse
|
@@ -44,7 +43,7 @@ class CDataCommentTest < Test::Unit::TestCase
|
|
44
43
|
cnode = XML::Node.new_cdata('test cdata')
|
45
44
|
|
46
45
|
# Can't create attributes on non-element nodes
|
47
|
-
|
46
|
+
assert_raises(ArgumentError) do
|
48
47
|
cnode['attr'] = '123'
|
49
48
|
end
|
50
49
|
end
|
data/test/tc_node_comment.rb
CHANGED
data/test/tc_node_copy.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require './test_helper'
|
4
|
-
require 'test/unit'
|
5
4
|
|
6
5
|
# see mailing list archive
|
7
6
|
# [libxml-devel] Segmentation fault when add the cloned/copied node
|
8
7
|
# 2007/11/27 20:51
|
9
8
|
|
10
|
-
class TestNodeCopy < Test
|
9
|
+
class TestNodeCopy < Minitest::Test
|
11
10
|
def setup
|
12
11
|
str = <<-STR
|
13
12
|
<html><body>
|
data/test/tc_node_edit.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require './test_helper'
|
4
|
-
require 'test/unit'
|
5
4
|
|
6
|
-
class TestNodeEdit < Test
|
5
|
+
class TestNodeEdit < Minitest::Test
|
7
6
|
def setup
|
8
7
|
xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
9
8
|
@doc = xp.parse
|
@@ -76,7 +75,7 @@ class TestNodeEdit < Test::Unit::TestCase
|
|
76
75
|
a.parent.remove!
|
77
76
|
|
78
77
|
# Node a has now been freed from under us
|
79
|
-
error =
|
78
|
+
error = assert_raises(RuntimeError) do
|
80
79
|
a.to_s
|
81
80
|
end
|
82
81
|
assert_equal('This node has already been freed.', error.to_s)
|
@@ -88,7 +87,7 @@ class TestNodeEdit < Test::Unit::TestCase
|
|
88
87
|
node = doc.root.child.remove!
|
89
88
|
node = nil
|
90
89
|
GC.start
|
91
|
-
|
90
|
+
refute_nil(doc)
|
92
91
|
end
|
93
92
|
|
94
93
|
def test_remove_node_iteration
|
@@ -105,7 +104,7 @@ class TestNodeEdit < Test::Unit::TestCase
|
|
105
104
|
def test_reuse_removed_node
|
106
105
|
# Remove the node
|
107
106
|
node = @doc.root.first.remove!
|
108
|
-
|
107
|
+
refute_nil(node)
|
109
108
|
|
110
109
|
# Add it to the end of the document
|
111
110
|
@doc.root.last.next = node
|
@@ -124,13 +123,12 @@ class TestNodeEdit < Test::Unit::TestCase
|
|
124
123
|
end
|
125
124
|
|
126
125
|
def test_wrong_doc
|
127
|
-
puts 333333
|
128
126
|
doc1 = XML::Parser.string('<nums><one></one></nums>').parse
|
129
127
|
doc2 = XML::Parser.string('<nums><two></two></nums>').parse
|
130
128
|
|
131
129
|
node = doc1.root.child
|
132
130
|
|
133
|
-
error =
|
131
|
+
error = assert_raises(XML::Error) do
|
134
132
|
doc2.root << node
|
135
133
|
end
|
136
134
|
|
data/test/tc_node_pi.rb
CHANGED
data/test/tc_node_text.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require './test_helper'
|
4
|
-
require 'test/unit'
|
5
4
|
|
6
|
-
class TestTextNode < Test
|
5
|
+
class TestTextNode < Minitest::Test
|
7
6
|
def test_content
|
8
7
|
node = XML::Node.new_text('testdata')
|
9
8
|
assert_instance_of(XML::Node, node)
|
@@ -11,7 +10,7 @@ class TestTextNode < Test::Unit::TestCase
|
|
11
10
|
end
|
12
11
|
|
13
12
|
def test_invalid_content
|
14
|
-
error =
|
13
|
+
error = assert_raises(TypeError) do
|
15
14
|
node = XML::Node.new_text(nil)
|
16
15
|
end
|
17
16
|
assert_equal('wrong argument type nil (expected String)', error.to_s)
|
data/test/tc_node_write.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require './test_helper'
|
4
|
-
require 'test/unit'
|
5
4
|
|
6
|
-
class TestNodeWrite < Test
|
5
|
+
class TestNodeWrite < Minitest::Test
|
7
6
|
def setup
|
8
7
|
load_encoding("utf-8")
|
9
8
|
end
|
@@ -81,7 +80,7 @@ class TestNodeWrite < Test::Unit::TestCase
|
|
81
80
|
end
|
82
81
|
|
83
82
|
# Invalid encoding
|
84
|
-
error =
|
83
|
+
error = assert_raises(ArgumentError) do
|
85
84
|
node.to_s(:encoding => -9999)
|
86
85
|
end
|
87
86
|
assert_equal('Unknown encoding value: -9999', error.to_s)
|
data/test/tc_node_xlink.rb
CHANGED
@@ -3,9 +3,8 @@
|
|
3
3
|
# $Id$
|
4
4
|
require './test_helper'
|
5
5
|
|
6
|
-
require 'test/unit'
|
7
6
|
|
8
|
-
class TC_XML_Node_XLink < Test
|
7
|
+
class TC_XML_Node_XLink < Minitest::Test
|
9
8
|
def setup()
|
10
9
|
xp = XML::Parser.string('<ruby_array xmlns:xlink="http://www.w3.org/1999/xlink/namespace/"><fixnum xlink:type="simple">one</fixnum></ruby_array>')
|
11
10
|
doc = xp.parse
|
data/test/tc_parser.rb
CHANGED
@@ -1,20 +1,13 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require './test_helper'
|
4
|
-
require 'test/unit'
|
5
4
|
require 'stringio'
|
6
5
|
|
7
|
-
class TestParser < Test
|
6
|
+
class TestParser < Minitest::Test
|
8
7
|
def setup
|
9
8
|
XML::Error.set_handler(&XML::Error::QUIET_HANDLER)
|
10
9
|
end
|
11
10
|
|
12
|
-
def teardown
|
13
|
-
GC.start
|
14
|
-
GC.start
|
15
|
-
GC.start
|
16
|
-
end
|
17
|
-
|
18
11
|
# ----- Sources -------
|
19
12
|
def test_document
|
20
13
|
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
|
@@ -30,7 +23,7 @@ class TestParser < Test::Unit::TestCase
|
|
30
23
|
end
|
31
24
|
|
32
25
|
def test_nil_document
|
33
|
-
error =
|
26
|
+
error = assert_raises(TypeError) do
|
34
27
|
XML::Parser.document(nil)
|
35
28
|
end
|
36
29
|
|
@@ -47,7 +40,7 @@ class TestParser < Test::Unit::TestCase
|
|
47
40
|
end
|
48
41
|
|
49
42
|
def test_noexistent_file
|
50
|
-
error =
|
43
|
+
error = assert_raises(XML::Error) do
|
51
44
|
XML::Parser.file('i_dont_exist.xml')
|
52
45
|
end
|
53
46
|
|
@@ -55,7 +48,7 @@ class TestParser < Test::Unit::TestCase
|
|
55
48
|
end
|
56
49
|
|
57
50
|
def test_nil_file
|
58
|
-
error =
|
51
|
+
error = assert_raises(TypeError) do
|
59
52
|
XML::Parser.file(nil)
|
60
53
|
end
|
61
54
|
|
@@ -66,7 +59,7 @@ class TestParser < Test::Unit::TestCase
|
|
66
59
|
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
|
67
60
|
parser = XML::Parser.file(file, :encoding => XML::Encoding::ISO_8859_1)
|
68
61
|
|
69
|
-
error =
|
62
|
+
error = assert_raises(XML::Error) do
|
70
63
|
doc = parser.parse
|
71
64
|
end
|
72
65
|
|
@@ -74,7 +67,7 @@ class TestParser < Test::Unit::TestCase
|
|
74
67
|
|
75
68
|
parser = XML::Parser.file(file, :encoding => XML::Encoding::UTF_8)
|
76
69
|
doc = parser.parse
|
77
|
-
|
70
|
+
refute_nil(doc)
|
78
71
|
end
|
79
72
|
|
80
73
|
def test_file_base_uri
|
@@ -111,7 +104,7 @@ class TestParser < Test::Unit::TestCase
|
|
111
104
|
end
|
112
105
|
|
113
106
|
def test_nil_io
|
114
|
-
error =
|
107
|
+
error = assert_raises(TypeError) do
|
115
108
|
XML::Parser.io(nil)
|
116
109
|
end
|
117
110
|
|
@@ -141,8 +134,9 @@ class TestParser < Test::Unit::TestCase
|
|
141
134
|
|
142
135
|
thread.join
|
143
136
|
assert(true)
|
137
|
+
puts 'Thread completed'
|
144
138
|
end
|
145
|
-
|
139
|
+
|
146
140
|
def test_string
|
147
141
|
str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
148
142
|
|
@@ -155,7 +149,7 @@ class TestParser < Test::Unit::TestCase
|
|
155
149
|
end
|
156
150
|
|
157
151
|
def test_nil_string
|
158
|
-
error =
|
152
|
+
error = assert_raises(TypeError) do
|
159
153
|
XML::Parser.string(nil)
|
160
154
|
end
|
161
155
|
|
@@ -215,7 +209,7 @@ class TestParser < Test::Unit::TestCase
|
|
215
209
|
# Parse as UTF_8
|
216
210
|
parser = XML::Parser.string(xml, :encoding => XML::Encoding::UTF_8)
|
217
211
|
|
218
|
-
error =
|
212
|
+
error = assert_raises(XML::Error) do
|
219
213
|
doc = parser.parse
|
220
214
|
end
|
221
215
|
|
@@ -246,7 +240,7 @@ class TestParser < Test::Unit::TestCase
|
|
246
240
|
max_fd = if RUBY_PLATFORM.match(/mswin32|mingw/i)
|
247
241
|
500
|
248
242
|
else
|
249
|
-
(
|
243
|
+
Process.getrlimit(Process::RLIMIT_NOFILE)[0] + 1
|
250
244
|
end
|
251
245
|
|
252
246
|
file = File.join(File.dirname(__FILE__), 'model/rubynet.xml')
|
@@ -264,11 +258,11 @@ class TestParser < Test::Unit::TestCase
|
|
264
258
|
|
265
259
|
# ----- Errors ------
|
266
260
|
def test_error
|
267
|
-
error =
|
261
|
+
error = assert_raises(XML::Error) do
|
268
262
|
XML::Parser.string('<foo><bar/></foz>').parse
|
269
263
|
end
|
270
264
|
|
271
|
-
|
265
|
+
refute_nil(error)
|
272
266
|
assert_kind_of(XML::Error, error)
|
273
267
|
assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", error.message)
|
274
268
|
assert_equal(XML::Error::PARSER, error.domain)
|
@@ -286,11 +280,11 @@ class TestParser < Test::Unit::TestCase
|
|
286
280
|
|
287
281
|
def test_bad_xml
|
288
282
|
parser = XML::Parser.string('<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
|
289
|
-
error =
|
290
|
-
|
283
|
+
error = assert_raises(XML::Error) do
|
284
|
+
refute_nil(parser.parse)
|
291
285
|
end
|
292
286
|
|
293
|
-
|
287
|
+
refute_nil(error)
|
294
288
|
assert_kind_of(XML::Error, error)
|
295
289
|
assert_equal("Fatal error: Extra content at the end of the document at :1.", error.message)
|
296
290
|
assert_equal(XML::Error::PARSER, error.domain)
|
@@ -302,7 +296,7 @@ class TestParser < Test::Unit::TestCase
|
|
302
296
|
assert_nil(error.str2)
|
303
297
|
assert_nil(error.str3)
|
304
298
|
assert_equal(0, error.int1)
|
305
|
-
assert_equal(
|
299
|
+
assert_equal(34, error.int2)
|
306
300
|
assert_nil(error.node)
|
307
301
|
end
|
308
302
|
|
data/test/tc_parser_context.rb
CHANGED
@@ -2,9 +2,8 @@
|
|
2
2
|
|
3
3
|
require './test_helper'
|
4
4
|
|
5
|
-
require 'test/unit'
|
6
5
|
|
7
|
-
class TestParserContext < Test
|
6
|
+
class TestParserContext < Minitest::Test
|
8
7
|
def test_string
|
9
8
|
# UTF8
|
10
9
|
xml = <<-EOS
|
@@ -44,7 +43,7 @@ class TestParserContext < Test::Unit::TestCase
|
|
44
43
|
|
45
44
|
context = XML::Parser::Context.string(xml)
|
46
45
|
|
47
|
-
error =
|
46
|
+
error = assert_raises(ArgumentError) do
|
48
47
|
context.encoding = -999
|
49
48
|
end
|
50
49
|
assert_equal("Unknown encoding: -999", error.to_s)
|
@@ -66,12 +65,12 @@ class TestParserContext < Test::Unit::TestCase
|
|
66
65
|
end
|
67
66
|
|
68
67
|
def test_string_empty
|
69
|
-
error =
|
68
|
+
error = assert_raises(TypeError) do
|
70
69
|
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 =
|
73
|
+
error = assert_raises(ArgumentError) do
|
75
74
|
XML::Parser::Context.string('')
|
76
75
|
end
|
77
76
|
assert_equal("Must specify a string with one or more characters", error.to_s)
|
@@ -85,7 +84,7 @@ class TestParserContext < Test::Unit::TestCase
|
|
85
84
|
|
86
85
|
def test_not_well_formed
|
87
86
|
parser = XML::Parser.string("<abc>")
|
88
|
-
|
87
|
+
assert_raises(XML::Error) do
|
89
88
|
parser.parse
|
90
89
|
end
|
91
90
|
assert(!parser.context.well_formed?)
|
@@ -166,7 +165,7 @@ class TestParserContext < Test::Unit::TestCase
|
|
166
165
|
def test_parse_error
|
167
166
|
xp = XML::Parser.string('<foo><bar/></foz>')
|
168
167
|
|
169
|
-
|
168
|
+
assert_raises(XML::Error) do
|
170
169
|
xp.parse
|
171
170
|
end
|
172
171
|
|
data/test/tc_properties.rb
CHANGED
@@ -2,12 +2,11 @@
|
|
2
2
|
|
3
3
|
require './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
|
9
|
+
class Testattributes < Minitest::Test
|
11
10
|
def setup()
|
12
11
|
xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
|
13
12
|
@doc = xp.parse
|