libxml-ruby 3.0.0 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/HISTORY +37 -0
- data/MANIFEST +34 -34
- data/README.rdoc +65 -36
- data/Rakefile +21 -3
- data/ext/libxml/extconf.rb +30 -26
- data/ext/libxml/ruby_libxml.h +0 -8
- data/ext/libxml/ruby_xml.c +40 -0
- data/ext/libxml/ruby_xml_document.c +1 -5
- data/ext/libxml/ruby_xml_dtd.c +6 -8
- data/ext/libxml/ruby_xml_encoding.c +1 -13
- data/ext/libxml/ruby_xml_encoding.h +0 -3
- data/ext/libxml/ruby_xml_error.c +1 -1
- data/ext/libxml/ruby_xml_error.h +1 -1
- data/ext/libxml/ruby_xml_io.c +14 -18
- data/ext/libxml/ruby_xml_io.h +1 -1
- data/ext/libxml/ruby_xml_node.c +16 -17
- data/ext/libxml/ruby_xml_parser_context.c +1 -1
- data/ext/libxml/ruby_xml_reader.c +7 -2
- data/ext/libxml/ruby_xml_schema.c +44 -66
- data/ext/libxml/ruby_xml_schema_element.c +15 -14
- data/ext/libxml/ruby_xml_schema_type.c +66 -93
- data/ext/libxml/ruby_xml_version.h +4 -4
- data/ext/libxml/ruby_xml_writer.c +189 -192
- data/lib/libxml/schema/element.rb +0 -8
- data/lib/libxml/schema/type.rb +0 -8
- data/lib/libxml/schema.rb +0 -19
- data/lib/libxml-ruby.rb +30 -0
- data/lib/libxml.rb +3 -28
- data/libxml-ruby.gemspec +5 -4
- data/setup.rb +0 -1
- data/test/model/cwm_1_0.xml +11336 -0
- data/test/{tc_attr.rb → test_attr.rb} +18 -18
- data/test/{tc_attr_decl.rb → test_attr_decl.rb} +8 -8
- data/test/{tc_attributes.rb → test_attributes.rb} +10 -10
- data/test/{tc_canonicalize.rb → test_canonicalize.rb} +35 -39
- data/test/test_deprecated_require.rb +12 -0
- data/test/{tc_document.rb → test_document.rb} +31 -24
- data/test/test_document_write.rb +146 -0
- data/test/{tc_dtd.rb → test_dtd.rb} +26 -25
- data/test/{tc_encoding.rb → test_encoding.rb} +20 -17
- data/test/{tc_encoding_sax.rb → test_encoding_sax.rb} +3 -3
- data/test/test_error.rb +178 -0
- data/test/test_helper.rb +4 -11
- data/test/{tc_html_parser.rb → test_html_parser.rb} +31 -30
- data/test/test_html_parser_context.rb +23 -0
- data/test/test_namespace.rb +60 -0
- data/test/{tc_namespaces.rb → test_namespaces.rb} +29 -38
- data/test/{tc_node.rb → test_node.rb} +37 -31
- data/test/{tc_node_cdata.rb → test_node_cdata.rb} +10 -10
- data/test/{tc_node_comment.rb → test_node_comment.rb} +6 -6
- data/test/{tc_node_copy.rb → test_node_copy.rb} +3 -4
- data/test/{tc_node_edit.rb → test_node_edit.rb} +20 -21
- data/test/{tc_node_pi.rb → test_node_pi.rb} +8 -10
- data/test/{tc_node_text.rb → test_node_text.rb} +8 -9
- data/test/{tc_node_write.rb → test_node_write.rb} +16 -26
- data/test/test_node_xlink.rb +28 -0
- data/test/{tc_parser.rb → test_parser.rb} +72 -75
- data/test/{tc_parser_context.rb → test_parser_context.rb} +38 -44
- data/test/{tc_properties.rb → test_properties.rb} +5 -5
- data/test/test_reader.rb +364 -0
- data/test/{tc_relaxng.rb → test_relaxng.rb} +11 -11
- data/test/{tc_sax_parser.rb → test_sax_parser.rb} +38 -31
- data/test/{tc_schema.rb → test_schema.rb} +40 -33
- data/test/test_suite.rb +39 -40
- data/test/{tc_traversal.rb → test_traversal.rb} +4 -4
- data/test/{tc_writer.rb → test_writer.rb} +95 -74
- data/test/{tc_xinclude.rb → test_xinclude.rb} +3 -3
- data/test/test_xml.rb +263 -0
- data/test/{tc_xpath.rb → test_xpath.rb} +25 -25
- data/test/{tc_xpath_context.rb → test_xpath_context.rb} +5 -5
- data/test/{tc_xpath_expression.rb → test_xpath_expression.rb} +7 -7
- data/test/{tc_xpointer.rb → test_xpointer.rb} +15 -15
- metadata +91 -102
- data/test/tc_deprecated_require.rb +0 -12
- data/test/tc_document_write.rb +0 -195
- data/test/tc_error.rb +0 -178
- data/test/tc_html_parser_context.rb +0 -23
- data/test/tc_namespace.rb +0 -61
- data/test/tc_node_xlink.rb +0 -28
- data/test/tc_reader.rb +0 -358
- data/test/tc_xml.rb +0 -225
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
require_relative './test_helper'
|
4
4
|
require 'stringio'
|
5
5
|
|
6
6
|
class HTMLParserTest < Minitest::Test
|
@@ -10,15 +10,15 @@ class HTMLParserTest < Minitest::Test
|
|
10
10
|
|
11
11
|
# ----- Sources ------
|
12
12
|
def test_file
|
13
|
-
xp = XML::HTMLParser.file(html_file)
|
14
|
-
assert_instance_of(XML::HTMLParser, xp)
|
13
|
+
xp = LibXML::XML::HTMLParser.file(html_file)
|
14
|
+
assert_instance_of(LibXML::XML::HTMLParser, xp)
|
15
15
|
doc = xp.parse
|
16
16
|
refute_nil(doc)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_noexistent_file
|
20
|
-
error = assert_raises(XML::Error) do
|
21
|
-
XML::HTMLParser.file('i_dont_exist.xml')
|
20
|
+
error = assert_raises(LibXML::XML::Error) do
|
21
|
+
LibXML::XML::HTMLParser.file('i_dont_exist.xml')
|
22
22
|
end
|
23
23
|
|
24
24
|
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
|
@@ -26,7 +26,7 @@ class HTMLParserTest < Minitest::Test
|
|
26
26
|
|
27
27
|
def test_nil_file
|
28
28
|
error = assert_raises(TypeError) do
|
29
|
-
XML::HTMLParser.file(nil)
|
29
|
+
LibXML::XML::HTMLParser.file(nil)
|
30
30
|
end
|
31
31
|
|
32
32
|
assert_match(/nil into String/, error.to_s)
|
@@ -34,11 +34,11 @@ class HTMLParserTest < Minitest::Test
|
|
34
34
|
|
35
35
|
def test_io
|
36
36
|
File.open(html_file) do |io|
|
37
|
-
xp = XML::HTMLParser.io(io)
|
38
|
-
assert_instance_of(XML::HTMLParser, xp)
|
37
|
+
xp = LibXML::XML::HTMLParser.io(io)
|
38
|
+
assert_instance_of(LibXML::XML::HTMLParser, xp)
|
39
39
|
|
40
40
|
doc = xp.parse
|
41
|
-
assert_instance_of(XML::Document, doc)
|
41
|
+
assert_instance_of(LibXML::XML::Document, doc)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -46,7 +46,7 @@ class HTMLParserTest < Minitest::Test
|
|
46
46
|
# Test that the reader keeps a reference
|
47
47
|
# to the io object
|
48
48
|
file = File.open(html_file)
|
49
|
-
parser = XML::HTMLParser.io(file)
|
49
|
+
parser = LibXML::XML::HTMLParser.io(file)
|
50
50
|
file = nil
|
51
51
|
GC.start
|
52
52
|
assert(parser.parse)
|
@@ -54,7 +54,7 @@ class HTMLParserTest < Minitest::Test
|
|
54
54
|
|
55
55
|
def test_nil_io
|
56
56
|
error = assert_raises(TypeError) do
|
57
|
-
XML::HTMLParser.io(nil)
|
57
|
+
LibXML::XML::HTMLParser.io(nil)
|
58
58
|
end
|
59
59
|
|
60
60
|
assert_equal("Must pass in an IO object", error.to_s)
|
@@ -63,27 +63,27 @@ class HTMLParserTest < Minitest::Test
|
|
63
63
|
def test_string_io
|
64
64
|
data = File.read(html_file)
|
65
65
|
io = StringIO.new(data)
|
66
|
-
xp = XML::HTMLParser.io(io)
|
67
|
-
assert_instance_of(XML::HTMLParser, xp)
|
66
|
+
xp = LibXML::XML::HTMLParser.io(io)
|
67
|
+
assert_instance_of(LibXML::XML::HTMLParser, xp)
|
68
68
|
|
69
69
|
doc = xp.parse
|
70
|
-
assert_instance_of(XML::Document, doc)
|
70
|
+
assert_instance_of(LibXML::XML::Document, doc)
|
71
71
|
end
|
72
72
|
|
73
73
|
def test_string
|
74
74
|
str = '<html><body><p>hi</p></body></html>'
|
75
|
-
xp = XML::HTMLParser.string(str)
|
75
|
+
xp = LibXML::XML::HTMLParser.string(str)
|
76
76
|
|
77
|
-
assert_instance_of(XML::HTMLParser, xp)
|
78
|
-
assert_instance_of(XML::HTMLParser, xp)
|
77
|
+
assert_instance_of(LibXML::XML::HTMLParser, xp)
|
78
|
+
assert_instance_of(LibXML::XML::HTMLParser, xp)
|
79
79
|
|
80
80
|
doc = xp.parse
|
81
|
-
assert_instance_of(XML::Document, doc)
|
81
|
+
assert_instance_of(LibXML::XML::Document, doc)
|
82
82
|
end
|
83
83
|
|
84
84
|
def test_nil_string
|
85
85
|
error = assert_raises(TypeError) do
|
86
|
-
XML::HTMLParser.string(nil)
|
86
|
+
LibXML::XML::HTMLParser.string(nil)
|
87
87
|
end
|
88
88
|
|
89
89
|
assert_equal("wrong argument type nil (expected String)", error.to_s)
|
@@ -98,26 +98,26 @@ class HTMLParserTest < Minitest::Test
|
|
98
98
|
<body>Hello<br>World</html>
|
99
99
|
EOS
|
100
100
|
|
101
|
-
parser = XML::HTMLParser.string(html, :options => XML::HTMLParser::Options::NOBLANKS)
|
101
|
+
parser = LibXML::XML::HTMLParser.string(html, :options => LibXML::XML::HTMLParser::Options::NOBLANKS)
|
102
102
|
doc = parser.parse
|
103
|
-
assert_instance_of XML::Document, doc
|
103
|
+
assert_instance_of LibXML::XML::Document, doc
|
104
104
|
|
105
105
|
root = doc.root
|
106
|
-
assert_instance_of XML::Node, root
|
106
|
+
assert_instance_of LibXML::XML::Node, root
|
107
107
|
assert_equal 'html', root.name
|
108
108
|
|
109
109
|
head = root.child
|
110
|
-
assert_instance_of XML::Node, head
|
110
|
+
assert_instance_of LibXML::XML::Node, head
|
111
111
|
assert_equal 'head', head.name
|
112
112
|
|
113
113
|
meta = head.child
|
114
|
-
assert_instance_of XML::Node, meta
|
114
|
+
assert_instance_of LibXML::XML::Node, meta
|
115
115
|
assert_equal 'meta', meta.name
|
116
116
|
assert_equal 'keywords', meta[:name]
|
117
117
|
assert_equal 'nasty', meta[:content]
|
118
118
|
|
119
119
|
body = head.next
|
120
|
-
assert_instance_of XML::Node, body
|
120
|
+
assert_instance_of LibXML::XML::Node, body
|
121
121
|
assert_equal 'body', body.name
|
122
122
|
|
123
123
|
hello = body.child
|
@@ -125,21 +125,21 @@ class HTMLParserTest < Minitest::Test
|
|
125
125
|
# cant figure our why or how, so this skips it if there
|
126
126
|
hello = hello.child if hello.name == "p"
|
127
127
|
|
128
|
-
assert_instance_of XML::Node, hello
|
128
|
+
assert_instance_of LibXML::XML::Node, hello
|
129
129
|
assert_equal 'Hello', hello.content
|
130
130
|
|
131
131
|
br = hello.next
|
132
|
-
assert_instance_of XML::Node, br
|
132
|
+
assert_instance_of LibXML::XML::Node, br
|
133
133
|
assert_equal 'br', br.name
|
134
134
|
|
135
135
|
world = br.next
|
136
|
-
assert_instance_of XML::Node, world
|
136
|
+
assert_instance_of LibXML::XML::Node, world
|
137
137
|
assert_equal 'World', world.content
|
138
138
|
end
|
139
139
|
|
140
140
|
def test_no_implied
|
141
141
|
html = "hello world"
|
142
|
-
parser = XML::HTMLParser.string(html, :options => XML::HTMLParser::Options::NOIMPLIED)
|
142
|
+
parser = LibXML::XML::HTMLParser.string(html, :options => LibXML::XML::HTMLParser::Options::NOIMPLIED)
|
143
143
|
doc = parser.parse
|
144
144
|
assert_equal("<p>#{html}</p>", doc.root.to_s)
|
145
145
|
end
|
@@ -154,8 +154,9 @@ class HTMLParserTest < Minitest::Test
|
|
154
154
|
end
|
155
155
|
|
156
156
|
def test_open_many_files
|
157
|
+
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/ruby-lang.html'))
|
157
158
|
1000.times do
|
158
|
-
|
159
|
+
LibXML::XML::HTMLParser.file(file).parse
|
159
160
|
end
|
160
161
|
end
|
161
162
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative './test_helper'
|
4
|
+
|
5
|
+
|
6
|
+
class TestHtmlParserContext < Minitest::Test
|
7
|
+
def test_default_options
|
8
|
+
context = LibXML::XML::HTMLParser::Context.new
|
9
|
+
assert_equal(0, context.options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_no_options
|
13
|
+
context = LibXML::XML::HTMLParser::Context.new
|
14
|
+
context.options = 0
|
15
|
+
assert_equal(0, context.options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_options
|
19
|
+
context = LibXML::XML::HTMLParser::Context.new
|
20
|
+
context.options = LibXML::XML::HTMLParser::Options::NOERROR
|
21
|
+
assert_equal(LibXML::XML::HTMLParser::Options::NOERROR, context.options)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative './test_helper'
|
4
|
+
|
5
|
+
|
6
|
+
class TestNS < Minitest::Test
|
7
|
+
def setup
|
8
|
+
file = File.join(File.dirname(__FILE__), 'model/soap.xml')
|
9
|
+
@doc = LibXML::XML::Document.file(file)
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
@doc = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_create_ns
|
17
|
+
node = LibXML::XML::Node.new('foo')
|
18
|
+
ns = LibXML::XML::Namespace.new(node, 'my_namepace', 'http://www.mynamespace.com')
|
19
|
+
assert_equal(ns.prefix, 'my_namepace')
|
20
|
+
assert_equal(ns.href, 'http://www.mynamespace.com')
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_create_default_ns
|
24
|
+
node = LibXML::XML::Node.new('foo')
|
25
|
+
ns = LibXML::XML::Namespace.new(node, nil, 'http://www.mynamespace.com')
|
26
|
+
assert_nil(ns.prefix)
|
27
|
+
assert_equal(ns.href, 'http://www.mynamespace.com')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_create_unbound_ns
|
31
|
+
error = assert_raises(TypeError) do
|
32
|
+
LibXML::XML::Namespace.new(nil, 'my_namepace', 'http://www.mynamespace.com')
|
33
|
+
end
|
34
|
+
assert_equal('wrong argument type nil (expected Data)', error.to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_duplicate_ns
|
38
|
+
node = LibXML::XML::Node.new('foo')
|
39
|
+
LibXML::XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
|
40
|
+
assert_raises(LibXML::XML::Error) do
|
41
|
+
LibXML::XML::Namespace.new(node, 'myname', 'http://www.mynamespace.com')
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_eql
|
46
|
+
node = LibXML::XML::Node.new('Envelope')
|
47
|
+
|
48
|
+
assert(node.namespaces.namespace.eql?(node.namespaces.namespace))
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_equal
|
52
|
+
node1 = LibXML::XML::Node.new('Envelope')
|
53
|
+
ns1 = LibXML::XML::Namespace.new(node1, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
54
|
+
|
55
|
+
node2 = LibXML::XML::Node.new('Envelope')
|
56
|
+
ns2 = LibXML::XML::Namespace.new(node2, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
57
|
+
|
58
|
+
assert(ns1 == ns2)
|
59
|
+
end
|
60
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
require_relative './test_helper'
|
4
4
|
|
5
5
|
|
6
6
|
class TestNamespaces < Minitest::Test
|
7
7
|
def setup
|
8
8
|
file = File.join(File.dirname(__FILE__), 'model/soap.xml')
|
9
|
-
@doc = XML::Document.file(file)
|
9
|
+
@doc = LibXML::XML::Document.file(file)
|
10
10
|
end
|
11
11
|
|
12
12
|
def teardown
|
@@ -28,10 +28,10 @@ class TestNamespaces < Minitest::Test
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def test_set_namespace_node
|
31
|
-
node = XML::Node.new('Envelope')
|
31
|
+
node = LibXML::XML::Node.new('Envelope')
|
32
32
|
assert_equal('<Envelope/>', node.to_s)
|
33
33
|
|
34
|
-
ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
34
|
+
ns = LibXML::XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
35
35
|
assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
36
36
|
assert_nil(node.namespaces.namespace)
|
37
37
|
|
@@ -43,16 +43,16 @@ class TestNamespaces < Minitest::Test
|
|
43
43
|
|
44
44
|
def test_set_namespace_attribute
|
45
45
|
# Create node
|
46
|
-
node = XML::Node.new('Envelope')
|
46
|
+
node = LibXML::XML::Node.new('Envelope')
|
47
47
|
assert_equal('<Envelope/>', node.to_s)
|
48
48
|
|
49
49
|
# Create attribute
|
50
|
-
attr = XML::Attr.new(node, "encodingStyle", "http://www.w3.org/2001/12/soap-encoding")
|
50
|
+
attr = LibXML::XML::Attr.new(node, "encodingStyle", "http://www.w3.org/2001/12/soap-encoding")
|
51
51
|
assert_equal('<Envelope encodingStyle="http://www.w3.org/2001/12/soap-encoding"/>',
|
52
52
|
node.to_s)
|
53
53
|
|
54
54
|
# Create namespace attribute
|
55
|
-
ns = XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
55
|
+
ns = LibXML::XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
56
56
|
assert_equal('<Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" encodingStyle="http://www.w3.org/2001/12/soap-encoding"/>',
|
57
57
|
node.to_s)
|
58
58
|
assert_nil(node.namespaces.namespace)
|
@@ -71,19 +71,19 @@ class TestNamespaces < Minitest::Test
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def test_define_namespace
|
74
|
-
node = XML::Node.new('Envelope')
|
74
|
+
node = LibXML::XML::Node.new('Envelope')
|
75
75
|
assert_equal('<Envelope/>', node.to_s)
|
76
76
|
|
77
|
-
XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
77
|
+
LibXML::XML::Namespace.new(node, 'soap', 'http://schemas.xmlsoap.org/soap/envelope/')
|
78
78
|
assert_equal("<Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
79
79
|
assert_nil(node.namespaces.namespace)
|
80
80
|
end
|
81
81
|
|
82
82
|
def test_define_default_namespace
|
83
|
-
node = XML::Node.new('Envelope')
|
83
|
+
node = LibXML::XML::Node.new('Envelope')
|
84
84
|
assert_equal('<Envelope/>', node.to_s)
|
85
85
|
|
86
|
-
XML::Namespace.new(node, nil, 'http://schemas.xmlsoap.org/soap/envelope/')
|
86
|
+
LibXML::XML::Namespace.new(node, nil, 'http://schemas.xmlsoap.org/soap/envelope/')
|
87
87
|
assert_equal("<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\"/>", node.to_s)
|
88
88
|
# This seems wrong, but appears to be the way libxml works
|
89
89
|
assert_nil(node.namespaces.namespace)
|
@@ -97,56 +97,47 @@ class TestNamespaces < Minitest::Test
|
|
97
97
|
assert_equal(5, namespaces.length)
|
98
98
|
|
99
99
|
namespace = namespaces[0]
|
100
|
-
assert_instance_of(XML::Namespace, namespace)
|
101
|
-
|
100
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
101
|
+
assert_nil(namespace.prefix)
|
102
102
|
assert_equal('http://services.somewhere.com', namespace.href)
|
103
103
|
|
104
104
|
namespace = namespaces[1]
|
105
|
-
assert_instance_of(XML::Namespace, namespace)
|
105
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
106
106
|
assert_equal('ns1', namespace.prefix)
|
107
107
|
assert_equal('http://domain.somewhere.com', namespace.href)
|
108
108
|
|
109
109
|
namespace = namespaces[2]
|
110
|
-
assert_instance_of(XML::Namespace, namespace)
|
110
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
111
111
|
assert_equal('soap', namespace.prefix)
|
112
112
|
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
113
113
|
|
114
114
|
namespace = namespaces[3]
|
115
|
-
assert_instance_of(XML::Namespace, namespace)
|
115
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
116
116
|
assert_equal('xsd', namespace.prefix)
|
117
117
|
assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
|
118
118
|
|
119
119
|
namespace = namespaces[4]
|
120
|
-
assert_instance_of(XML::Namespace, namespace)
|
120
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
121
121
|
assert_equal('xsi', namespace.prefix)
|
122
122
|
assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
|
123
123
|
end
|
124
124
|
|
125
|
-
def test_namespaces
|
126
|
-
node = @doc.find_first('//ns1:IdAndName',
|
127
|
-
:ns1 => 'http://domain.somewhere.com')
|
128
|
-
|
129
|
-
node.namespaces.each do |namespace|
|
130
|
-
assert_instance_of(XML::Namespace, namespace)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
125
|
def test_namespace_definitions
|
135
126
|
ns_defs = @doc.root.namespaces.definitions
|
136
127
|
assert_equal(3, ns_defs.size)
|
137
128
|
|
138
129
|
namespace = ns_defs[0]
|
139
|
-
assert_instance_of(XML::Namespace, namespace)
|
130
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
140
131
|
assert_equal('soap', namespace.prefix)
|
141
132
|
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
142
133
|
|
143
134
|
namespace = ns_defs[1]
|
144
|
-
assert_instance_of(XML::Namespace, namespace)
|
135
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
145
136
|
assert_equal('xsd', namespace.prefix)
|
146
137
|
assert_equal('http://www.w3.org/2001/XMLSchema', namespace.href)
|
147
138
|
|
148
139
|
namespace = ns_defs[2]
|
149
|
-
assert_instance_of(XML::Namespace, namespace)
|
140
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
150
141
|
assert_equal('xsi', namespace.prefix)
|
151
142
|
assert_equal('http://www.w3.org/2001/XMLSchema-instance', namespace.href)
|
152
143
|
|
@@ -156,15 +147,15 @@ class TestNamespaces < Minitest::Test
|
|
156
147
|
assert_equal(1, ns_defs.size)
|
157
148
|
|
158
149
|
namespace = ns_defs[0]
|
159
|
-
assert_instance_of(XML::Namespace, namespace)
|
160
|
-
|
150
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
151
|
+
assert_nil(namespace.prefix)
|
161
152
|
assert_equal('http://services.somewhere.com', namespace.href)
|
162
153
|
end
|
163
154
|
|
164
155
|
def test_find_by_prefix
|
165
156
|
namespace = @doc.root.namespaces.find_by_prefix('soap')
|
166
157
|
|
167
|
-
assert_instance_of(XML::Namespace, namespace)
|
158
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
168
159
|
assert_equal('soap', namespace.prefix)
|
169
160
|
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
170
161
|
end
|
@@ -177,8 +168,8 @@ class TestNamespaces < Minitest::Test
|
|
177
168
|
:ns1 => 'http://services.somewhere.com')
|
178
169
|
namespace = node.namespaces.find_by_prefix(nil)
|
179
170
|
|
180
|
-
assert_instance_of(XML::Namespace, namespace)
|
181
|
-
|
171
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
172
|
+
assert_nil(namespace.prefix)
|
182
173
|
assert_equal('http://services.somewhere.com', namespace.href)
|
183
174
|
end
|
184
175
|
|
@@ -188,22 +179,22 @@ class TestNamespaces < Minitest::Test
|
|
188
179
|
|
189
180
|
namespace = node.namespaces.find_by_href('http://schemas.xmlsoap.org/soap/envelope/')
|
190
181
|
|
191
|
-
assert_instance_of(XML::Namespace, namespace)
|
182
|
+
assert_instance_of(LibXML::XML::Namespace, namespace)
|
192
183
|
assert_equal('soap', namespace.prefix)
|
193
184
|
assert_equal('http://schemas.xmlsoap.org/soap/envelope/', namespace.href)
|
194
185
|
end
|
195
186
|
|
196
187
|
def test_default_namespace
|
197
|
-
doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
188
|
+
doc = LibXML::XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
198
189
|
ns = doc.root.namespaces.default
|
199
190
|
assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
|
200
191
|
end
|
201
192
|
|
202
193
|
def test_default_prefix
|
203
|
-
doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
194
|
+
doc = LibXML::XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
204
195
|
doc.root.namespaces.default_prefix = 'soap'
|
205
196
|
|
206
197
|
node = doc.root.find_first('/soap:Envelope')
|
207
198
|
refute_nil(node)
|
208
199
|
end
|
209
|
-
end
|
200
|
+
end
|
@@ -1,19 +1,19 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
require_relative './test_helper'
|
4
4
|
|
5
5
|
class TestNode < Minitest::Test
|
6
6
|
def setup
|
7
7
|
@file_name = "model/bands.utf-8.xml"
|
8
8
|
|
9
9
|
# Strip spaces to make testing easier
|
10
|
-
XML.default_keep_blanks = false
|
10
|
+
LibXML::XML.default_keep_blanks = false
|
11
11
|
file = File.join(File.dirname(__FILE__), @file_name)
|
12
|
-
@doc = XML::Document.file(file)
|
12
|
+
@doc = LibXML::XML::Document.file(file)
|
13
13
|
end
|
14
14
|
|
15
15
|
def teardown
|
16
|
-
XML.default_keep_blanks = true
|
16
|
+
LibXML::XML.default_keep_blanks = true
|
17
17
|
@doc = nil
|
18
18
|
end
|
19
19
|
|
@@ -23,52 +23,48 @@ class TestNode < Minitest::Test
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def test_doc_class
|
26
|
-
assert_instance_of(XML::Document, @doc)
|
26
|
+
assert_instance_of(LibXML::XML::Document, @doc)
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_doc_node_type
|
30
|
-
assert_equal XML::Node::DOCUMENT_NODE, @doc.node_type
|
30
|
+
assert_equal LibXML::XML::Node::DOCUMENT_NODE, @doc.node_type
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_root_class
|
34
|
-
assert_instance_of(XML::Node, @doc.root)
|
34
|
+
assert_instance_of(LibXML::XML::Node, @doc.root)
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_root_node_type
|
38
|
-
assert_equal XML::Node::ELEMENT_NODE, @doc.root.node_type
|
38
|
+
assert_equal LibXML::XML::Node::ELEMENT_NODE, @doc.root.node_type
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_node_class
|
42
42
|
for n in nodes
|
43
|
-
assert_instance_of(XML::Node, n)
|
43
|
+
assert_instance_of(LibXML::XML::Node, n)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_context
|
48
48
|
node = @doc.root
|
49
49
|
context = node.context
|
50
|
-
assert_instance_of(XML::XPath::Context, context)
|
50
|
+
assert_instance_of(LibXML::XML::XPath::Context, context)
|
51
51
|
end
|
52
52
|
|
53
53
|
def test_find
|
54
|
-
assert_instance_of(XML::XPath::Object, self.nodes)
|
54
|
+
assert_instance_of(LibXML::XML::XPath::Object, self.nodes)
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_node_child_get
|
58
58
|
assert_instance_of(TrueClass, @doc.root.child?)
|
59
|
-
assert_instance_of(XML::Node, @doc.root.child)
|
59
|
+
assert_instance_of(LibXML::XML::Node, @doc.root.child)
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
assert_equal("m\u00F6tley_cr\u00FCe", @doc.root.child.name)
|
64
|
-
else
|
65
|
-
assert_equal("m\303\266tley_cr\303\274e", @doc.root.child.name)
|
66
|
-
end
|
61
|
+
assert_equal(Encoding::UTF_8, @doc.root.child.name.encoding)
|
62
|
+
assert_equal("m\u00F6tley_cr\u00FCe", @doc.root.child.name)
|
67
63
|
end
|
68
64
|
|
69
65
|
def test_node_doc
|
70
66
|
for n in nodes
|
71
|
-
assert_instance_of(XML::Document, n.doc) if n.document?
|
67
|
+
assert_instance_of(LibXML::XML::Document, n.doc) if n.document?
|
72
68
|
end
|
73
69
|
end
|
74
70
|
|
@@ -80,11 +76,11 @@ class TestNode < Minitest::Test
|
|
80
76
|
def test_node_find
|
81
77
|
nodes = @doc.root.find('./fixnum')
|
82
78
|
for node in nodes
|
83
|
-
assert_instance_of(XML::Node, node)
|
79
|
+
assert_instance_of(LibXML::XML::Node, node)
|
84
80
|
end
|
85
81
|
end
|
86
82
|
|
87
|
-
|
83
|
+
def test_equality
|
88
84
|
node_a = @doc.find_first('*[@country]')
|
89
85
|
node_b = @doc.root.child
|
90
86
|
|
@@ -96,7 +92,7 @@ class TestNode < Minitest::Test
|
|
96
92
|
assert(node_a.eql?(node_b))
|
97
93
|
|
98
94
|
file = File.join(File.dirname(__FILE__), @file_name)
|
99
|
-
doc2 = XML::Document.file(file)
|
95
|
+
doc2 = LibXML::XML::Document.file(file)
|
100
96
|
|
101
97
|
node_a2 = doc2.find_first('*[@country]')
|
102
98
|
|
@@ -107,8 +103,8 @@ class TestNode < Minitest::Test
|
|
107
103
|
end
|
108
104
|
|
109
105
|
def test_equality_2
|
110
|
-
parent = XML::Node.new('parent')
|
111
|
-
child = XML::Node.new('child')
|
106
|
+
parent = LibXML::XML::Node.new('parent')
|
107
|
+
child = LibXML::XML::Node.new('child')
|
112
108
|
parent << child
|
113
109
|
|
114
110
|
node_a = child.parent
|
@@ -139,7 +135,7 @@ class TestNode < Minitest::Test
|
|
139
135
|
end
|
140
136
|
|
141
137
|
def test_base
|
142
|
-
doc = XML::Parser.string('<person />').parse
|
138
|
+
doc = LibXML::XML::Parser.string('<person />').parse
|
143
139
|
assert_nil(doc.root.base_uri)
|
144
140
|
end
|
145
141
|
|
@@ -152,7 +148,7 @@ class TestNode < Minitest::Test
|
|
152
148
|
#
|
153
149
|
def test_output_escaping
|
154
150
|
text = '<bad-script>if (a < b || b > c) { return "text"; }<stop/>return ">>>snip<<<";</bad-script>'
|
155
|
-
node = XML::Parser.string(text).parse.root
|
151
|
+
node = LibXML::XML::Parser.string(text).parse.root
|
156
152
|
assert_equal text, node.to_s
|
157
153
|
|
158
154
|
text_noenc = '<bad-script>if (a < b || b > c) { return "text"; }<stop/>return ">>>snip<<<";</bad-script>'
|
@@ -172,7 +168,7 @@ class TestNode < Minitest::Test
|
|
172
168
|
# Just a sanity check for output escaping.
|
173
169
|
def test_output_escaping_sanity
|
174
170
|
text = '<bad-script>if (a < b || b > c) { return "text"; }<stop/>return ">>>snip<<<";</bad-script>'
|
175
|
-
node = XML::Parser.string(text).parse.root
|
171
|
+
node = LibXML::XML::Parser.string(text).parse.root
|
176
172
|
affected = node.find('//text()')
|
177
173
|
|
178
174
|
check_escaping = lambda do |flag|
|
@@ -205,15 +201,15 @@ class TestNode < Minitest::Test
|
|
205
201
|
node = @doc.root
|
206
202
|
|
207
203
|
node.space_preserve = false
|
208
|
-
assert_equal XML::Node::SPACE_DEFAULT, node.space_preserve
|
204
|
+
assert_equal LibXML::XML::Node::SPACE_DEFAULT, node.space_preserve
|
209
205
|
|
210
206
|
node.space_preserve = true
|
211
|
-
assert_equal XML::Node::SPACE_PRESERVE, node.space_preserve
|
207
|
+
assert_equal LibXML::XML::Node::SPACE_PRESERVE, node.space_preserve
|
212
208
|
end
|
213
209
|
|
214
210
|
def test_empty
|
215
211
|
text = '<name> </name>'
|
216
|
-
doc = XML::Parser.string(text).parse
|
212
|
+
doc = LibXML::XML::Parser.string(text).parse
|
217
213
|
|
218
214
|
node = doc.root
|
219
215
|
assert(!node.empty?)
|
@@ -222,8 +218,18 @@ class TestNode < Minitest::Test
|
|
222
218
|
assert(text_node.empty?)
|
223
219
|
end
|
224
220
|
|
221
|
+
def test_save_no_empty_tags
|
222
|
+
node = LibXML::XML::Node.new('test')
|
223
|
+
assert_equal '<test/>', node.to_s
|
224
|
+
|
225
|
+
LibXML::XML.default_save_no_empty_tags = true
|
226
|
+
assert_equal '<test></test>', node.to_s
|
227
|
+
|
228
|
+
LibXML::XML.default_save_no_empty_tags = false
|
229
|
+
end
|
230
|
+
|
225
231
|
def test_set_content
|
226
|
-
node = XML::Node.new('test')
|
232
|
+
node = LibXML::XML::Node.new('test')
|
227
233
|
node.content = "unescaped & string"
|
228
234
|
assert_equal("unescaped & string", node.content)
|
229
235
|
assert_equal("<test>unescaped & string</test>", node.to_s)
|