libxml-ruby 3.0.0-x64-mingw32 → 3.2.2-x64-mingw32
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/3.0/libxml_ruby.so +0 -0
- 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 +92 -106
- data/lib/2.4/libxml_ruby.so +0 -0
- data/lib/libs/libiconv-2.dll +0 -0
- data/lib/libs/libxml2-2.dll +0 -0
- data/lib/libs/zlib1.dll +0 -0
- 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
@@ -0,0 +1,146 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative './test_helper'
|
4
|
+
require 'tmpdir'
|
5
|
+
|
6
|
+
class TestDocumentWrite < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@file_name = "model/bands.utf-8.xml"
|
9
|
+
|
10
|
+
# Strip spaces to make testing easier
|
11
|
+
LibXML::XML.default_keep_blanks = false
|
12
|
+
file = File.join(File.dirname(__FILE__), @file_name)
|
13
|
+
@doc = LibXML::XML::Document.file(file)
|
14
|
+
end
|
15
|
+
|
16
|
+
def teardown
|
17
|
+
LibXML::XML.default_keep_blanks = true
|
18
|
+
@doc = nil
|
19
|
+
end
|
20
|
+
|
21
|
+
# --- to_s tests ---
|
22
|
+
def test_to_s_default
|
23
|
+
# Default to_s has indentation
|
24
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
|
25
|
+
@doc.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_to_s_no_global_indentation
|
29
|
+
# No indentation due to global setting
|
30
|
+
LibXML::XML.indent_tree_output = false
|
31
|
+
value = @doc.to_s
|
32
|
+
|
33
|
+
assert_equal(Encoding::UTF_8, value.encoding)
|
34
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n<m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n<iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
|
35
|
+
value)
|
36
|
+
ensure
|
37
|
+
LibXML::XML.indent_tree_output = true
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_to_s_no_indentation
|
41
|
+
# No indentation due to local setting
|
42
|
+
value = @doc.to_s(:indent => false)
|
43
|
+
assert_equal(Encoding::UTF_8, value.encoding)
|
44
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\"><m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
|
45
|
+
value)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_to_s_encoding
|
49
|
+
# Test encodings
|
50
|
+
|
51
|
+
# UTF8:
|
52
|
+
# ö - c3 b6 in hex, \303\266 in octal
|
53
|
+
# ü - c3 bc in hex, \303\274 in octal
|
54
|
+
value = @doc.to_s(:encoding => LibXML::XML::Encoding::UTF_8)
|
55
|
+
assert_equal(Encoding::UTF_8, value.encoding)
|
56
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
|
57
|
+
value)
|
58
|
+
|
59
|
+
# ISO_8859_1:
|
60
|
+
# ö - f6 in hex, \366 in octal
|
61
|
+
# ü - fc in hex, \374 in octal
|
62
|
+
value = @doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1)
|
63
|
+
assert_equal(Encoding::ISO8859_1, value.encoding)
|
64
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n".force_encoding(Encoding::ISO8859_1),
|
65
|
+
@doc.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1))
|
66
|
+
|
67
|
+
# Invalid encoding
|
68
|
+
error = assert_raises(ArgumentError) do
|
69
|
+
@doc.to_s(:encoding => -9999)
|
70
|
+
end
|
71
|
+
assert_equal('Unknown encoding value: -9999', error.to_s)
|
72
|
+
end
|
73
|
+
|
74
|
+
# --- save tests -----
|
75
|
+
def test_save_utf8
|
76
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8.xml")
|
77
|
+
|
78
|
+
bytes = @doc.save(temp_filename)
|
79
|
+
assert_equal(305, bytes)
|
80
|
+
|
81
|
+
contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
|
82
|
+
assert_equal(Encoding::UTF_8, contents.encoding)
|
83
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
|
84
|
+
contents)
|
85
|
+
ensure
|
86
|
+
File.delete(temp_filename)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_save_utf8_no_indents
|
90
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8_no_indents.xml")
|
91
|
+
|
92
|
+
bytes = @doc.save(temp_filename, :indent => false)
|
93
|
+
assert_equal(298, bytes)
|
94
|
+
|
95
|
+
contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
|
96
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\"><m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
|
97
|
+
contents)
|
98
|
+
ensure
|
99
|
+
File.delete(temp_filename)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_save_iso_8859_1
|
103
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml")
|
104
|
+
bytes = @doc.save(temp_filename, :encoding => LibXML::XML::Encoding::ISO_8859_1)
|
105
|
+
assert_equal(304, bytes)
|
106
|
+
|
107
|
+
contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
|
108
|
+
assert_equal(Encoding::ISO8859_1, contents.encoding)
|
109
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n".force_encoding(Encoding::ISO8859_1),
|
110
|
+
contents)
|
111
|
+
ensure
|
112
|
+
File.delete(temp_filename)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_save_iso_8859_1_no_indent
|
116
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml")
|
117
|
+
bytes = @doc.save(temp_filename, :indent => false, :encoding => LibXML::XML::Encoding::ISO_8859_1)
|
118
|
+
assert_equal(297, bytes)
|
119
|
+
|
120
|
+
contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
|
121
|
+
assert_equal(Encoding::ISO8859_1, contents.encoding)
|
122
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\"><m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n".force_encoding(Encoding::ISO8859_1),
|
123
|
+
contents)
|
124
|
+
ensure
|
125
|
+
File.delete(temp_filename)
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_thread_set_root
|
129
|
+
# Previously a segmentation fault occurred when running libxml in
|
130
|
+
# background threads.
|
131
|
+
thread = Thread.new do
|
132
|
+
100000.times do |i|
|
133
|
+
document = LibXML::XML::Document.new
|
134
|
+
node = LibXML::XML::Node.new('test')
|
135
|
+
document.root = node
|
136
|
+
end
|
137
|
+
end
|
138
|
+
thread.join
|
139
|
+
assert(true)
|
140
|
+
end
|
141
|
+
|
142
|
+
# --- Debug ---
|
143
|
+
def test_debug
|
144
|
+
assert(@doc.debug)
|
145
|
+
end
|
146
|
+
end
|
@@ -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,60 +31,61 @@ 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
|
44
44
|
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
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
|
58
58
|
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
59
|
-
|
59
|
+
end
|
60
60
|
|
61
61
|
def test_valid
|
62
62
|
assert(@doc.validate(dtd))
|
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
|
+
# Different answers across operating systems
|
88
|
+
# assert_nil(error.str2)
|
88
89
|
assert_nil(error.str3)
|
89
90
|
assert_equal(0, error.int1)
|
90
91
|
assert_equal(0, error.int2)
|
@@ -101,28 +102,28 @@ class TestDtd < Minitest::Test
|
|
101
102
|
EOS
|
102
103
|
|
103
104
|
errors = Array.new
|
104
|
-
XML::Error.set_handler do |error|
|
105
|
+
LibXML::XML::Error.set_handler do |error|
|
105
106
|
errors << error
|
106
107
|
end
|
107
108
|
|
108
|
-
XML.default_load_external_dtd = false
|
109
|
-
|
109
|
+
LibXML::XML.default_load_external_dtd = false
|
110
|
+
LibXML::XML::Parser.string(xml).parse
|
110
111
|
assert_equal(0, errors.length)
|
111
112
|
|
112
113
|
errors.clear
|
113
|
-
XML.default_load_external_dtd = true
|
114
|
-
|
114
|
+
LibXML::XML.default_load_external_dtd = true
|
115
|
+
LibXML::XML::Parser.string(xml).parse
|
115
116
|
assert_equal(1, errors.length)
|
116
117
|
assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
|
117
118
|
errors[0].to_s)
|
118
119
|
|
119
120
|
errors = Array.new
|
120
|
-
|
121
|
+
LibXML::XML::Parser.string(xml, :options => LibXML::XML::Parser::Options::DTDLOAD).parse
|
121
122
|
assert_equal(1, errors.length)
|
122
123
|
assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
|
123
124
|
errors[0].to_s)
|
124
125
|
ensure
|
125
|
-
XML.default_load_external_dtd = false
|
126
|
-
XML::Error.reset_handler
|
126
|
+
LibXML::XML.default_load_external_dtd = false
|
127
|
+
LibXML::XML::Error.reset_handler
|
127
128
|
end
|
128
129
|
end
|
@@ -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
|
@@ -21,9 +21,14 @@ require './test_helper'
|
|
21
21
|
|
22
22
|
class TestEncoding < Minitest::Test
|
23
23
|
def setup
|
24
|
+
@original_encoding = Encoding.default_internal
|
24
25
|
Encoding.default_internal = nil
|
25
26
|
end
|
26
27
|
|
28
|
+
def teardown
|
29
|
+
Encoding.default_internal = @original_encoding
|
30
|
+
end
|
31
|
+
|
27
32
|
def file_for_encoding(encoding)
|
28
33
|
file_name = "model/bands.#{encoding.name.downcase}.xml"
|
29
34
|
File.join(File.dirname(__FILE__), file_name)
|
@@ -34,28 +39,27 @@ class TestEncoding < Minitest::Test
|
|
34
39
|
file = file_for_encoding(encoding)
|
35
40
|
|
36
41
|
# Strip spaces to make testing easier
|
37
|
-
XML.default_keep_blanks = false
|
38
|
-
@doc = XML::Document.file(file)
|
39
|
-
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
|
40
45
|
end
|
41
46
|
|
42
47
|
def test_encoding
|
43
|
-
doc = XML::Document.new
|
44
|
-
assert_equal(XML::Encoding::NONE, doc.encoding)
|
45
|
-
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)
|
46
51
|
|
47
52
|
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
|
48
|
-
doc = XML::Document.file(file)
|
49
|
-
assert_equal(XML::Encoding::UTF_8, doc.encoding)
|
50
|
-
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)
|
51
56
|
|
52
|
-
doc.encoding = XML::Encoding::ISO_8859_1
|
53
|
-
assert_equal(XML::Encoding::ISO_8859_1, doc.encoding)
|
54
|
-
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)
|
55
60
|
end
|
56
61
|
|
57
62
|
def test_no_internal_encoding_iso_8859_1
|
58
|
-
Encoding.default_internal = nil
|
59
63
|
load_encoding(Encoding::ISO_8859_1)
|
60
64
|
node = @doc.root.children.first
|
61
65
|
|
@@ -93,7 +97,6 @@ class TestEncoding < Minitest::Test
|
|
93
97
|
end
|
94
98
|
|
95
99
|
def test_no_internal_encoding_utf_8
|
96
|
-
Encoding.default_internal = nil
|
97
100
|
load_encoding(Encoding::UTF_8)
|
98
101
|
node = @doc.root.children.first
|
99
102
|
|
@@ -120,7 +123,7 @@ class TestEncoding < Minitest::Test
|
|
120
123
|
end
|
121
124
|
|
122
125
|
def test_encoding_conversions
|
123
|
-
assert_equal("UTF-8", XML::Encoding.to_s(XML::Encoding::UTF_8))
|
124
|
-
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"))
|
125
128
|
end
|
126
129
|
end
|
@@ -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
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative './test_helper'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
class TestError < Minitest::Test
|
7
|
+
# def test_error_codes
|
8
|
+
# assert_equal(4, LibXML::XML::Error::DTD)
|
9
|
+
# assert_equal(4, LibXML::XML::Error.const_get('DTD'))
|
10
|
+
#
|
11
|
+
# assert_equal(4, LibXML::XML::Error::DOCUMENT_EMPTY)
|
12
|
+
# assert_equal(4, LibXML::XML::Error.const_get('DOCUMENT_EMPTY'))
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# def test_invalid_handler
|
16
|
+
# assert_raises(RuntimeError) do
|
17
|
+
# LibXML::XML::Error.set_handler
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
#
|
21
|
+
# def test_handler
|
22
|
+
# exception = nil
|
23
|
+
# LibXML::XML::Error.set_handler do |error|
|
24
|
+
# exception = error
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# # Raise the error
|
28
|
+
# error = assert_raises(LibXML::XML::Error) do
|
29
|
+
# LibXML::XML::Reader.string('<foo').read
|
30
|
+
# end
|
31
|
+
# assert_equal(exception, error)
|
32
|
+
#
|
33
|
+
# # Check the handler worked
|
34
|
+
# refute_nil(exception)
|
35
|
+
# assert_kind_of(LibXML::XML::Error, exception)
|
36
|
+
# assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", exception.message)
|
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
|
+
# assert_nil(exception.file)
|
41
|
+
# assert_equal(1, exception.line)
|
42
|
+
# assert_equal('foo', exception.str1)
|
43
|
+
# assert_nil(exception.str2)
|
44
|
+
# assert_nil(exception.str3)
|
45
|
+
# assert_equal(0, exception.int1)
|
46
|
+
# assert_equal(5, exception.int2)
|
47
|
+
# assert_nil(exception.node)
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# def test_reset_handler
|
51
|
+
# exception = nil
|
52
|
+
# LibXML::XML::Error.set_handler do |error|
|
53
|
+
# exception = error
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# LibXML::XML::Error.reset_handler
|
57
|
+
# LibXML::XML::Reader.string('<foo')
|
58
|
+
# assert_nil(exception)
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# def test_get_handler
|
62
|
+
# assert_respond_to(LibXML::XML::Error, :get_handler)
|
63
|
+
# assert_equal(0, LibXML::XML::Error.method(:get_handler).arity)
|
64
|
+
#
|
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
|
+
#
|
69
|
+
# LibXML::XML::Error.set_handler(&saved_handler)
|
70
|
+
# assert_equal(LibXML::XML::Error.get_handler, saved_handler)
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# def test_verbose_handler
|
74
|
+
# LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
|
75
|
+
# output = StringIO.new
|
76
|
+
# original_stderr = Object::STDERR
|
77
|
+
#
|
78
|
+
# Object.const_set(:STDERR, output)
|
79
|
+
# begin
|
80
|
+
# assert_raises(LibXML::XML::Error) do
|
81
|
+
# LibXML::XML::Parser.string('<foo><bar/></foz>').parse
|
82
|
+
# end
|
83
|
+
# ensure
|
84
|
+
# Object.const_set(:STDERR, original_stderr)
|
85
|
+
# end
|
86
|
+
# assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.\n", output.string)
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# def test_no_hanlder
|
90
|
+
# LibXML::XML::Error.reset_handler
|
91
|
+
# output = StringIO.new
|
92
|
+
# original_stderr = Object::STDERR
|
93
|
+
#
|
94
|
+
# Object.const_set(:STDERR, output)
|
95
|
+
# begin
|
96
|
+
# assert_raises(LibXML::XML::Error) do
|
97
|
+
# LibXML::XML::Parser.string('<foo><bar/></foz>').parse
|
98
|
+
# end
|
99
|
+
# ensure
|
100
|
+
# Object.const_set(:STDERR, original_stderr)
|
101
|
+
# end
|
102
|
+
# assert_equal('', output.string)
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
# def test_parse_error
|
106
|
+
# exception = assert_raises(LibXML::XML::Error) do
|
107
|
+
# LibXML::XML::Parser.string('<foo><bar/></foz>').parse
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# assert_instance_of(LibXML::XML::Error, exception)
|
111
|
+
# assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", exception.message)
|
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
|
+
# assert_nil(exception.file)
|
116
|
+
# assert_equal(1, exception.line)
|
117
|
+
# end
|
118
|
+
#
|
119
|
+
# def test_xpath_error
|
120
|
+
# doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/soap.xml'))
|
121
|
+
#
|
122
|
+
# exception = assert_raises(LibXML::XML::Error) do
|
123
|
+
# doc.find('/foo[bar=test')
|
124
|
+
# end
|
125
|
+
#
|
126
|
+
# assert_instance_of(LibXML::XML::Error, exception)
|
127
|
+
# assert_equal("Error: Invalid predicate.", exception.message)
|
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
|
+
# assert_nil(exception.file)
|
132
|
+
# assert_nil(nil)
|
133
|
+
# end
|
134
|
+
|
135
|
+
def test_double_parse
|
136
|
+
LibXML::XML::Parser.register_error_handler(lambda {|msg| nil })
|
137
|
+
parser = LibXML::XML::Parser.string("<test>something</test>")
|
138
|
+
parser.parse
|
139
|
+
|
140
|
+
error = assert_raises(LibXML::XML::Error) do
|
141
|
+
# Try parsing a second time
|
142
|
+
parser.parse
|
143
|
+
end
|
144
|
+
|
145
|
+
assert_equal(" LibXML::XML::Error.", error.to_s)
|
146
|
+
end
|
147
|
+
|
148
|
+
# def test_libxml_parser_empty_string
|
149
|
+
# xp = LibXML::XML::Parser.new
|
150
|
+
#
|
151
|
+
# error = assert_raises(TypeError) do
|
152
|
+
# xp.string = nil
|
153
|
+
# end
|
154
|
+
# assert_equal('wrong argument type nil (expected String)', error.to_s)
|
155
|
+
#
|
156
|
+
# error = assert_raises(ArgumentError) do
|
157
|
+
# xp.string = ''
|
158
|
+
# end
|
159
|
+
# assert_equal('Must specify a string with one or more characters', error.to_s)
|
160
|
+
# end
|
161
|
+
#
|
162
|
+
# def test_error_domain_to_s
|
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
|
+
# end
|
166
|
+
#
|
167
|
+
# assert_equal(LibXML::XML::Error::PARSER, exception.domain)
|
168
|
+
# assert_equal("PARSER",exception.domain_to_s)
|
169
|
+
# end
|
170
|
+
#
|
171
|
+
# def test_error_code_to_s
|
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
|
+
# end
|
175
|
+
# assert_equal(LibXML::XML::Error::ENTITYREF_SEMICOL_MISSING, exception.code)
|
176
|
+
# assert_equal("ENTITYREF_SEMICOL_MISSING",exception.code_to_s)
|
177
|
+
# end
|
178
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -2,15 +2,8 @@
|
|
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'
|
15
|
-
|
16
|
-
|
7
|
+
require 'libxml-ruby'
|
8
|
+
|
9
|
+
STDOUT.write "\nlibxml2: #{LibXML::XML::LIBXML_VERSION}\n#{RUBY_DESCRIPTION}\n\n"
|