libxml-ruby 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY +8 -0
- data/ext/libxml/extconf.h +3 -0
- 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 -1
- data/ext/libxml/ruby_xml_dtd.c +6 -8
- data/ext/libxml/ruby_xml_node.c +1 -1
- data/ext/libxml/ruby_xml_parser_context.c +1 -1
- data/ext/libxml/ruby_xml_version.h +3 -3
- data/lib/libxml-ruby.rb +30 -0
- data/lib/libxml.rb +3 -28
- data/libxml-ruby.gemspec +2 -2
- data/test/test_attr.rb +18 -18
- data/test/test_attr_decl.rb +8 -8
- data/test/test_attributes.rb +10 -10
- data/test/test_canonicalize.rb +16 -24
- data/test/test_deprecated_require.rb +3 -3
- data/test/test_document.rb +118 -112
- data/test/test_document_write.rb +39 -88
- data/test/test_dtd.rb +23 -23
- data/test/test_encoding.rb +15 -15
- data/test/test_encoding_sax.rb +3 -3
- data/test/test_error.rb +51 -51
- data/test/test_helper.rb +2 -9
- data/test/test_html_parser.rb +30 -30
- data/test/test_html_parser_context.rb +6 -6
- data/test/test_namespace.rb +16 -16
- data/test/test_namespaces.rb +25 -25
- data/test/test_node.rb +36 -30
- data/test/test_node_cdata.rb +10 -10
- data/test/test_node_comment.rb +6 -6
- data/test/test_node_copy.rb +2 -2
- data/test/test_node_edit.rb +16 -16
- data/test/test_node_pi.rb +7 -7
- data/test/test_node_text.rb +6 -6
- data/test/test_node_write.rb +16 -26
- data/test/test_node_xlink.rb +6 -6
- data/test/test_parser.rb +68 -72
- data/test/test_parser_context.rb +28 -28
- data/test/test_properties.rb +5 -5
- data/test/test_reader.rb +80 -85
- data/test/test_relaxng.rb +11 -11
- data/test/test_sax_parser.rb +28 -28
- data/test/test_schema.rb +24 -24
- data/test/test_suite.rb +3 -4
- data/test/test_traversal.rb +4 -4
- data/test/test_writer.rb +50 -52
- data/test/test_xinclude.rb +3 -3
- data/test/test_xml.rb +114 -102
- data/test/test_xpath.rb +22 -22
- data/test/test_xpath_context.rb +5 -5
- data/test/test_xpath_expression.rb +6 -6
- data/test/test_xpointer.rb +15 -15
- metadata +6 -5
data/test/test_dtd.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
require_relative './test_helper'
|
4
4
|
|
5
5
|
|
6
6
|
class TestDtd < Minitest::Test
|
7
7
|
def setup
|
8
|
-
xp = XML::Parser.string(<<-EOS)
|
8
|
+
xp = LibXML::XML::Parser.string(<<-EOS)
|
9
9
|
<root>
|
10
10
|
<head a="ee" id="1">Colorado</head>
|
11
11
|
<descr>Lots of nice mountains</descr>
|
@@ -19,7 +19,7 @@ class TestDtd < Minitest::Test
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def dtd
|
22
|
-
XML::Dtd.new(<<-EOS)
|
22
|
+
LibXML::XML::Dtd.new(<<-EOS)
|
23
23
|
<!ELEMENT root (head, descr)>
|
24
24
|
<!ELEMENT head (#PCDATA)>
|
25
25
|
<!ATTLIST head
|
@@ -31,13 +31,13 @@ class TestDtd < Minitest::Test
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_internal_subset
|
34
|
-
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, nil, true
|
34
|
+
xhtml_dtd = LibXML::XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, nil, true
|
35
35
|
assert xhtml_dtd.name.nil?
|
36
36
|
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
37
37
|
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
38
38
|
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
39
39
|
|
40
|
-
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1", nil, true
|
40
|
+
xhtml_dtd = LibXML::XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1", nil, true
|
41
41
|
assert_equal "xhtml1", xhtml_dtd.name
|
42
42
|
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
43
43
|
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
@@ -45,13 +45,13 @@ class TestDtd < Minitest::Test
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_external_subset
|
48
|
-
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil
|
48
|
+
xhtml_dtd = LibXML::XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil
|
49
49
|
assert xhtml_dtd.name.nil?
|
50
50
|
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
51
51
|
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
52
52
|
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
53
53
|
|
54
|
-
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1"
|
54
|
+
xhtml_dtd = LibXML::XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1"
|
55
55
|
assert_equal "xhtml1", xhtml_dtd.name
|
56
56
|
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
57
57
|
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
@@ -63,28 +63,28 @@ class TestDtd < Minitest::Test
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def test_node_type
|
66
|
-
assert_equal(XML::Node::DTD_NODE, dtd.node_type)
|
66
|
+
assert_equal(LibXML::XML::Node::DTD_NODE, dtd.node_type)
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_invalid
|
70
|
-
new_node = XML::Node.new('invalid', 'this will mess up validation')
|
70
|
+
new_node = LibXML::XML::Node.new('invalid', 'this will mess up validation')
|
71
71
|
@doc.root << new_node
|
72
72
|
|
73
|
-
error = assert_raises(XML::Error) do
|
73
|
+
error = assert_raises(LibXML::XML::Error) do
|
74
74
|
@doc.validate(dtd)
|
75
75
|
end
|
76
76
|
|
77
77
|
# Check the error worked
|
78
78
|
refute_nil(error)
|
79
|
-
assert_kind_of(XML::Error, error)
|
79
|
+
assert_kind_of(LibXML::XML::Error, error)
|
80
80
|
assert_equal("Error: No declaration for element invalid.", error.message)
|
81
|
-
assert_equal(XML::Error::VALID, error.domain)
|
82
|
-
assert_equal(XML::Error::DTD_UNKNOWN_ELEM, error.code)
|
83
|
-
assert_equal(XML::Error::ERROR, error.level)
|
81
|
+
assert_equal(LibXML::XML::Error::VALID, error.domain)
|
82
|
+
assert_equal(LibXML::XML::Error::DTD_UNKNOWN_ELEM, error.code)
|
83
|
+
assert_equal(LibXML::XML::Error::ERROR, error.level)
|
84
84
|
assert_nil(error.file)
|
85
85
|
assert_nil(error.line)
|
86
86
|
assert_equal('invalid', error.str1)
|
87
|
-
|
87
|
+
assert_nil(error.str2)
|
88
88
|
assert_nil(error.str3)
|
89
89
|
assert_equal(0, error.int1)
|
90
90
|
assert_equal(0, error.int2)
|
@@ -101,28 +101,28 @@ class TestDtd < Minitest::Test
|
|
101
101
|
EOS
|
102
102
|
|
103
103
|
errors = Array.new
|
104
|
-
XML::Error.set_handler do |error|
|
104
|
+
LibXML::XML::Error.set_handler do |error|
|
105
105
|
errors << error
|
106
106
|
end
|
107
107
|
|
108
|
-
XML.default_load_external_dtd = false
|
109
|
-
XML::Parser.string(xml).parse
|
108
|
+
LibXML::XML.default_load_external_dtd = false
|
109
|
+
LibXML::XML::Parser.string(xml).parse
|
110
110
|
assert_equal(0, errors.length)
|
111
111
|
|
112
112
|
errors.clear
|
113
|
-
XML.default_load_external_dtd = true
|
114
|
-
XML::Parser.string(xml).parse
|
113
|
+
LibXML::XML.default_load_external_dtd = true
|
114
|
+
LibXML::XML::Parser.string(xml).parse
|
115
115
|
assert_equal(1, errors.length)
|
116
116
|
assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
|
117
117
|
errors[0].to_s)
|
118
118
|
|
119
119
|
errors = Array.new
|
120
|
-
XML::Parser.string(xml, :options => XML::Parser::Options::DTDLOAD).parse
|
120
|
+
LibXML::XML::Parser.string(xml, :options => LibXML::XML::Parser::Options::DTDLOAD).parse
|
121
121
|
assert_equal(1, errors.length)
|
122
122
|
assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
|
123
123
|
errors[0].to_s)
|
124
124
|
ensure
|
125
|
-
XML.default_load_external_dtd = false
|
126
|
-
XML::Error.reset_handler
|
125
|
+
LibXML::XML.default_load_external_dtd = false
|
126
|
+
LibXML::XML::Error.reset_handler
|
127
127
|
end
|
128
128
|
end
|
data/test/test_encoding.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
require_relative './test_helper'
|
4
4
|
|
5
5
|
# Code UTF8 Latin1 Hex
|
6
6
|
# m 109 109 6D
|
@@ -39,24 +39,24 @@ class TestEncoding < Minitest::Test
|
|
39
39
|
file = file_for_encoding(encoding)
|
40
40
|
|
41
41
|
# Strip spaces to make testing easier
|
42
|
-
XML.default_keep_blanks = false
|
43
|
-
@doc = XML::Document.file(file)
|
44
|
-
XML.default_keep_blanks = true
|
42
|
+
LibXML::XML.default_keep_blanks = false
|
43
|
+
@doc = LibXML::XML::Document.file(file)
|
44
|
+
LibXML::XML.default_keep_blanks = true
|
45
45
|
end
|
46
46
|
|
47
47
|
def test_encoding
|
48
|
-
doc = XML::Document.new
|
49
|
-
assert_equal(XML::Encoding::NONE, doc.encoding)
|
50
|
-
assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding)
|
48
|
+
doc = LibXML::XML::Document.new
|
49
|
+
assert_equal(LibXML::XML::Encoding::NONE, doc.encoding)
|
50
|
+
assert_equal(Encoding::ASCII_8BIT, doc.rb_encoding)
|
51
51
|
|
52
52
|
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
|
53
|
-
doc = XML::Document.file(file)
|
54
|
-
assert_equal(XML::Encoding::UTF_8, doc.encoding)
|
55
|
-
assert_equal(Encoding::UTF_8, doc.rb_encoding)
|
53
|
+
doc = LibXML::XML::Document.file(file)
|
54
|
+
assert_equal(LibXML::XML::Encoding::UTF_8, doc.encoding)
|
55
|
+
assert_equal(Encoding::UTF_8, doc.rb_encoding)
|
56
56
|
|
57
|
-
doc.encoding = XML::Encoding::ISO_8859_1
|
58
|
-
assert_equal(XML::Encoding::ISO_8859_1, doc.encoding)
|
59
|
-
assert_equal(Encoding::ISO8859_1, doc.rb_encoding)
|
57
|
+
doc.encoding = LibXML::XML::Encoding::ISO_8859_1
|
58
|
+
assert_equal(LibXML::XML::Encoding::ISO_8859_1, doc.encoding)
|
59
|
+
assert_equal(Encoding::ISO8859_1, doc.rb_encoding)
|
60
60
|
end
|
61
61
|
|
62
62
|
def test_no_internal_encoding_iso_8859_1
|
@@ -123,7 +123,7 @@ class TestEncoding < Minitest::Test
|
|
123
123
|
end
|
124
124
|
|
125
125
|
def test_encoding_conversions
|
126
|
-
assert_equal("UTF-8", XML::Encoding.to_s(XML::Encoding::UTF_8))
|
127
|
-
assert_equal(XML::Encoding::UTF_8, XML::Encoding.from_s("UTF-8"))
|
126
|
+
assert_equal("UTF-8", LibXML::XML::Encoding.to_s(LibXML::XML::Encoding::UTF_8))
|
127
|
+
assert_equal(LibXML::XML::Encoding::UTF_8, LibXML::XML::Encoding.from_s("UTF-8"))
|
128
128
|
end
|
129
129
|
end
|
data/test/test_encoding_sax.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: UTF-8
|
2
|
-
|
2
|
+
require_relative './test_helper'
|
3
3
|
|
4
4
|
class SaxEncodingCallbacks
|
5
5
|
attr_reader :encoding
|
@@ -102,13 +102,13 @@ class TestEncodingSax < Minitest::Test
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def test_encoding_iso_8859_1
|
105
|
-
parser = XML::SaxParser.file(file_for_encoding(Encoding::ISO_8859_1))
|
105
|
+
parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::ISO_8859_1))
|
106
106
|
parser.callbacks = SaxEncodingCallbacks.new
|
107
107
|
parser.parse
|
108
108
|
end
|
109
109
|
|
110
110
|
def test_encoding_utf8
|
111
|
-
parser = XML::SaxParser.file(file_for_encoding(Encoding::UTF_8))
|
111
|
+
parser = LibXML::XML::SaxParser.file(file_for_encoding(Encoding::UTF_8))
|
112
112
|
parser.callbacks = SaxEncodingCallbacks.new
|
113
113
|
parser.parse
|
114
114
|
end
|
data/test/test_error.rb
CHANGED
@@ -1,42 +1,42 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
|
3
|
+
require_relative './test_helper'
|
4
4
|
require 'stringio'
|
5
5
|
|
6
6
|
class TestError < Minitest::Test
|
7
7
|
# def test_error_codes
|
8
|
-
# assert_equal(4, XML::Error::DTD)
|
9
|
-
# assert_equal(4, XML::Error.const_get('DTD'))
|
8
|
+
# assert_equal(4, LibXML::XML::Error::DTD)
|
9
|
+
# assert_equal(4, LibXML::XML::Error.const_get('DTD'))
|
10
10
|
#
|
11
|
-
# assert_equal(4, XML::Error::DOCUMENT_EMPTY)
|
12
|
-
# assert_equal(4, XML::Error.const_get('DOCUMENT_EMPTY'))
|
11
|
+
# assert_equal(4, LibXML::XML::Error::DOCUMENT_EMPTY)
|
12
|
+
# assert_equal(4, LibXML::XML::Error.const_get('DOCUMENT_EMPTY'))
|
13
13
|
# end
|
14
14
|
#
|
15
15
|
# def test_invalid_handler
|
16
16
|
# assert_raises(RuntimeError) do
|
17
|
-
# XML::Error.set_handler
|
17
|
+
# LibXML::XML::Error.set_handler
|
18
18
|
# end
|
19
19
|
# end
|
20
20
|
#
|
21
21
|
# def test_handler
|
22
22
|
# exception = nil
|
23
|
-
# XML::Error.set_handler do |error|
|
23
|
+
# LibXML::XML::Error.set_handler do |error|
|
24
24
|
# exception = error
|
25
25
|
# end
|
26
26
|
#
|
27
27
|
# # Raise the error
|
28
|
-
# error = assert_raises(XML::Error) do
|
29
|
-
# XML::Reader.string('<foo').read
|
28
|
+
# error = assert_raises(LibXML::XML::Error) do
|
29
|
+
# LibXML::XML::Reader.string('<foo').read
|
30
30
|
# end
|
31
31
|
# assert_equal(exception, error)
|
32
32
|
#
|
33
33
|
# # Check the handler worked
|
34
34
|
# refute_nil(exception)
|
35
|
-
# assert_kind_of(XML::Error, exception)
|
35
|
+
# assert_kind_of(LibXML::XML::Error, exception)
|
36
36
|
# assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", exception.message)
|
37
|
-
# assert_equal(XML::Error::PARSER, exception.domain)
|
38
|
-
# assert_equal(XML::Error::GT_REQUIRED, exception.code)
|
39
|
-
# assert_equal(XML::Error::FATAL, exception.level)
|
37
|
+
# assert_equal(LibXML::XML::Error::PARSER, exception.domain)
|
38
|
+
# assert_equal(LibXML::XML::Error::GT_REQUIRED, exception.code)
|
39
|
+
# assert_equal(LibXML::XML::Error::FATAL, exception.level)
|
40
40
|
# assert_nil(exception.file)
|
41
41
|
# assert_equal(1, exception.line)
|
42
42
|
# assert_equal('foo', exception.str1)
|
@@ -49,36 +49,36 @@ class TestError < Minitest::Test
|
|
49
49
|
#
|
50
50
|
# def test_reset_handler
|
51
51
|
# exception = nil
|
52
|
-
# XML::Error.set_handler do |error|
|
52
|
+
# LibXML::XML::Error.set_handler do |error|
|
53
53
|
# exception = error
|
54
54
|
# end
|
55
55
|
#
|
56
|
-
# XML::Error.reset_handler
|
57
|
-
# XML::Reader.string('<foo')
|
56
|
+
# LibXML::XML::Error.reset_handler
|
57
|
+
# LibXML::XML::Reader.string('<foo')
|
58
58
|
# assert_nil(exception)
|
59
59
|
# end
|
60
60
|
#
|
61
61
|
# def test_get_handler
|
62
|
-
# assert_respond_to(XML::Error, :get_handler)
|
63
|
-
# assert_equal(0, XML::Error.method(:get_handler).arity)
|
62
|
+
# assert_respond_to(LibXML::XML::Error, :get_handler)
|
63
|
+
# assert_equal(0, LibXML::XML::Error.method(:get_handler).arity)
|
64
64
|
#
|
65
|
-
# saved_handler = XML::Error.get_handler
|
66
|
-
# XML::Error.set_handler{ puts "New handler" }
|
67
|
-
# refute_equal(XML::Error.get_handler, saved_handler)
|
65
|
+
# saved_handler = LibXML::XML::Error.get_handler
|
66
|
+
# LibXML::XML::Error.set_handler{ puts "New handler" }
|
67
|
+
# refute_equal(LibXML::XML::Error.get_handler, saved_handler)
|
68
68
|
#
|
69
|
-
# XML::Error.set_handler(&saved_handler)
|
70
|
-
# assert_equal(XML::Error.get_handler, saved_handler)
|
69
|
+
# LibXML::XML::Error.set_handler(&saved_handler)
|
70
|
+
# assert_equal(LibXML::XML::Error.get_handler, saved_handler)
|
71
71
|
# end
|
72
72
|
#
|
73
73
|
# def test_verbose_handler
|
74
|
-
# XML::Error.set_handler(&XML::Error::VERBOSE_HANDLER)
|
74
|
+
# LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
|
75
75
|
# output = StringIO.new
|
76
76
|
# original_stderr = Object::STDERR
|
77
77
|
#
|
78
78
|
# Object.const_set(:STDERR, output)
|
79
79
|
# begin
|
80
|
-
# assert_raises(XML::Error) do
|
81
|
-
# XML::Parser.string('<foo><bar/></foz>').parse
|
80
|
+
# assert_raises(LibXML::XML::Error) do
|
81
|
+
# LibXML::XML::Parser.string('<foo><bar/></foz>').parse
|
82
82
|
# end
|
83
83
|
# ensure
|
84
84
|
# Object.const_set(:STDERR, original_stderr)
|
@@ -87,14 +87,14 @@ class TestError < Minitest::Test
|
|
87
87
|
# end
|
88
88
|
#
|
89
89
|
# def test_no_hanlder
|
90
|
-
# XML::Error.reset_handler
|
90
|
+
# LibXML::XML::Error.reset_handler
|
91
91
|
# output = StringIO.new
|
92
92
|
# original_stderr = Object::STDERR
|
93
93
|
#
|
94
94
|
# Object.const_set(:STDERR, output)
|
95
95
|
# begin
|
96
|
-
# assert_raises(XML::Error) do
|
97
|
-
# XML::Parser.string('<foo><bar/></foz>').parse
|
96
|
+
# assert_raises(LibXML::XML::Error) do
|
97
|
+
# LibXML::XML::Parser.string('<foo><bar/></foz>').parse
|
98
98
|
# end
|
99
99
|
# ensure
|
100
100
|
# Object.const_set(:STDERR, original_stderr)
|
@@ -103,41 +103,41 @@ class TestError < Minitest::Test
|
|
103
103
|
# end
|
104
104
|
#
|
105
105
|
# def test_parse_error
|
106
|
-
# exception = assert_raises(XML::Error) do
|
107
|
-
# XML::Parser.string('<foo><bar/></foz>').parse
|
106
|
+
# exception = assert_raises(LibXML::XML::Error) do
|
107
|
+
# LibXML::XML::Parser.string('<foo><bar/></foz>').parse
|
108
108
|
# end
|
109
109
|
#
|
110
|
-
# assert_instance_of(XML::Error, exception)
|
110
|
+
# assert_instance_of(LibXML::XML::Error, exception)
|
111
111
|
# assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", exception.message)
|
112
|
-
# assert_equal(XML::Error::PARSER, exception.domain)
|
113
|
-
# assert_equal(XML::Error::TAG_NAME_MISMATCH, exception.code)
|
114
|
-
# assert_equal(XML::Error::FATAL, exception.level)
|
112
|
+
# assert_equal(LibXML::XML::Error::PARSER, exception.domain)
|
113
|
+
# assert_equal(LibXML::XML::Error::TAG_NAME_MISMATCH, exception.code)
|
114
|
+
# assert_equal(LibXML::XML::Error::FATAL, exception.level)
|
115
115
|
# assert_nil(exception.file)
|
116
116
|
# assert_equal(1, exception.line)
|
117
117
|
# end
|
118
118
|
#
|
119
119
|
# def test_xpath_error
|
120
|
-
# doc = XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
|
120
|
+
# doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
|
121
121
|
#
|
122
|
-
# exception = assert_raises(XML::Error) do
|
122
|
+
# exception = assert_raises(LibXML::XML::Error) do
|
123
123
|
# doc.find('/foo[bar=test')
|
124
124
|
# end
|
125
125
|
#
|
126
|
-
# assert_instance_of(XML::Error, exception)
|
126
|
+
# assert_instance_of(LibXML::XML::Error, exception)
|
127
127
|
# assert_equal("Error: Invalid predicate.", exception.message)
|
128
|
-
# assert_equal(XML::Error::XPATH, exception.domain)
|
129
|
-
# assert_equal(XML::Error::XPATH_INVALID_PREDICATE_ERROR, exception.code)
|
130
|
-
# assert_equal(XML::Error::ERROR, exception.level)
|
128
|
+
# assert_equal(LibXML::XML::Error::XPATH, exception.domain)
|
129
|
+
# assert_equal(LibXML::XML::Error::XPATH_INVALID_PREDICATE_ERROR, exception.code)
|
130
|
+
# assert_equal(LibXML::XML::Error::ERROR, exception.level)
|
131
131
|
# assert_nil(exception.file)
|
132
132
|
# assert_nil(nil)
|
133
133
|
# end
|
134
134
|
|
135
135
|
def test_double_parse
|
136
|
-
XML::Parser.register_error_handler(lambda {|msg| nil })
|
137
|
-
parser = XML::Parser.string("<test>something</test>")
|
136
|
+
LibXML::XML::Parser.register_error_handler(lambda {|msg| nil })
|
137
|
+
parser = LibXML::XML::Parser.string("<test>something</test>")
|
138
138
|
parser.parse
|
139
139
|
|
140
|
-
error = assert_raises(XML::Error) do
|
140
|
+
error = assert_raises(LibXML::XML::Error) do
|
141
141
|
# Try parsing a second time
|
142
142
|
parser.parse
|
143
143
|
end
|
@@ -146,7 +146,7 @@ class TestError < Minitest::Test
|
|
146
146
|
end
|
147
147
|
|
148
148
|
# def test_libxml_parser_empty_string
|
149
|
-
# xp = XML::Parser.new
|
149
|
+
# xp = LibXML::XML::Parser.new
|
150
150
|
#
|
151
151
|
# error = assert_raises(TypeError) do
|
152
152
|
# xp.string = nil
|
@@ -160,19 +160,19 @@ class TestError < Minitest::Test
|
|
160
160
|
# end
|
161
161
|
#
|
162
162
|
# def test_error_domain_to_s
|
163
|
-
# exception = assert_raises(XML::Error) do
|
164
|
-
# XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
|
163
|
+
# exception = assert_raises(LibXML::XML::Error) do
|
164
|
+
# LibXML::XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
|
165
165
|
# end
|
166
166
|
#
|
167
|
-
# assert_equal(XML::Error::PARSER, exception.domain)
|
167
|
+
# assert_equal(LibXML::XML::Error::PARSER, exception.domain)
|
168
168
|
# assert_equal("PARSER",exception.domain_to_s)
|
169
169
|
# end
|
170
170
|
#
|
171
171
|
# def test_error_code_to_s
|
172
|
-
# exception = assert_raises(XML::Error) do
|
173
|
-
# XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
|
172
|
+
# exception = assert_raises(LibXML::XML::Error) do
|
173
|
+
# LibXML::XML::Parser.string('<foo href="http://example.org/cgi?k1=v1&k2=v2"></foo>').parse
|
174
174
|
# end
|
175
|
-
# assert_equal(XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code)
|
175
|
+
# assert_equal(LibXML::XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code)
|
176
176
|
# assert_equal("ENTITYREF_SEMICOL_MISSING",exception.code_to_s)
|
177
177
|
# end
|
178
178
|
end
|
data/test/test_helper.rb
CHANGED
@@ -2,13 +2,6 @@
|
|
2
2
|
|
3
3
|
# To make testing/debugging easier, test within this source tree versus an installed gem
|
4
4
|
|
5
|
-
|
6
|
-
root = File.expand_path(File.join(dir, '..'))
|
7
|
-
lib = File.expand_path(File.join(root, 'lib'))
|
8
|
-
ext = File.expand_path(File.join(root, 'ext', 'libxml'))
|
9
|
-
|
10
|
-
$LOAD_PATH << lib
|
11
|
-
$LOAD_PATH << ext
|
12
|
-
|
13
|
-
require 'xml'
|
5
|
+
require 'bundler/setup'
|
14
6
|
require 'minitest/autorun'
|
7
|
+
require 'libxml-ruby'
|
data/test/test_html_parser.rb
CHANGED
@@ -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
|
@@ -156,7 +156,7 @@ class HTMLParserTest < Minitest::Test
|
|
156
156
|
def test_open_many_files
|
157
157
|
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/ruby-lang.html'))
|
158
158
|
1000.times do
|
159
|
-
XML::HTMLParser.file(file).parse
|
159
|
+
LibXML::XML::HTMLParser.file(file).parse
|
160
160
|
end
|
161
161
|
end
|
162
162
|
end
|