libxml-ruby 2.0.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +516 -0
- data/LICENSE +23 -0
- data/MANIFEST +165 -0
- data/README.rdoc +161 -0
- data/Rakefile +82 -0
- data/ext/libxml/extconf.rb +122 -0
- data/ext/libxml/libxml.c +93 -0
- data/ext/libxml/ruby_libxml.h +101 -0
- data/ext/libxml/ruby_xml.c +893 -0
- data/ext/libxml/ruby_xml.h +10 -0
- data/ext/libxml/ruby_xml_attr.c +352 -0
- data/ext/libxml/ruby_xml_attr.h +14 -0
- data/ext/libxml/ruby_xml_attr_decl.c +171 -0
- data/ext/libxml/ruby_xml_attr_decl.h +13 -0
- data/ext/libxml/ruby_xml_attributes.c +277 -0
- data/ext/libxml/ruby_xml_attributes.h +17 -0
- data/ext/libxml/ruby_xml_cbg.c +85 -0
- data/ext/libxml/ruby_xml_document.c +958 -0
- data/ext/libxml/ruby_xml_document.h +17 -0
- data/ext/libxml/ruby_xml_dtd.c +257 -0
- data/ext/libxml/ruby_xml_dtd.h +9 -0
- data/ext/libxml/ruby_xml_encoding.c +221 -0
- data/ext/libxml/ruby_xml_encoding.h +16 -0
- data/ext/libxml/ruby_xml_error.c +1004 -0
- data/ext/libxml/ruby_xml_error.h +14 -0
- data/ext/libxml/ruby_xml_html_parser.c +92 -0
- data/ext/libxml/ruby_xml_html_parser.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_input_cbg.c +191 -0
- data/ext/libxml/ruby_xml_input_cbg.h +20 -0
- 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 +170 -0
- data/ext/libxml/ruby_xml_namespace.h +12 -0
- data/ext/libxml/ruby_xml_namespaces.c +295 -0
- data/ext/libxml/ruby_xml_namespaces.h +11 -0
- data/ext/libxml/ruby_xml_node.c +1386 -0
- data/ext/libxml/ruby_xml_node.h +13 -0
- data/ext/libxml/ruby_xml_parser.c +94 -0
- data/ext/libxml/ruby_xml_parser.h +14 -0
- data/ext/libxml/ruby_xml_parser_context.c +982 -0
- data/ext/libxml/ruby_xml_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_parser_options.c +68 -0
- data/ext/libxml/ruby_xml_parser_options.h +14 -0
- data/ext/libxml/ruby_xml_reader.c +1057 -0
- data/ext/libxml/ruby_xml_reader.h +14 -0
- data/ext/libxml/ruby_xml_relaxng.c +111 -0
- data/ext/libxml/ruby_xml_relaxng.h +10 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +334 -0
- data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
- data/ext/libxml/ruby_xml_sax_parser.c +136 -0
- data/ext/libxml/ruby_xml_sax_parser.h +12 -0
- data/ext/libxml/ruby_xml_schema.c +159 -0
- data/ext/libxml/ruby_xml_schema.h +11 -0
- data/ext/libxml/ruby_xml_version.h +9 -0
- data/ext/libxml/ruby_xml_xinclude.c +18 -0
- data/ext/libxml/ruby_xml_xinclude.h +13 -0
- data/ext/libxml/ruby_xml_xpath.c +107 -0
- data/ext/libxml/ruby_xml_xpath.h +12 -0
- data/ext/libxml/ruby_xml_xpath_context.c +390 -0
- data/ext/libxml/ruby_xml_xpath_context.h +11 -0
- data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
- data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
- data/ext/libxml/ruby_xml_xpath_object.c +336 -0
- data/ext/libxml/ruby_xml_xpath_object.h +19 -0
- data/ext/libxml/ruby_xml_xpointer.c +101 -0
- data/ext/libxml/ruby_xml_xpointer.h +13 -0
- data/ext/mingw/Rakefile +34 -0
- data/ext/mingw/build.rake +41 -0
- data/ext/vc/libxml_ruby.sln +26 -0
- data/lib/1.8/libxml_ruby.so +0 -0
- data/lib/1.9/libxml_ruby.so +0 -0
- data/lib/libxml.rb +30 -0
- data/lib/libxml/attr.rb +113 -0
- data/lib/libxml/attr_decl.rb +80 -0
- data/lib/libxml/attributes.rb +14 -0
- data/lib/libxml/document.rb +192 -0
- data/lib/libxml/error.rb +90 -0
- data/lib/libxml/hpricot.rb +78 -0
- data/lib/libxml/html_parser.rb +96 -0
- data/lib/libxml/namespace.rb +62 -0
- data/lib/libxml/namespaces.rb +38 -0
- data/lib/libxml/node.rb +399 -0
- data/lib/libxml/ns.rb +22 -0
- data/lib/libxml/parser.rb +367 -0
- data/lib/libxml/properties.rb +23 -0
- data/lib/libxml/reader.rb +29 -0
- data/lib/libxml/sax_callbacks.rb +180 -0
- data/lib/libxml/sax_parser.rb +58 -0
- data/lib/libxml/tree.rb +29 -0
- data/lib/libxml/xpath_object.rb +16 -0
- data/lib/xml.rb +16 -0
- data/lib/xml/libxml.rb +10 -0
- data/libxml-ruby.gemspec +50 -0
- data/script/benchmark/depixelate +634 -0
- data/script/benchmark/hamlet.xml +9055 -0
- data/script/benchmark/parsecount +170 -0
- data/script/benchmark/sock_entries.xml +507 -0
- data/script/benchmark/throughput +41 -0
- data/script/test +6 -0
- data/setup.rb +1585 -0
- data/test/etc_doc_to_s.rb +21 -0
- data/test/ets_doc_file.rb +17 -0
- data/test/ets_doc_to_s.rb +23 -0
- data/test/ets_gpx.rb +28 -0
- data/test/ets_node_gc.rb +23 -0
- data/test/ets_test.xml +2 -0
- data/test/ets_tsr.rb +11 -0
- data/test/model/atom.xml +13 -0
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/model/bands.xml +5 -0
- data/test/model/books.xml +146 -0
- data/test/model/merge_bug_data.xml +58 -0
- data/test/model/ruby-lang.html +238 -0
- data/test/model/rubynet.xml +79 -0
- data/test/model/rubynet_project +1 -0
- data/test/model/shiporder.rnc +28 -0
- data/test/model/shiporder.rng +86 -0
- data/test/model/shiporder.xml +23 -0
- data/test/model/shiporder.xsd +31 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/rb-magic-comment.rb +33 -0
- data/test/tc_attr.rb +181 -0
- data/test/tc_attr_decl.rb +133 -0
- data/test/tc_attributes.rb +135 -0
- data/test/tc_deprecated_require.rb +13 -0
- data/test/tc_document.rb +119 -0
- data/test/tc_document_write.rb +187 -0
- data/test/tc_dtd.rb +125 -0
- data/test/tc_error.rb +138 -0
- data/test/tc_html_parser.rb +140 -0
- data/test/tc_namespace.rb +62 -0
- data/test/tc_namespaces.rb +177 -0
- data/test/tc_node.rb +258 -0
- data/test/tc_node_cdata.rb +51 -0
- data/test/tc_node_comment.rb +33 -0
- data/test/tc_node_copy.rb +42 -0
- data/test/tc_node_edit.rb +160 -0
- data/test/tc_node_text.rb +71 -0
- data/test/tc_node_write.rb +108 -0
- data/test/tc_node_xlink.rb +29 -0
- data/test/tc_parser.rb +336 -0
- data/test/tc_parser_context.rb +189 -0
- data/test/tc_properties.rb +39 -0
- data/test/tc_reader.rb +298 -0
- data/test/tc_relaxng.rb +54 -0
- data/test/tc_sax_parser.rb +276 -0
- data/test/tc_schema.rb +53 -0
- data/test/tc_traversal.rb +222 -0
- data/test/tc_xinclude.rb +21 -0
- data/test/tc_xml.rb +226 -0
- data/test/tc_xpath.rb +195 -0
- data/test/tc_xpath_context.rb +80 -0
- data/test/tc_xpath_expression.rb +38 -0
- data/test/tc_xpointer.rb +74 -0
- data/test/test_helper.rb +14 -0
- data/test/test_suite.rb +39 -0
- metadata +254 -0
data/test/tc_parser.rb
ADDED
@@ -0,0 +1,336 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
require 'test/unit'
|
5
|
+
require 'stringio'
|
6
|
+
|
7
|
+
class TestParser < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
XML::Error.set_handler(&XML::Error::QUIET_HANDLER)
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
GC.start
|
14
|
+
GC.start
|
15
|
+
GC.start
|
16
|
+
end
|
17
|
+
|
18
|
+
# ----- Sources -------8
|
19
|
+
def test_document
|
20
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
|
21
|
+
parser = XML::Parser.file(file)
|
22
|
+
doc = parser.parse
|
23
|
+
|
24
|
+
parser = XML::Parser.document(doc)
|
25
|
+
|
26
|
+
doc = parser.parse
|
27
|
+
|
28
|
+
assert_instance_of(XML::Document, doc)
|
29
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_nil_document
|
33
|
+
error = assert_raise(TypeError) do
|
34
|
+
XML::Parser.document(nil)
|
35
|
+
end
|
36
|
+
|
37
|
+
assert_equal("Must pass an XML::Document object", error.to_s)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_file
|
41
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
42
|
+
|
43
|
+
parser = XML::Parser.file(file)
|
44
|
+
doc = parser.parse
|
45
|
+
assert_instance_of(XML::Document, doc)
|
46
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_noexistent_file
|
50
|
+
error = assert_raise(XML::Error) do
|
51
|
+
XML::Parser.file('i_dont_exist.xml')
|
52
|
+
end
|
53
|
+
|
54
|
+
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_nil_file
|
58
|
+
error = assert_raise(TypeError) do
|
59
|
+
XML::Parser.file(nil)
|
60
|
+
end
|
61
|
+
|
62
|
+
assert_equal("can't convert nil into String", error.to_s)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_file_encoding
|
66
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
|
67
|
+
parser = XML::Parser.file(file, :encoding => XML::Encoding::ISO_8859_1)
|
68
|
+
|
69
|
+
error = assert_raise(XML::Error) do
|
70
|
+
doc = parser.parse
|
71
|
+
end
|
72
|
+
|
73
|
+
assert(error.to_s.match(/Fatal error: Extra content at the end of the document/))
|
74
|
+
|
75
|
+
parser = XML::Parser.file(file, :encoding => XML::Encoding::UTF_8)
|
76
|
+
doc = parser.parse
|
77
|
+
assert_not_nil(doc)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_file_base_uri
|
81
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
|
82
|
+
|
83
|
+
parser = XML::Parser.file(file)
|
84
|
+
doc = parser.parse
|
85
|
+
assert(doc.child.base_uri.match(/test\/model\/bands.utf-8.xml/))
|
86
|
+
|
87
|
+
parser = XML::Parser.file(file, :base_uri => "http://libxml.org")
|
88
|
+
doc = parser.parse
|
89
|
+
assert(doc.child.base_uri.match(/test\/model\/bands.utf-8.xml/))
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_io
|
93
|
+
File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
|
94
|
+
parser = XML::Parser.io(io)
|
95
|
+
assert_instance_of(XML::Parser, parser)
|
96
|
+
|
97
|
+
doc = parser.parse
|
98
|
+
assert_instance_of(XML::Document, doc)
|
99
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_io_gc
|
104
|
+
# Test that the reader keeps a reference
|
105
|
+
# to the io object
|
106
|
+
file = File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
107
|
+
parser = XML::Parser.io(file)
|
108
|
+
file = nil
|
109
|
+
GC.start
|
110
|
+
assert(parser.parse)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_nil_io
|
114
|
+
error = assert_raise(TypeError) do
|
115
|
+
XML::Parser.io(nil)
|
116
|
+
end
|
117
|
+
|
118
|
+
assert_equal("Must pass in an IO object", error.to_s)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_string_io
|
122
|
+
data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
123
|
+
string_io = StringIO.new(data)
|
124
|
+
parser = XML::Parser.io(string_io)
|
125
|
+
|
126
|
+
doc = parser.parse
|
127
|
+
assert_instance_of(XML::Document, doc)
|
128
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
129
|
+
end
|
130
|
+
|
131
|
+
def test_string
|
132
|
+
str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
133
|
+
|
134
|
+
parser = XML::Parser.string(str)
|
135
|
+
assert_instance_of(XML::Parser, parser)
|
136
|
+
|
137
|
+
doc = parser.parse
|
138
|
+
assert_instance_of(XML::Document, doc)
|
139
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_nil_string
|
143
|
+
error = assert_raise(TypeError) do
|
144
|
+
XML::Parser.string(nil)
|
145
|
+
end
|
146
|
+
|
147
|
+
assert_equal("wrong argument type nil (expected String)", error.to_s)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_string_options
|
151
|
+
xml = <<-EOS
|
152
|
+
<!DOCTYPE foo [<!ENTITY foo 'bar'>]>
|
153
|
+
<test>
|
154
|
+
<cdata><![CDATA[something]]></cdata>
|
155
|
+
<entity>&foo;</entity>
|
156
|
+
</test>
|
157
|
+
EOS
|
158
|
+
|
159
|
+
XML::default_substitute_entities = false
|
160
|
+
|
161
|
+
# Parse normally
|
162
|
+
parser = XML::Parser.string(xml)
|
163
|
+
doc = parser.parse
|
164
|
+
assert_nil(doc.child.base_uri)
|
165
|
+
|
166
|
+
# Cdata section should be cdata nodes
|
167
|
+
node = doc.find_first('/test/cdata').child
|
168
|
+
assert_equal(XML::Node::CDATA_SECTION_NODE, node.node_type)
|
169
|
+
|
170
|
+
# Entities should not be subtituted
|
171
|
+
node = doc.find_first('/test/entity')
|
172
|
+
assert_equal('&foo;', node.child.to_s)
|
173
|
+
|
174
|
+
# Parse with options
|
175
|
+
parser = XML::Parser.string(xml, :base_uri => 'http://libxml.rubyforge.org',
|
176
|
+
:options => XML::Parser::Options::NOCDATA | XML::Parser::Options::NOENT)
|
177
|
+
doc = parser.parse
|
178
|
+
assert_equal(doc.child.base_uri, 'http://libxml.rubyforge.org')
|
179
|
+
|
180
|
+
# Cdata section should be text nodes
|
181
|
+
node = doc.find_first('/test/cdata').child
|
182
|
+
assert_equal(XML::Node::TEXT_NODE, node.node_type)
|
183
|
+
|
184
|
+
# Entities should be subtituted
|
185
|
+
node = doc.find_first('/test/entity')
|
186
|
+
assert_equal('bar', node.child.to_s)
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_string_encoding
|
190
|
+
# ISO_8859_1:
|
191
|
+
# ö - f6 in hex, \366 in octal
|
192
|
+
# ü - fc in hex, \374 in octal
|
193
|
+
|
194
|
+
xml = <<-EOS
|
195
|
+
<bands>
|
196
|
+
<metal>m\366tley_cr\374e</metal>
|
197
|
+
</bands>
|
198
|
+
EOS
|
199
|
+
|
200
|
+
# Parse as UTF_8
|
201
|
+
parser = XML::Parser.string(xml, :encoding => XML::Encoding::UTF_8)
|
202
|
+
|
203
|
+
error = assert_raise(XML::Error) do
|
204
|
+
doc = parser.parse
|
205
|
+
end
|
206
|
+
|
207
|
+
assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
|
208
|
+
error.to_s)
|
209
|
+
|
210
|
+
# Parse as ISO_8859_1:
|
211
|
+
parser = XML::Parser.string(xml, :encoding => XML::Encoding::ISO_8859_1)
|
212
|
+
doc = parser.parse
|
213
|
+
node = doc.find_first('//metal')
|
214
|
+
if defined?(Encoding)
|
215
|
+
assert_equal(Encoding::ISO8859_1, node.content.encoding)
|
216
|
+
assert_equal("m\303\266tley_cr\303\274e".force_encoding(Encoding::ISO8859_1), node.content)
|
217
|
+
else
|
218
|
+
assert_equal("m\303\266tley_cr\303\274e", node.content)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_fd_gc
|
223
|
+
# Test opening # of documents up to the file limit for the OS.
|
224
|
+
# Ideally it should run until libxml emits a warning,
|
225
|
+
# thereby knowing we've done a GC sweep. For the time being,
|
226
|
+
# re-open the same doc `limit descriptors` times.
|
227
|
+
# If we make it to the end, then we've succeeded,
|
228
|
+
# otherwise an exception will be thrown.
|
229
|
+
XML::Error.set_handler {|error|}
|
230
|
+
|
231
|
+
max_fd = if RUBY_PLATFORM.match(/mswin32|mingw/i)
|
232
|
+
500
|
233
|
+
else
|
234
|
+
(`ulimit -n`.chomp.to_i) + 1
|
235
|
+
end
|
236
|
+
|
237
|
+
file = File.join(File.dirname(__FILE__), 'model/rubynet.xml')
|
238
|
+
max_fd.times do
|
239
|
+
XML::Parser.file(file).parse
|
240
|
+
end
|
241
|
+
XML::Error.reset_handler {|error|}
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
# ----- Errors ------
|
246
|
+
def test_error
|
247
|
+
error = assert_raise(XML::Error) do
|
248
|
+
XML::Parser.string('<foo><bar/></foz>').parse
|
249
|
+
end
|
250
|
+
|
251
|
+
assert_not_nil(error)
|
252
|
+
assert_kind_of(XML::Error, error)
|
253
|
+
assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", error.message)
|
254
|
+
assert_equal(XML::Error::PARSER, error.domain)
|
255
|
+
assert_equal(XML::Error::TAG_NAME_MISMATCH, error.code)
|
256
|
+
assert_equal(XML::Error::FATAL, error.level)
|
257
|
+
assert_nil(error.file)
|
258
|
+
assert_equal(1, error.line)
|
259
|
+
assert_equal('foo', error.str1)
|
260
|
+
assert_equal('foz', error.str2)
|
261
|
+
assert_nil(error.str3)
|
262
|
+
assert_equal(1, error.int1)
|
263
|
+
assert_equal(20, error.int2)
|
264
|
+
assert_nil(error.node)
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_bad_xml
|
268
|
+
parser = XML::Parser.string('<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
|
269
|
+
error = assert_raise(XML::Error) do
|
270
|
+
assert_not_nil(parser.parse)
|
271
|
+
end
|
272
|
+
|
273
|
+
assert_not_nil(error)
|
274
|
+
assert_kind_of(XML::Error, error)
|
275
|
+
assert_equal("Fatal error: Extra content at the end of the document at :1.", error.message)
|
276
|
+
assert_equal(XML::Error::PARSER, error.domain)
|
277
|
+
assert_equal(XML::Error::DOCUMENT_END, error.code)
|
278
|
+
assert_equal(XML::Error::FATAL, error.level)
|
279
|
+
assert_nil(error.file)
|
280
|
+
assert_equal(1, error.line)
|
281
|
+
assert_nil(error.str1)
|
282
|
+
assert_nil(error.str2)
|
283
|
+
assert_nil(error.str3)
|
284
|
+
assert_equal(0, error.int1)
|
285
|
+
assert_equal(20, error.int2)
|
286
|
+
assert_nil(error.node)
|
287
|
+
end
|
288
|
+
|
289
|
+
# Deprecated methods
|
290
|
+
def test_document_deprecated
|
291
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
|
292
|
+
parser = XML::Parser.file(file)
|
293
|
+
doc = parser.parse
|
294
|
+
|
295
|
+
parser = XML::Parser.new
|
296
|
+
parser.document = doc
|
297
|
+
doc = parser.parse
|
298
|
+
|
299
|
+
assert_instance_of(XML::Document, doc)
|
300
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_file_deprecated
|
304
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
305
|
+
|
306
|
+
parser = XML::Parser.new
|
307
|
+
parser.file = file
|
308
|
+
doc = parser.parse
|
309
|
+
assert_instance_of(XML::Document, doc)
|
310
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_io_deprecated
|
314
|
+
File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
|
315
|
+
parser = XML::Parser.new
|
316
|
+
assert_instance_of(XML::Parser, parser)
|
317
|
+
parser.io = io
|
318
|
+
|
319
|
+
doc = parser.parse
|
320
|
+
assert_instance_of(XML::Document, doc)
|
321
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
325
|
+
def test_string_deprecated
|
326
|
+
str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
327
|
+
|
328
|
+
parser = XML::Parser.new
|
329
|
+
parser.string = str
|
330
|
+
assert_instance_of(XML::Parser, parser)
|
331
|
+
|
332
|
+
doc = parser.parse
|
333
|
+
assert_instance_of(XML::Document, doc)
|
334
|
+
assert_instance_of(XML::Parser::Context, parser.context)
|
335
|
+
end
|
336
|
+
end
|
@@ -0,0 +1,189 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TestParserContext < Test::Unit::TestCase
|
8
|
+
def test_string
|
9
|
+
# UTF8
|
10
|
+
xml = <<-EOS
|
11
|
+
<bands>
|
12
|
+
<metal>m\303\266tley_cr\303\274e</metal>
|
13
|
+
</bands>
|
14
|
+
EOS
|
15
|
+
|
16
|
+
context = XML::Parser::Context.string(xml)
|
17
|
+
assert_instance_of(XML::Parser::Context, context)
|
18
|
+
assert_equal(XML::Encoding::NONE, context.encoding)
|
19
|
+
assert_nil(context.base_uri)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_encoding
|
23
|
+
# ISO_8859_1:
|
24
|
+
xml = <<-EOS
|
25
|
+
<bands>
|
26
|
+
<metal>m\366tley_cr\374e</metal>
|
27
|
+
</bands>
|
28
|
+
EOS
|
29
|
+
|
30
|
+
context = XML::Parser::Context.string(xml)
|
31
|
+
assert_equal(XML::Encoding::NONE, context.encoding)
|
32
|
+
|
33
|
+
context.encoding = XML::Encoding::ISO_8859_1
|
34
|
+
assert_equal(XML::Encoding::ISO_8859_1, context.encoding)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_base_uri
|
38
|
+
# UTF8
|
39
|
+
xml = <<-EOS
|
40
|
+
<bands>
|
41
|
+
<metal>m\303\266tley_cr\303\274e</metal>
|
42
|
+
</bands>
|
43
|
+
EOS
|
44
|
+
|
45
|
+
context = XML::Parser::Context.string(xml)
|
46
|
+
assert_nil(context.base_uri)
|
47
|
+
|
48
|
+
context.base_uri = 'http://libxml.rubyforge.org'
|
49
|
+
assert_equal('http://libxml.rubyforge.org', context.base_uri)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_string_empty
|
53
|
+
error = assert_raise(TypeError) do
|
54
|
+
parser = XML::Parser::Context.string(nil)
|
55
|
+
end
|
56
|
+
assert_equal("wrong argument type nil (expected String)", error.to_s)
|
57
|
+
|
58
|
+
error = assert_raise(ArgumentError) do
|
59
|
+
XML::Parser::Context.string('')
|
60
|
+
end
|
61
|
+
assert_equal("Must specify a string with one or more characters", error.to_s)
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_well_formed
|
65
|
+
parser = XML::Parser.string("<abc/>")
|
66
|
+
parser.parse
|
67
|
+
assert(parser.context.well_formed?)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_not_well_formed
|
71
|
+
parser = XML::Parser.string("<abc>")
|
72
|
+
assert_raise(XML::Error) do
|
73
|
+
parser.parse
|
74
|
+
end
|
75
|
+
assert(!parser.context.well_formed?)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_version_info
|
79
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
|
80
|
+
parser = XML::Parser.file(file)
|
81
|
+
assert_nil(parser.context.version)
|
82
|
+
parser.parse
|
83
|
+
assert_equal("1.0", parser.context.version)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_depth
|
87
|
+
context = XML::Parser::Context.new
|
88
|
+
assert_instance_of(Fixnum, context.depth)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_disable_sax
|
92
|
+
context = XML::Parser::Context.new
|
93
|
+
assert(!context.disable_sax?)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_docbook
|
97
|
+
context = XML::Parser::Context.new
|
98
|
+
assert(!context.docbook?)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_html
|
102
|
+
context = XML::Parser::Context.new
|
103
|
+
assert(!context.html?)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_keep_blanks
|
107
|
+
context = XML::Parser::Context.new
|
108
|
+
if context.keep_blanks?
|
109
|
+
assert_instance_of(TrueClass, context.keep_blanks?)
|
110
|
+
else
|
111
|
+
assert_instance_of(FalseClass, context.keep_blanks?)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
if ENV['NOTWORKING']
|
116
|
+
def test_num_chars
|
117
|
+
assert_equal(17, context.num_chars)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_replace_entities
|
122
|
+
context = XML::Parser::Context.new
|
123
|
+
assert(!context.replace_entities?)
|
124
|
+
|
125
|
+
# context.options = 1
|
126
|
+
# assert(context.replace_entities?)
|
127
|
+
|
128
|
+
context.options = 0
|
129
|
+
assert(!context.replace_entities?)
|
130
|
+
|
131
|
+
context.replace_entities = true
|
132
|
+
assert(context.replace_entities?)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_space_depth
|
136
|
+
context = XML::Parser::Context.new
|
137
|
+
assert_equal(1, context.space_depth)
|
138
|
+
end
|
139
|
+
|
140
|
+
def test_subset_external
|
141
|
+
context = XML::Parser::Context.new
|
142
|
+
assert(!context.subset_external?)
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_data_directory_get
|
146
|
+
context = XML::Parser::Context.new
|
147
|
+
assert_nil(context.data_directory)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_parse_error
|
151
|
+
xp = XML::Parser.string('<foo><bar/></foz>')
|
152
|
+
|
153
|
+
assert_raise(XML::Error) do
|
154
|
+
xp.parse
|
155
|
+
end
|
156
|
+
|
157
|
+
# Now check context
|
158
|
+
context = xp.context
|
159
|
+
assert_equal(nil, context.data_directory)
|
160
|
+
assert_equal(0, context.depth)
|
161
|
+
assert_equal(true, context.disable_sax?)
|
162
|
+
assert_equal(false, context.docbook?)
|
163
|
+
assert_equal(XML::Encoding::NONE, context.encoding)
|
164
|
+
assert_equal(76, context.errno)
|
165
|
+
assert_equal(false, context.html?)
|
166
|
+
assert_equal(5, context.io_max_num_streams)
|
167
|
+
assert_equal(1, context.io_num_streams)
|
168
|
+
assert_equal(true, context.keep_blanks?)
|
169
|
+
assert_equal(1, context.io_num_streams)
|
170
|
+
assert_equal(nil, context.name_node)
|
171
|
+
assert_equal(0, context.name_depth)
|
172
|
+
assert_equal(10, context.name_depth_max)
|
173
|
+
assert_equal(17, context.num_chars)
|
174
|
+
assert_equal(false, context.replace_entities?)
|
175
|
+
assert_equal(1, context.space_depth)
|
176
|
+
assert_equal(10, context.space_depth_max)
|
177
|
+
assert_equal(false, context.subset_external?)
|
178
|
+
assert_equal(nil, context.subset_external_system_id)
|
179
|
+
assert_equal(nil, context.subset_external_uri)
|
180
|
+
assert_equal(false, context.subset_internal?)
|
181
|
+
assert_equal(nil, context.subset_internal_name)
|
182
|
+
assert_equal(false, context.stats?)
|
183
|
+
assert_equal(true, context.standalone?)
|
184
|
+
assert_equal(false, context.valid)
|
185
|
+
assert_equal(false, context.validate?)
|
186
|
+
assert_equal('1.0', context.version)
|
187
|
+
assert_equal(false, context.well_formed?)
|
188
|
+
end
|
189
|
+
end
|