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