libxml-ruby 0.9.7-x86-mswin32-60 → 0.9.8-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +53 -0
- data/Rakefile +1 -0
- data/ext/libxml/build.log +4 -0
- data/ext/libxml/cbg.c +86 -86
- data/ext/libxml/libxml.c +878 -876
- data/ext/libxml/ruby_libxml.h +8 -4
- data/ext/libxml/ruby_xml_attr.c +36 -168
- data/ext/libxml/ruby_xml_attr.h +2 -4
- data/ext/libxml/ruby_xml_attr_decl.c +177 -0
- data/ext/libxml/ruby_xml_attr_decl.h +13 -0
- data/ext/libxml/ruby_xml_attributes.c +29 -20
- data/ext/libxml/ruby_xml_document.c +895 -898
- data/ext/libxml/ruby_xml_dtd.c +18 -1
- data/ext/libxml/ruby_xml_dtd.h +1 -0
- data/ext/libxml/ruby_xml_encoding.c +116 -0
- data/ext/libxml/ruby_xml_encoding.h +12 -0
- data/ext/libxml/ruby_xml_error.c +8 -2
- data/ext/libxml/ruby_xml_html_parser.c +53 -74
- data/ext/libxml/ruby_xml_html_parser.h +2 -3
- data/ext/libxml/ruby_xml_html_parser_context.c +145 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +48 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_input_cbg.c +1 -1
- data/ext/libxml/ruby_xml_io.c +30 -0
- data/ext/libxml/ruby_xml_io.h +9 -0
- data/ext/libxml/ruby_xml_namespace.c +34 -16
- data/ext/libxml/ruby_xml_namespace.h +2 -2
- data/ext/libxml/ruby_xml_namespaces.c +6 -6
- data/ext/libxml/ruby_xml_node.c +1367 -1324
- data/ext/libxml/ruby_xml_node.h +2 -2
- data/ext/libxml/ruby_xml_parser.c +26 -78
- data/ext/libxml/ruby_xml_parser.h +1 -1
- data/ext/libxml/ruby_xml_parser_context.c +284 -13
- data/ext/libxml/ruby_xml_parser_context.h +1 -2
- data/ext/libxml/ruby_xml_parser_options.c +75 -0
- data/ext/libxml/ruby_xml_parser_options.h +14 -0
- data/ext/libxml/ruby_xml_reader.c +277 -183
- data/ext/libxml/ruby_xml_sax_parser.c +60 -57
- data/ext/libxml/ruby_xml_xpath_context.c +43 -8
- data/ext/libxml/ruby_xml_xpath_expression.c +6 -0
- data/ext/libxml/ruby_xml_xpath_object.c +107 -95
- data/ext/libxml/ruby_xml_xpath_object.h +9 -1
- data/ext/libxml/ruby_xml_xpointer.c +107 -107
- data/ext/libxml/version.h +2 -2
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.vcproj +43 -3
- data/lib/libxml.rb +2 -3
- data/lib/libxml/attr.rb +71 -2
- data/lib/libxml/attr_decl.rb +81 -0
- data/lib/libxml/document.rb +78 -14
- data/lib/libxml/html_parser.rb +75 -42
- data/lib/libxml/node.rb +11 -0
- data/lib/libxml/parser.rb +106 -62
- data/lib/libxml/reader.rb +12 -0
- data/lib/libxml/sax_parser.rb +42 -52
- data/lib/libxml/xpath_object.rb +15 -0
- data/test/model/atom.xml +12 -12
- data/test/model/bands.xml +4 -4
- data/test/model/books.xml +146 -147
- data/test/model/merge_bug_data.xml +1 -1
- data/test/model/rubynet.xml +1 -0
- data/test/model/shiporder.rng +1 -1
- data/test/model/shiporder.xml +22 -22
- data/test/model/shiporder.xsd +30 -30
- data/test/model/xinclude.xml +1 -1
- data/test/{tc_node_attr.rb → tc_attr.rb} +1 -1
- data/test/tc_attr_decl.rb +131 -0
- data/test/tc_deprecated_require.rb +1 -3
- data/test/tc_document.rb +13 -3
- data/test/tc_document_write.rb +5 -5
- data/test/tc_dtd.rb +13 -5
- data/test/tc_html_parser.rb +14 -26
- data/test/tc_node_cdata.rb +1 -3
- data/test/tc_node_comment.rb +2 -4
- data/test/tc_node_edit.rb +2 -3
- data/test/tc_node_text.rb +35 -1
- data/test/tc_node_write.rb +3 -3
- data/test/tc_node_xlink.rb +2 -4
- data/test/tc_parser.rb +163 -70
- data/test/tc_parser_context.rb +103 -42
- data/test/tc_reader.rb +173 -45
- data/test/tc_relaxng.rb +2 -2
- data/test/tc_sax_parser.rb +48 -52
- data/test/tc_schema.rb +2 -2
- data/test/tc_xpath.rb +37 -6
- data/test/tc_xpath_context.rb +7 -1
- data/test/tc_xpath_expression.rb +1 -3
- data/test/tc_xpointer.rb +1 -3
- data/test/test_suite.rb +2 -3
- metadata +20 -13
- data/ext/libxml/ruby_xml_input.c +0 -329
- data/ext/libxml/ruby_xml_input.h +0 -20
- data/lib/libxml/parser_context.rb +0 -17
- data/lib/libxml/parser_options.rb +0 -25
- data/test/model/simple.xml +0 -7
- data/test/tc_input.rb +0 -13
- data/test/tc_well_formed.rb +0 -11
data/test/tc_reader.rb
CHANGED
@@ -2,99 +2,127 @@ require 'xml'
|
|
2
2
|
require 'test/unit'
|
3
3
|
|
4
4
|
class TestReader < Test::Unit::TestCase
|
5
|
-
|
6
|
-
SIMPLE_XML = File.join(File.dirname(__FILE__), 'model/simple.xml')
|
5
|
+
XML_FILE = File.join(File.dirname(__FILE__), 'model/atom.xml')
|
7
6
|
|
8
7
|
def verify_simple(reader)
|
9
8
|
node_types = []
|
10
|
-
|
11
|
-
|
9
|
+
|
10
|
+
# Read each node
|
11
|
+
26.times do
|
12
|
+
assert(reader.read)
|
12
13
|
node_types << reader.node_type
|
13
14
|
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
15
|
+
|
16
|
+
# There are no more nodes
|
17
|
+
assert(!reader.read)
|
18
|
+
|
19
|
+
# Check what was read
|
20
|
+
expected = [XML::Reader::TYPE_PROCESSING_INSTRUCTION,
|
21
|
+
XML::Reader::TYPE_ELEMENT,
|
22
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
23
|
+
XML::Reader::TYPE_COMMENT,
|
24
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
25
|
+
XML::Reader::TYPE_ELEMENT,
|
26
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
27
|
+
XML::Reader::TYPE_ELEMENT,
|
28
|
+
XML::Reader::TYPE_CDATA,
|
29
|
+
XML::Reader::TYPE_END_ELEMENT,
|
30
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
31
|
+
XML::Reader::TYPE_ELEMENT,
|
32
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
33
|
+
XML::Reader::TYPE_ELEMENT,
|
34
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
35
|
+
XML::Reader::TYPE_ELEMENT,
|
36
|
+
XML::Reader::TYPE_TEXT,
|
37
|
+
XML::Reader::TYPE_END_ELEMENT,
|
38
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
39
|
+
XML::Reader::TYPE_END_ELEMENT,
|
40
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
41
|
+
XML::Reader::TYPE_END_ELEMENT,
|
42
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
43
|
+
XML::Reader::TYPE_END_ELEMENT,
|
44
|
+
XML::Reader::TYPE_SIGNIFICANT_WHITESPACE,
|
45
|
+
XML::Reader::TYPE_END_ELEMENT]
|
46
|
+
|
47
|
+
assert_equal(expected, node_types)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_document
|
51
|
+
reader = XML::Reader.document(XML::Document.file(XML_FILE))
|
52
|
+
verify_simple(reader)
|
35
53
|
end
|
36
54
|
|
37
55
|
def test_file
|
38
|
-
reader = XML::Reader.file(
|
56
|
+
reader = XML::Reader.file(XML_FILE)
|
39
57
|
verify_simple(reader)
|
40
58
|
end
|
41
59
|
|
42
60
|
def test_invalid_file
|
43
|
-
|
61
|
+
assert_raise(XML::Error) do
|
44
62
|
XML::Reader.file('/does/not/exist')
|
45
63
|
end
|
46
64
|
end
|
47
65
|
|
48
66
|
def test_string
|
49
|
-
reader = XML::Reader.string(File.read(
|
67
|
+
reader = XML::Reader.string(File.read(XML_FILE))
|
50
68
|
verify_simple(reader)
|
51
69
|
end
|
52
70
|
|
53
71
|
def test_io
|
54
|
-
File.open(
|
72
|
+
File.open(XML_FILE, 'rb') do |io|
|
55
73
|
reader = XML::Reader.io(io)
|
56
74
|
verify_simple(reader)
|
57
75
|
end
|
58
76
|
end
|
59
77
|
|
60
78
|
def test_string_io
|
61
|
-
data = File.read(
|
79
|
+
data = File.read(XML_FILE)
|
62
80
|
string_io = StringIO.new(data)
|
63
81
|
reader = XML::Reader.io(string_io)
|
64
82
|
verify_simple(reader)
|
65
83
|
end
|
66
84
|
|
67
|
-
def
|
68
|
-
reader = XML::Reader.
|
69
|
-
|
85
|
+
def test_error
|
86
|
+
reader = XML::Reader.string('<foo blah')
|
87
|
+
|
88
|
+
error = assert_raise(XML::Error) do
|
89
|
+
reader.read
|
90
|
+
end
|
91
|
+
assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", error.to_s)
|
70
92
|
end
|
71
93
|
|
72
94
|
def test_deprecated_error_handler
|
73
95
|
called = false
|
74
|
-
reader = XML::Reader.
|
96
|
+
reader = XML::Reader.string('<foo blah')
|
75
97
|
reader.set_error_handler do |error|
|
76
98
|
called = true
|
77
99
|
end
|
78
100
|
|
79
|
-
|
101
|
+
assert_raise(XML::Error) do
|
102
|
+
reader.read
|
103
|
+
end
|
104
|
+
|
80
105
|
assert(called)
|
81
106
|
end
|
82
107
|
|
83
108
|
def test_deprecated_reset_error_handler
|
84
109
|
called = false
|
85
|
-
reader = XML::Reader.
|
110
|
+
reader = XML::Reader.string('<foo blah')
|
86
111
|
reader.set_error_handler do |error|
|
87
112
|
called = true
|
88
113
|
end
|
89
114
|
reader.reset_error_handler
|
90
115
|
|
91
|
-
|
116
|
+
assert_raise(XML::Error) do
|
117
|
+
reader.read
|
118
|
+
end
|
119
|
+
|
92
120
|
assert(!called)
|
93
121
|
end
|
94
122
|
|
95
123
|
def test_attr
|
96
|
-
parser = XML::Reader.
|
97
|
-
|
124
|
+
parser = XML::Reader.string("<foo x='1' y='2'/>")
|
125
|
+
assert(parser.read)
|
98
126
|
assert_equal('foo', parser.name)
|
99
127
|
assert_equal('1', parser['x'])
|
100
128
|
assert_equal('1', parser[0])
|
@@ -105,24 +133,24 @@ class TestReader < Test::Unit::TestCase
|
|
105
133
|
end
|
106
134
|
|
107
135
|
def test_value
|
108
|
-
parser = XML::Reader.
|
109
|
-
|
136
|
+
parser = XML::Reader.string("<foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>")
|
137
|
+
assert(parser.read)
|
110
138
|
assert_equal('foo', parser.name)
|
111
139
|
assert_equal(nil, parser.value)
|
112
140
|
3.times do |i|
|
113
|
-
|
141
|
+
assert(parser.read)
|
114
142
|
assert_equal(XML::Reader::TYPE_ELEMENT, parser.node_type)
|
115
143
|
assert_equal('bar', parser.name)
|
116
|
-
|
144
|
+
assert(parser.read)
|
117
145
|
assert_equal(XML::Reader::TYPE_TEXT, parser.node_type)
|
118
146
|
assert_equal((i + 1).to_s, parser.value)
|
119
|
-
|
147
|
+
assert(parser.read)
|
120
148
|
assert_equal(XML::Reader::TYPE_END_ELEMENT, parser.node_type)
|
121
149
|
end
|
122
150
|
end
|
123
151
|
|
124
152
|
def test_expand
|
125
|
-
reader = XML::Reader.file(
|
153
|
+
reader = XML::Reader.file(XML_FILE)
|
126
154
|
reader.read
|
127
155
|
node = reader.expand
|
128
156
|
doc = node.doc
|
@@ -138,4 +166,104 @@ class TestReader < Test::Unit::TestCase
|
|
138
166
|
reader.read
|
139
167
|
assert_equal(XML::Reader::MODE_EOF, reader.read_state)
|
140
168
|
end
|
169
|
+
|
170
|
+
def test_bytes_consumed
|
171
|
+
reader = XML::Reader.file(XML_FILE)
|
172
|
+
reader.read
|
173
|
+
assert_equal(416, reader.byte_consumed)
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_node
|
177
|
+
XML.default_line_numbers = true
|
178
|
+
reader = XML::Reader.file(XML_FILE)
|
179
|
+
reader.read
|
180
|
+
assert_instance_of(XML::Node, reader.node)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_base_uri
|
184
|
+
# UTF8:
|
185
|
+
# ö - c3 b6 in hex, \303\266 in octal
|
186
|
+
# ü - c3 bc in hex, \303\274 in octal
|
187
|
+
xml = "<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
|
188
|
+
reader = XML::Reader.string(xml, :base_uri => "http://libxml.rubyforge.org")
|
189
|
+
|
190
|
+
reader.read
|
191
|
+
assert_equal(reader.base_uri, "http://libxml.rubyforge.org")
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_options
|
195
|
+
xml = <<-EOS
|
196
|
+
<!DOCTYPE foo [<!ENTITY foo 'bar'>]>
|
197
|
+
<test>
|
198
|
+
<cdata><![CDATA[something]]></cdata>
|
199
|
+
<entity>&foo;</entity>
|
200
|
+
</test>
|
201
|
+
EOS
|
202
|
+
|
203
|
+
# Parse normally
|
204
|
+
reader = XML::Reader.string(xml)
|
205
|
+
reader.read # foo
|
206
|
+
reader.read # test
|
207
|
+
reader.read # text
|
208
|
+
reader.read # cdata
|
209
|
+
reader.read # cdata-section
|
210
|
+
assert_equal(XML::Node::CDATA_SECTION_NODE, reader.node_type)
|
211
|
+
|
212
|
+
# Convert cdata section to text
|
213
|
+
reader = XML::Reader.string(xml, :options => XML::Parser::Options::NOCDATA)
|
214
|
+
reader.read # foo
|
215
|
+
reader.read # test
|
216
|
+
reader.read # text
|
217
|
+
reader.read # cdata
|
218
|
+
reader.read # cdata-section
|
219
|
+
assert_equal(XML::Node::TEXT_NODE, reader.node_type)
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_encoding
|
223
|
+
# ISO_8859_1:
|
224
|
+
# ö - f6 in hex, \366 in octal
|
225
|
+
# ü - fc in hex, \374 in octal
|
226
|
+
xml = "<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
|
227
|
+
|
228
|
+
reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1)
|
229
|
+
reader.read
|
230
|
+
|
231
|
+
# libxml converts all data sources to utf8 internally
|
232
|
+
assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
|
233
|
+
reader.read_outer_xml)
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_invalid_encoding
|
237
|
+
# ISO_8859_1:
|
238
|
+
# ö - f6 in hex, \366 in octal
|
239
|
+
# ü - fc in hex, \374 in octal
|
240
|
+
xml = "<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
|
241
|
+
|
242
|
+
reader = XML::Reader.string(xml)
|
243
|
+
error = assert_raise(XML::Error) do
|
244
|
+
node = reader.read
|
245
|
+
end
|
246
|
+
|
247
|
+
assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
|
248
|
+
error.to_s)
|
249
|
+
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_file_encoding
|
253
|
+
reader = XML::Reader.file(XML_FILE)
|
254
|
+
reader.read
|
255
|
+
assert_equal(reader.encoding, XML::Encoding::UTF_8)
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_string_encoding
|
259
|
+
# ISO_8859_1:
|
260
|
+
# ö - f6 in hex, \366 in octal
|
261
|
+
# ü - fc in hex, \374 in octal
|
262
|
+
xml = "<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>"
|
263
|
+
reader = XML::Reader.string(xml, :encoding => XML::Encoding::ISO_8859_1)
|
264
|
+
reader.read
|
265
|
+
|
266
|
+
# Encoding is always null for strings, very annoying!
|
267
|
+
assert_equal(reader.encoding, XML::Encoding::NONE)
|
268
|
+
end
|
141
269
|
end
|
data/test/tc_relaxng.rb
CHANGED
@@ -3,8 +3,8 @@ require 'test/unit'
|
|
3
3
|
|
4
4
|
class TestRelaxNG < Test::Unit::TestCase
|
5
5
|
def setup
|
6
|
-
|
7
|
-
@doc = XML::Document.file(
|
6
|
+
file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
|
7
|
+
@doc = XML::Document.file(file)
|
8
8
|
end
|
9
9
|
|
10
10
|
def teardown
|
data/test/tc_sax_parser.rb
CHANGED
@@ -67,22 +67,12 @@ class TestCaseCallbacks
|
|
67
67
|
end
|
68
68
|
|
69
69
|
class TestSaxParser < Test::Unit::TestCase
|
70
|
-
def setup
|
71
|
-
XML.default_keep_blanks = true
|
72
|
-
@xp = XML::SaxParser.new
|
73
|
-
end
|
74
|
-
|
75
|
-
def teardown
|
76
|
-
@xp = nil
|
77
|
-
XML.default_keep_blanks = true
|
78
|
-
end
|
79
|
-
|
80
70
|
def saxtest_file
|
81
71
|
File.join(File.dirname(__FILE__), 'model/atom.xml')
|
82
72
|
end
|
83
73
|
|
84
|
-
def verify
|
85
|
-
result =
|
74
|
+
def verify(parser)
|
75
|
+
result = parser.callbacks.result
|
86
76
|
|
87
77
|
i = -1
|
88
78
|
assert_equal("startdoc", result[i+=1])
|
@@ -127,75 +117,80 @@ class TestSaxParser < Test::Unit::TestCase
|
|
127
117
|
assert_equal("end_document", result[i+=1])
|
128
118
|
end
|
129
119
|
|
130
|
-
def
|
131
|
-
|
132
|
-
|
120
|
+
def test_file
|
121
|
+
parser = XML::SaxParser.file(saxtest_file)
|
122
|
+
parser.callbacks = TestCaseCallbacks.new
|
123
|
+
parser.parse
|
124
|
+
verify(parser)
|
133
125
|
end
|
134
126
|
|
135
127
|
def test_file_no_callbacks
|
136
|
-
|
137
|
-
assert_equal true,
|
128
|
+
parser = XML::SaxParser.file(saxtest_file)
|
129
|
+
assert_equal true, parser.parse
|
138
130
|
end
|
139
131
|
|
140
|
-
def
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
132
|
+
def test_io
|
133
|
+
File.open(saxtest_file) do |file|
|
134
|
+
parser = XML::SaxParser.io(file)
|
135
|
+
parser.callbacks = TestCaseCallbacks.new
|
136
|
+
parser.parse
|
137
|
+
verify(parser)
|
138
|
+
end
|
145
139
|
end
|
146
140
|
|
147
|
-
def
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
verify
|
141
|
+
def test_string_no_callbacks
|
142
|
+
xml = File.read(saxtest_file)
|
143
|
+
parser = XML::SaxParser.string(xml)
|
144
|
+
assert_equal true, parser.parse
|
152
145
|
end
|
153
146
|
|
154
|
-
def
|
155
|
-
File.
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
end
|
147
|
+
def test_string
|
148
|
+
xml = File.read(saxtest_file)
|
149
|
+
parser = XML::SaxParser.string(xml)
|
150
|
+
parser.callbacks = TestCaseCallbacks.new
|
151
|
+
parser.parse
|
152
|
+
verify(parser)
|
161
153
|
end
|
162
154
|
|
163
155
|
def test_string_io
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
156
|
+
xml = File.read(saxtest_file)
|
157
|
+
io = StringIO.new(xml)
|
158
|
+
parser = XML::SaxParser.io(io)
|
159
|
+
|
160
|
+
parser.callbacks = TestCaseCallbacks.new
|
161
|
+
parser.parse
|
162
|
+
verify(parser)
|
170
163
|
end
|
171
164
|
|
172
165
|
def test_doctype
|
173
|
-
|
174
|
-
@xp.string = <<-EOS
|
166
|
+
xml = <<-EOS
|
175
167
|
<?xml version="1.0" encoding="UTF-8"?>
|
176
168
|
<!DOCTYPE Results SYSTEM "results.dtd">
|
177
169
|
<Results>
|
178
170
|
<a>a1</a>
|
179
171
|
</Results>
|
180
172
|
EOS
|
181
|
-
|
173
|
+
parser = XML::SaxParser.string(xml)
|
174
|
+
parser.callbacks = DocTypeCallback.new
|
175
|
+
doc = parser.parse
|
182
176
|
assert_not_nil(doc)
|
183
177
|
end
|
184
178
|
|
185
|
-
|
186
179
|
def test_parse_warning
|
187
|
-
@xp.callbacks = TestCaseCallbacks.new
|
188
180
|
# Two xml PIs is a warning
|
189
|
-
|
181
|
+
xml = <<-EOS
|
190
182
|
<?xml version="1.0" encoding="utf-8"?>
|
191
183
|
<?xml-invalid?>
|
192
184
|
<Test/>
|
193
185
|
EOS
|
194
186
|
|
195
|
-
|
187
|
+
parser = XML::SaxParser.string(xml)
|
188
|
+
parser.callbacks = TestCaseCallbacks.new
|
189
|
+
|
190
|
+
parser.parse
|
196
191
|
|
197
192
|
# Check callbacks
|
198
|
-
result =
|
193
|
+
result = parser.callbacks.result
|
199
194
|
i = -1
|
200
195
|
assert_equal("startdoc", result[i+=1])
|
201
196
|
assert_equal("error: Warning: xmlParsePITarget: invalid name prefix 'xml' at :2.", result[i+=1])
|
@@ -208,17 +203,18 @@ EOS
|
|
208
203
|
end
|
209
204
|
|
210
205
|
def test_parse_error
|
211
|
-
|
212
|
-
@xp.string = <<-EOS
|
206
|
+
xml = <<-EOS
|
213
207
|
<Results>
|
214
208
|
EOS
|
209
|
+
parser = XML::SaxParser.string(xml)
|
210
|
+
parser.callbacks = TestCaseCallbacks.new
|
215
211
|
|
216
212
|
error = assert_raise(XML::Error) do
|
217
|
-
doc =
|
213
|
+
doc = parser.parse
|
218
214
|
end
|
219
215
|
|
220
216
|
# Check callbacks
|
221
|
-
result =
|
217
|
+
result = parser.callbacks.result
|
222
218
|
|
223
219
|
i = -1
|
224
220
|
assert_equal("startdoc", result[i+=1])
|