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
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
require_relative './test_helper'
|
|
4
4
|
require 'stringio'
|
|
5
|
-
require 'test/unit'
|
|
6
5
|
|
|
7
6
|
class DocTypeCallback
|
|
8
|
-
include XML::SaxParser::Callbacks
|
|
7
|
+
include LibXML::XML::SaxParser::Callbacks
|
|
9
8
|
def on_start_element(element, attributes)
|
|
10
9
|
end
|
|
11
10
|
end
|
|
12
11
|
|
|
13
12
|
class TestCaseCallbacks
|
|
14
|
-
include XML::SaxParser::Callbacks
|
|
13
|
+
include LibXML::XML::SaxParser::Callbacks
|
|
15
14
|
|
|
16
15
|
attr_accessor :result
|
|
17
16
|
|
|
@@ -68,7 +67,7 @@ class TestCaseCallbacks
|
|
|
68
67
|
end
|
|
69
68
|
end
|
|
70
69
|
|
|
71
|
-
class TestSaxParser < Test
|
|
70
|
+
class TestSaxParser < Minitest::Test
|
|
72
71
|
def saxtest_file
|
|
73
72
|
File.join(File.dirname(__FILE__), 'model/atom.xml')
|
|
74
73
|
end
|
|
@@ -120,28 +119,28 @@ class TestSaxParser < Test::Unit::TestCase
|
|
|
120
119
|
end
|
|
121
120
|
|
|
122
121
|
def test_file
|
|
123
|
-
parser = XML::SaxParser.file(saxtest_file)
|
|
122
|
+
parser = LibXML::XML::SaxParser.file(saxtest_file)
|
|
124
123
|
parser.callbacks = TestCaseCallbacks.new
|
|
125
124
|
parser.parse
|
|
126
125
|
verify(parser)
|
|
127
126
|
end
|
|
128
127
|
|
|
129
128
|
def test_file_no_callbacks
|
|
130
|
-
parser = XML::SaxParser.file(saxtest_file)
|
|
129
|
+
parser = LibXML::XML::SaxParser.file(saxtest_file)
|
|
131
130
|
assert_equal true, parser.parse
|
|
132
131
|
end
|
|
133
132
|
|
|
134
133
|
def test_noexistent_file
|
|
135
|
-
error =
|
|
136
|
-
XML::SaxParser.file('i_dont_exist.xml')
|
|
134
|
+
error = assert_raises(LibXML::XML::Error) do
|
|
135
|
+
LibXML::XML::SaxParser.file('i_dont_exist.xml')
|
|
137
136
|
end
|
|
138
137
|
|
|
139
138
|
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
|
|
140
139
|
end
|
|
141
140
|
|
|
142
141
|
def test_nil_file
|
|
143
|
-
error =
|
|
144
|
-
XML::SaxParser.file(nil)
|
|
142
|
+
error = assert_raises(TypeError) do
|
|
143
|
+
LibXML::XML::SaxParser.file(nil)
|
|
145
144
|
end
|
|
146
145
|
|
|
147
146
|
assert_match(/nil into String/, error.to_s)
|
|
@@ -149,7 +148,7 @@ class TestSaxParser < Test::Unit::TestCase
|
|
|
149
148
|
|
|
150
149
|
def test_io
|
|
151
150
|
File.open(saxtest_file) do |file|
|
|
152
|
-
parser = XML::SaxParser.io(file)
|
|
151
|
+
parser = LibXML::XML::SaxParser.io(file)
|
|
153
152
|
parser.callbacks = TestCaseCallbacks.new
|
|
154
153
|
parser.parse
|
|
155
154
|
verify(parser)
|
|
@@ -157,8 +156,8 @@ class TestSaxParser < Test::Unit::TestCase
|
|
|
157
156
|
end
|
|
158
157
|
|
|
159
158
|
def test_nil_io
|
|
160
|
-
error =
|
|
161
|
-
XML::HTMLParser.io(nil)
|
|
159
|
+
error = assert_raises(TypeError) do
|
|
160
|
+
LibXML::XML::HTMLParser.io(nil)
|
|
162
161
|
end
|
|
163
162
|
|
|
164
163
|
assert_equal("Must pass in an IO object", error.to_s)
|
|
@@ -166,13 +165,13 @@ class TestSaxParser < Test::Unit::TestCase
|
|
|
166
165
|
|
|
167
166
|
def test_string_no_callbacks
|
|
168
167
|
xml = File.read(saxtest_file)
|
|
169
|
-
parser = XML::SaxParser.string(xml)
|
|
168
|
+
parser = LibXML::XML::SaxParser.string(xml)
|
|
170
169
|
assert_equal true, parser.parse
|
|
171
170
|
end
|
|
172
171
|
|
|
173
172
|
def test_string
|
|
174
173
|
xml = File.read(saxtest_file)
|
|
175
|
-
parser = XML::SaxParser.string(xml)
|
|
174
|
+
parser = LibXML::XML::SaxParser.string(xml)
|
|
176
175
|
parser.callbacks = TestCaseCallbacks.new
|
|
177
176
|
parser.parse
|
|
178
177
|
verify(parser)
|
|
@@ -181,7 +180,7 @@ class TestSaxParser < Test::Unit::TestCase
|
|
|
181
180
|
def test_string_io
|
|
182
181
|
xml = File.read(saxtest_file)
|
|
183
182
|
io = StringIO.new(xml)
|
|
184
|
-
parser = XML::SaxParser.io(io)
|
|
183
|
+
parser = LibXML::XML::SaxParser.io(io)
|
|
185
184
|
|
|
186
185
|
parser.callbacks = TestCaseCallbacks.new
|
|
187
186
|
parser.parse
|
|
@@ -189,8 +188,8 @@ class TestSaxParser < Test::Unit::TestCase
|
|
|
189
188
|
end
|
|
190
189
|
|
|
191
190
|
def test_nil_string
|
|
192
|
-
error =
|
|
193
|
-
XML::SaxParser.string(nil)
|
|
191
|
+
error = assert_raises(TypeError) do
|
|
192
|
+
LibXML::XML::SaxParser.string(nil)
|
|
194
193
|
end
|
|
195
194
|
|
|
196
195
|
assert_equal("wrong argument type nil (expected String)", error.to_s)
|
|
@@ -204,10 +203,10 @@ class TestSaxParser < Test::Unit::TestCase
|
|
|
204
203
|
<a>a1</a>
|
|
205
204
|
</Results>
|
|
206
205
|
EOS
|
|
207
|
-
parser = XML::SaxParser.string(xml)
|
|
206
|
+
parser = LibXML::XML::SaxParser.string(xml)
|
|
208
207
|
parser.callbacks = DocTypeCallback.new
|
|
209
208
|
doc = parser.parse
|
|
210
|
-
|
|
209
|
+
refute_nil(doc)
|
|
211
210
|
end
|
|
212
211
|
|
|
213
212
|
def test_parse_warning
|
|
@@ -218,7 +217,7 @@ EOS
|
|
|
218
217
|
<Test/>
|
|
219
218
|
EOS
|
|
220
219
|
|
|
221
|
-
parser = XML::SaxParser.string(xml)
|
|
220
|
+
parser = LibXML::XML::SaxParser.string(xml)
|
|
222
221
|
parser.callbacks = TestCaseCallbacks.new
|
|
223
222
|
|
|
224
223
|
parser.parse
|
|
@@ -240,11 +239,11 @@ EOS
|
|
|
240
239
|
xml = <<-EOS
|
|
241
240
|
<Results>
|
|
242
241
|
EOS
|
|
243
|
-
parser = XML::SaxParser.string(xml)
|
|
242
|
+
parser = LibXML::XML::SaxParser.string(xml)
|
|
244
243
|
parser.callbacks = TestCaseCallbacks.new
|
|
245
244
|
|
|
246
|
-
error =
|
|
247
|
-
|
|
245
|
+
error = assert_raises(LibXML::XML::Error) do
|
|
246
|
+
parser.parse
|
|
248
247
|
end
|
|
249
248
|
|
|
250
249
|
# Check callbacks
|
|
@@ -255,21 +254,21 @@ EOS
|
|
|
255
254
|
assert_equal("start_element: Results, attr: {}", result[i+=1])
|
|
256
255
|
assert_equal("start_element_ns: Results, attr: {}, prefix: , uri: , ns: {}", result[i+=1])
|
|
257
256
|
assert_equal("characters: \n", result[i+=1])
|
|
258
|
-
assert_equal("error: Fatal error:
|
|
257
|
+
assert_equal("error: Fatal error: EndTag: '</' not found at :2.", result[i+=1])
|
|
259
258
|
assert_equal("end_document", result[i+=1])
|
|
260
259
|
|
|
261
|
-
|
|
262
|
-
assert_kind_of(XML::Error, error)
|
|
263
|
-
assert_equal("Fatal error:
|
|
264
|
-
assert_equal(XML::Error::PARSER, error.domain)
|
|
265
|
-
assert_equal(XML::Error::
|
|
266
|
-
assert_equal(XML::Error::FATAL, error.level)
|
|
260
|
+
refute_nil(error)
|
|
261
|
+
assert_kind_of(LibXML::XML::Error, error)
|
|
262
|
+
assert_equal("Fatal error: EndTag: '</' not found at :2.", error.message)
|
|
263
|
+
assert_equal(LibXML::XML::Error::PARSER, error.domain)
|
|
264
|
+
assert_equal(LibXML::XML::Error::LTSLASH_REQUIRED, error.code)
|
|
265
|
+
assert_equal(LibXML::XML::Error::FATAL, error.level)
|
|
267
266
|
assert_nil(error.file)
|
|
268
267
|
assert_equal(2, error.line)
|
|
269
|
-
|
|
268
|
+
assert_nil(error.str1)
|
|
270
269
|
assert_nil(error.str2)
|
|
271
270
|
assert_nil(error.str3)
|
|
272
|
-
assert_equal(
|
|
271
|
+
assert_equal(0, error.int1)
|
|
273
272
|
assert_equal(1, error.int2)
|
|
274
273
|
assert_nil(error.node)
|
|
275
274
|
end
|
|
@@ -306,15 +305,15 @@ EOS
|
|
|
306
305
|
</Products>
|
|
307
306
|
EOS
|
|
308
307
|
|
|
309
|
-
parser = XML::SaxParser.string(xml)
|
|
308
|
+
parser = LibXML::XML::SaxParser.string(xml)
|
|
310
309
|
parser.callbacks = TestCaseCallbacks.new
|
|
311
310
|
|
|
312
|
-
error =
|
|
311
|
+
error = assert_raises(LibXML::XML::Error) do
|
|
313
312
|
parser.parse
|
|
314
313
|
end
|
|
315
314
|
assert_equal("Fatal error: xmlParseEntityRef: no name at :5.", error.to_s)
|
|
316
315
|
|
|
317
316
|
# Check callbacks
|
|
318
|
-
|
|
317
|
+
parser.callbacks.result
|
|
319
318
|
end
|
|
320
319
|
end
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# encoding: UTF-8
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
require 'test/unit'
|
|
3
|
+
require_relative './test_helper'
|
|
5
4
|
|
|
6
|
-
class TestSchema < Test
|
|
5
|
+
class TestSchema < Minitest::Test
|
|
7
6
|
def setup
|
|
8
7
|
file = File.join(File.dirname(__FILE__), 'model/shiporder.xml')
|
|
9
|
-
@doc = XML::Document.file(file)
|
|
8
|
+
@doc = LibXML::XML::Document.file(file)
|
|
10
9
|
end
|
|
11
10
|
|
|
12
11
|
def teardown
|
|
@@ -14,17 +13,17 @@ class TestSchema < Test::Unit::TestCase
|
|
|
14
13
|
end
|
|
15
14
|
|
|
16
15
|
def schema
|
|
17
|
-
document = XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xsd'))
|
|
18
|
-
XML::Schema.document(document)
|
|
16
|
+
document = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/shiporder.xsd'))
|
|
17
|
+
LibXML::XML::Schema.document(document)
|
|
19
18
|
end
|
|
20
19
|
|
|
21
20
|
def check_error(error)
|
|
22
|
-
|
|
21
|
+
refute_nil(error)
|
|
23
22
|
assert(error.message.match(/Error: Element 'invalid': This element is not expected. Expected is \( item \)/))
|
|
24
|
-
assert_kind_of(XML::Error, error)
|
|
25
|
-
assert_equal(XML::Error::SCHEMASV, error.domain)
|
|
26
|
-
assert_equal(XML::Error::SCHEMAV_ELEMENT_CONTENT, error.code)
|
|
27
|
-
assert_equal(XML::Error::ERROR, error.level)
|
|
23
|
+
assert_kind_of(LibXML::XML::Error, error)
|
|
24
|
+
assert_equal(LibXML::XML::Error::SCHEMASV, error.domain)
|
|
25
|
+
assert_equal(LibXML::XML::Error::SCHEMAV_ELEMENT_CONTENT, error.code)
|
|
26
|
+
assert_equal(LibXML::XML::Error::ERROR, error.level)
|
|
28
27
|
assert(error.file.match(/shiporder.xml/)) if error.file
|
|
29
28
|
assert_nil(error.str1)
|
|
30
29
|
assert_nil(error.str2)
|
|
@@ -34,7 +33,7 @@ class TestSchema < Test::Unit::TestCase
|
|
|
34
33
|
end
|
|
35
34
|
|
|
36
35
|
def test_load_from_doc
|
|
37
|
-
assert_instance_of(XML::Schema, schema)
|
|
36
|
+
assert_instance_of(LibXML::XML::Schema, schema)
|
|
38
37
|
end
|
|
39
38
|
|
|
40
39
|
def test_doc_valid
|
|
@@ -42,21 +41,21 @@ class TestSchema < Test::Unit::TestCase
|
|
|
42
41
|
end
|
|
43
42
|
|
|
44
43
|
def test_doc_invalid
|
|
45
|
-
new_node = XML::Node.new('invalid', 'this will mess up validation')
|
|
44
|
+
new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation')
|
|
46
45
|
@doc.root << new_node
|
|
47
46
|
|
|
48
|
-
error =
|
|
47
|
+
error = assert_raises(LibXML::XML::Error) do
|
|
49
48
|
@doc.validate_schema(schema)
|
|
50
49
|
end
|
|
51
50
|
|
|
52
51
|
check_error(error)
|
|
53
52
|
assert_nil(error.line)
|
|
54
|
-
|
|
53
|
+
refute_nil(error.node)
|
|
55
54
|
assert_equal('invalid', error.node.name)
|
|
56
55
|
end
|
|
57
56
|
|
|
58
57
|
def test_reader_valid
|
|
59
|
-
reader = XML::Reader.string(@doc.to_s)
|
|
58
|
+
reader = LibXML::XML::Reader.string(@doc.to_s)
|
|
60
59
|
assert(reader.schema_validate(schema))
|
|
61
60
|
|
|
62
61
|
while reader.read
|
|
@@ -66,13 +65,13 @@ class TestSchema < Test::Unit::TestCase
|
|
|
66
65
|
def test_reader_invalid
|
|
67
66
|
# Set error handler
|
|
68
67
|
errors = Array.new
|
|
69
|
-
XML::Error.set_handler do |error|
|
|
68
|
+
LibXML::XML::Error.set_handler do |error|
|
|
70
69
|
errors << error
|
|
71
70
|
end
|
|
72
71
|
|
|
73
|
-
new_node = XML::Node.new('invalid', 'this will mess up validation')
|
|
72
|
+
new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation')
|
|
74
73
|
@doc.root << new_node
|
|
75
|
-
reader = XML::Reader.string(@doc.to_s)
|
|
74
|
+
reader = LibXML::XML::Reader.string(@doc.to_s)
|
|
76
75
|
|
|
77
76
|
# Set a schema
|
|
78
77
|
assert(reader.schema_validate(schema))
|
|
@@ -86,35 +85,45 @@ class TestSchema < Test::Unit::TestCase
|
|
|
86
85
|
check_error(error)
|
|
87
86
|
assert_equal(21, error.line)
|
|
88
87
|
ensure
|
|
89
|
-
XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
|
|
88
|
+
LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
|
|
90
89
|
end
|
|
91
90
|
|
|
92
91
|
|
|
93
92
|
# Schema meta-data tests
|
|
94
|
-
|
|
95
93
|
def test_elements
|
|
96
94
|
assert_instance_of(Hash, schema.elements)
|
|
97
95
|
assert_equal(1, schema.elements.length)
|
|
98
|
-
assert_instance_of(XML::Schema::Element, schema.elements['shiporder'])
|
|
96
|
+
assert_instance_of(LibXML::XML::Schema::Element, schema.elements['shiporder'])
|
|
99
97
|
end
|
|
100
98
|
|
|
101
99
|
def test_types
|
|
102
100
|
assert_instance_of(Hash, schema.types)
|
|
103
101
|
assert_equal(1, schema.types.length)
|
|
104
|
-
assert_instance_of(XML::Schema::Type, schema.types['shiporder'])
|
|
102
|
+
assert_instance_of(LibXML::XML::Schema::Type, schema.types['shiporder'])
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_imported_types
|
|
106
|
+
assert_instance_of(Hash, schema.imported_types)
|
|
107
|
+
assert_equal(1, schema.imported_types.length)
|
|
108
|
+
assert_instance_of(LibXML::XML::Schema::Type, schema.types['shiporder'])
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def test_namespaces
|
|
112
|
+
assert_instance_of(Array, schema.namespaces)
|
|
113
|
+
assert_equal(1, schema.namespaces.length)
|
|
105
114
|
end
|
|
106
115
|
|
|
107
116
|
def test_schema_type
|
|
108
117
|
type = schema.types['shiporder']
|
|
109
118
|
|
|
110
119
|
assert_equal('shiporder', type.name)
|
|
111
|
-
|
|
120
|
+
assert_nil(type.namespace)
|
|
112
121
|
assert_equal("Shiporder type documentation", type.annotation)
|
|
113
|
-
assert_instance_of(XML::Node, type.node)
|
|
114
|
-
assert_equal(XML::Schema::Types::XML_SCHEMA_TYPE_COMPLEX, type.kind)
|
|
115
|
-
assert_instance_of(XML::Schema::Type, type.base)
|
|
122
|
+
assert_instance_of(LibXML::XML::Node, type.node)
|
|
123
|
+
assert_equal(LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_COMPLEX, type.kind)
|
|
124
|
+
assert_instance_of(LibXML::XML::Schema::Type, type.base)
|
|
116
125
|
assert_equal("anyType", type.base.name)
|
|
117
|
-
assert_equal(XML::Schema::Types::XML_SCHEMA_TYPE_BASIC, type.base.kind)
|
|
126
|
+
assert_equal(LibXML::XML::Schema::Types::XML_SCHEMA_TYPE_BASIC, type.base.kind)
|
|
118
127
|
|
|
119
128
|
assert_instance_of(Hash, type.elements)
|
|
120
129
|
assert_equal(3, type.elements.length)
|
|
@@ -124,17 +133,14 @@ class TestSchema < Test::Unit::TestCase
|
|
|
124
133
|
element = schema.types['shiporder'].elements['orderperson']
|
|
125
134
|
|
|
126
135
|
assert_equal('orderperson', element.name)
|
|
127
|
-
|
|
136
|
+
assert_nil(element.namespace)
|
|
128
137
|
assert_equal("orderperson element documentation", element.annotation)
|
|
129
|
-
assert_equal(1, element.min_occurs)
|
|
130
|
-
assert_equal(1, element.max_occurs)
|
|
131
|
-
|
|
132
138
|
|
|
133
139
|
element = schema.types['shiporder'].elements['item']
|
|
134
|
-
assert_equal(
|
|
140
|
+
assert_equal('item', element.name)
|
|
135
141
|
|
|
136
142
|
element = schema.types['shiporder'].elements['item'].type.elements['note']
|
|
137
|
-
assert_equal(
|
|
143
|
+
assert_equal('note', element.name)
|
|
138
144
|
assert_equal('string', element.type.name)
|
|
139
145
|
end
|
|
140
146
|
|
|
@@ -143,14 +149,14 @@ class TestSchema < Test::Unit::TestCase
|
|
|
143
149
|
|
|
144
150
|
assert_instance_of(Array, type.attributes)
|
|
145
151
|
assert_equal(2, type.attributes.length)
|
|
146
|
-
assert_instance_of(XML::Schema::Attribute, type.attributes.first)
|
|
152
|
+
assert_instance_of(LibXML::XML::Schema::Attribute, type.attributes.first)
|
|
147
153
|
end
|
|
148
154
|
|
|
149
155
|
def test_schema_attribute
|
|
150
156
|
attribute = schema.types['shiporder'].attributes.first
|
|
151
157
|
|
|
152
158
|
assert_equal("orderid", attribute.name)
|
|
153
|
-
|
|
159
|
+
assert_nil(attribute.namespace)
|
|
154
160
|
assert_equal(1, attribute.occurs)
|
|
155
161
|
assert_equal('string', attribute.type.name)
|
|
156
162
|
|
|
@@ -159,4 +165,4 @@ class TestSchema < Test::Unit::TestCase
|
|
|
159
165
|
assert_equal('1', attribute.default)
|
|
160
166
|
assert_equal('integer', attribute.type.name)
|
|
161
167
|
end
|
|
162
|
-
end
|
|
168
|
+
end
|
data/test/test_suite.rb
CHANGED
|
@@ -5,46 +5,44 @@
|
|
|
5
5
|
dir = File.dirname(__FILE__)
|
|
6
6
|
Dir.chdir(dir)
|
|
7
7
|
|
|
8
|
-
require './
|
|
9
|
-
require './
|
|
10
|
-
require './
|
|
11
|
-
require './
|
|
12
|
-
require './
|
|
13
|
-
require './
|
|
14
|
-
require './
|
|
15
|
-
require './
|
|
16
|
-
require './
|
|
17
|
-
require './
|
|
18
|
-
require './
|
|
19
|
-
require './
|
|
20
|
-
require './
|
|
21
|
-
require './
|
|
22
|
-
require './
|
|
23
|
-
require './
|
|
24
|
-
require './
|
|
25
|
-
require './
|
|
26
|
-
require './
|
|
27
|
-
require './
|
|
28
|
-
require './
|
|
29
|
-
require './
|
|
30
|
-
require './
|
|
31
|
-
require './
|
|
32
|
-
require './
|
|
33
|
-
require './
|
|
34
|
-
require './
|
|
35
|
-
require './
|
|
36
|
-
require './
|
|
37
|
-
require './
|
|
38
|
-
require './
|
|
39
|
-
require './
|
|
40
|
-
require './
|
|
41
|
-
require './
|
|
8
|
+
require './test_attr'
|
|
9
|
+
require './test_attr_decl'
|
|
10
|
+
require './test_attributes'
|
|
11
|
+
require './test_canonicalize'
|
|
12
|
+
require './test_document'
|
|
13
|
+
require './test_document_write'
|
|
14
|
+
require './test_dtd'
|
|
15
|
+
require './test_error'
|
|
16
|
+
require './test_html_parser'
|
|
17
|
+
require './test_html_parser_context'
|
|
18
|
+
require './test_namespace'
|
|
19
|
+
require './test_namespaces'
|
|
20
|
+
require './test_node'
|
|
21
|
+
require './test_node_cdata'
|
|
22
|
+
require './test_node_comment'
|
|
23
|
+
require './test_node_copy'
|
|
24
|
+
require './test_node_edit'
|
|
25
|
+
require './test_node_pi'
|
|
26
|
+
require './test_node_text'
|
|
27
|
+
require './test_node_write'
|
|
28
|
+
require './test_node_xlink'
|
|
29
|
+
require './test_parser'
|
|
30
|
+
require './test_parser_context'
|
|
31
|
+
require './test_reader'
|
|
32
|
+
require './test_relaxng'
|
|
33
|
+
require './test_sax_parser'
|
|
34
|
+
require './test_schema'
|
|
35
|
+
require './test_traversal'
|
|
36
|
+
require './test_writer'
|
|
37
|
+
require './test_xinclude'
|
|
38
|
+
require './test_xpath'
|
|
39
|
+
require './test_xpath_context'
|
|
40
|
+
require './test_xpath_expression'
|
|
41
|
+
require './test_xpointer'
|
|
42
42
|
|
|
43
|
+
require './test_encoding'
|
|
44
|
+
require './test_encoding_sax'
|
|
43
45
|
|
|
44
|
-
if defined?(Encoding)
|
|
45
|
-
require './tc_encoding'
|
|
46
|
-
require './tc_encoding_sax'
|
|
47
|
-
end
|
|
48
46
|
# Compatibility
|
|
49
|
-
require './
|
|
50
|
-
require './
|
|
47
|
+
require './test_properties'
|
|
48
|
+
require './test_deprecated_require'
|