libxml-ruby 5.0.4 → 5.0.5
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 +4 -4
- data/HISTORY +10 -6
- data/README.rdoc +1 -1
- data/ext/libxml/extconf.rb +5 -0
- data/ext/libxml/ruby_xml.c +556 -556
- data/ext/libxml/ruby_xml_attributes.h +17 -17
- data/ext/libxml/ruby_xml_document.c +1129 -1129
- data/ext/libxml/ruby_xml_dtd.c +257 -257
- data/ext/libxml/ruby_xml_encoding.c +250 -250
- data/ext/libxml/ruby_xml_error.c +1003 -1003
- data/ext/libxml/ruby_xml_error.h +14 -14
- data/ext/libxml/ruby_xml_html_parser_context.c +351 -351
- data/ext/libxml/ruby_xml_input_cbg.c +188 -188
- data/ext/libxml/ruby_xml_namespace.c +151 -151
- data/ext/libxml/ruby_xml_parser.h +10 -10
- data/ext/libxml/ruby_xml_parser_context.c +1009 -1009
- data/ext/libxml/ruby_xml_parser_options.c +74 -74
- data/ext/libxml/ruby_xml_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
- data/ext/libxml/ruby_xml_sax_parser.c +108 -108
- data/ext/libxml/ruby_xml_version.h +9 -9
- data/lib/libxml/attr.rb +122 -122
- data/lib/libxml/attr_decl.rb +80 -80
- data/lib/libxml/attributes.rb +13 -13
- data/lib/libxml/document.rb +194 -194
- data/lib/libxml/error.rb +95 -95
- data/lib/libxml/hpricot.rb +77 -77
- data/lib/libxml/html_parser.rb +96 -96
- data/lib/libxml/namespace.rb +61 -61
- data/lib/libxml/namespaces.rb +37 -37
- data/lib/libxml/node.rb +323 -323
- data/lib/libxml/parser.rb +102 -102
- data/lib/libxml/sax_callbacks.rb +179 -179
- data/lib/libxml/sax_parser.rb +40 -40
- data/lib/libxml/tree.rb +28 -28
- data/lib/libxml.rb +4 -4
- data/lib/xml/libxml.rb +10 -10
- data/lib/xml.rb +13 -13
- data/libxml-ruby.gemspec +50 -49
- data/test/test_document.rb +140 -140
- data/test/test_document_write.rb +142 -142
- data/test/test_dtd.rb +126 -126
- data/test/test_encoding.rb +126 -126
- data/test/test_error.rb +194 -194
- data/test/test_helper.rb +20 -20
- data/test/test_namespace.rb +58 -58
- data/test/test_node.rb +235 -235
- data/test/test_node_write.rb +93 -93
- data/test/test_parser.rb +333 -333
- data/test/test_reader.rb +364 -364
- data/test/test_xml.rb +168 -168
- metadata +5 -4
data/test/test_node_write.rb
CHANGED
@@ -1,94 +1,94 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require_relative './test_helper'
|
4
|
-
|
5
|
-
class TestNodeWrite < Minitest::Test
|
6
|
-
def setup
|
7
|
-
load_encoding("utf-8")
|
8
|
-
end
|
9
|
-
|
10
|
-
def teardown
|
11
|
-
@doc = nil
|
12
|
-
end
|
13
|
-
|
14
|
-
def load_encoding(name)
|
15
|
-
@encoding = Encoding.find(name)
|
16
|
-
@file_name = "model/bands.#{name.downcase}.xml"
|
17
|
-
|
18
|
-
file = File.join(File.dirname(__FILE__), @file_name)
|
19
|
-
@doc = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NOBLANKS)
|
20
|
-
end
|
21
|
-
|
22
|
-
def test_to_s_default
|
23
|
-
# Default to_s has indentation
|
24
|
-
node = @doc.root
|
25
|
-
assert_equal(Encoding::UTF_8, node.to_s.encoding)
|
26
|
-
assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
|
27
|
-
node.to_s)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_to_s_no_global_indentation
|
31
|
-
# No indentation due to global setting
|
32
|
-
node = @doc.root
|
33
|
-
LibXML::XML.indent_tree_output = false
|
34
|
-
assert_equal("<bands genre=\"metal\">\n<m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n<iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
|
35
|
-
node.to_s)
|
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
|
-
node = @doc.root
|
43
|
-
assert_equal("<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>",
|
44
|
-
node.to_s(:indent => false))
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_to_s_level
|
48
|
-
# No indentation due to local setting
|
49
|
-
node = @doc.root
|
50
|
-
assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n </bands>",
|
51
|
-
node.to_s(:level => 1))
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_to_s_encoding
|
55
|
-
# Test encodings
|
56
|
-
node = @doc.root
|
57
|
-
|
58
|
-
# UTF8:
|
59
|
-
# ö - c3 b6 in hex, \303\266 in octal
|
60
|
-
# ü - c3 bc in hex, \303\274 in octal
|
61
|
-
value = node.to_s(:encoding => LibXML::XML::Encoding::UTF_8)
|
62
|
-
assert_equal(Encoding::UTF_8, node.to_s.encoding)
|
63
|
-
assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
|
64
|
-
value)
|
65
|
-
|
66
|
-
# ISO_8859_1:
|
67
|
-
# ö - f6 in hex, \366 in octal
|
68
|
-
# ü - fc in hex, \374 in octal
|
69
|
-
value = node.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1)
|
70
|
-
assert_equal(Encoding::ISO8859_1, value.encoding)
|
71
|
-
assert_equal("<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>".force_encoding(Encoding::ISO8859_1),
|
72
|
-
value)
|
73
|
-
|
74
|
-
# Invalid encoding
|
75
|
-
error = assert_raises(ArgumentError) do
|
76
|
-
node.to_s(:encoding => -9999)
|
77
|
-
end
|
78
|
-
assert_equal('Unknown encoding value: -9999', error.to_s)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_inner_xml
|
82
|
-
# Default to_s has indentation
|
83
|
-
node = @doc.root
|
84
|
-
|
85
|
-
assert_equal(Encoding::UTF_8, node.inner_xml.encoding)
|
86
|
-
assert_equal("<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>",
|
87
|
-
node.inner_xml)
|
88
|
-
end
|
89
|
-
|
90
|
-
# --- Debug ---
|
91
|
-
def test_debug
|
92
|
-
assert(@doc.root.debug)
|
93
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative './test_helper'
|
4
|
+
|
5
|
+
class TestNodeWrite < Minitest::Test
|
6
|
+
def setup
|
7
|
+
load_encoding("utf-8")
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
@doc = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def load_encoding(name)
|
15
|
+
@encoding = Encoding.find(name)
|
16
|
+
@file_name = "model/bands.#{name.downcase}.xml"
|
17
|
+
|
18
|
+
file = File.join(File.dirname(__FILE__), @file_name)
|
19
|
+
@doc = LibXML::XML::Document.file(file, options: LibXML::XML::Parser::Options::NOBLANKS)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_to_s_default
|
23
|
+
# Default to_s has indentation
|
24
|
+
node = @doc.root
|
25
|
+
assert_equal(Encoding::UTF_8, node.to_s.encoding)
|
26
|
+
assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
|
27
|
+
node.to_s)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_to_s_no_global_indentation
|
31
|
+
# No indentation due to global setting
|
32
|
+
node = @doc.root
|
33
|
+
LibXML::XML.indent_tree_output = false
|
34
|
+
assert_equal("<bands genre=\"metal\">\n<m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n<iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
|
35
|
+
node.to_s)
|
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
|
+
node = @doc.root
|
43
|
+
assert_equal("<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>",
|
44
|
+
node.to_s(:indent => false))
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_to_s_level
|
48
|
+
# No indentation due to local setting
|
49
|
+
node = @doc.root
|
50
|
+
assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n </bands>",
|
51
|
+
node.to_s(:level => 1))
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_to_s_encoding
|
55
|
+
# Test encodings
|
56
|
+
node = @doc.root
|
57
|
+
|
58
|
+
# UTF8:
|
59
|
+
# ö - c3 b6 in hex, \303\266 in octal
|
60
|
+
# ü - c3 bc in hex, \303\274 in octal
|
61
|
+
value = node.to_s(:encoding => LibXML::XML::Encoding::UTF_8)
|
62
|
+
assert_equal(Encoding::UTF_8, node.to_s.encoding)
|
63
|
+
assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
|
64
|
+
value)
|
65
|
+
|
66
|
+
# ISO_8859_1:
|
67
|
+
# ö - f6 in hex, \366 in octal
|
68
|
+
# ü - fc in hex, \374 in octal
|
69
|
+
value = node.to_s(:encoding => LibXML::XML::Encoding::ISO_8859_1)
|
70
|
+
assert_equal(Encoding::ISO8859_1, value.encoding)
|
71
|
+
assert_equal("<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>".force_encoding(Encoding::ISO8859_1),
|
72
|
+
value)
|
73
|
+
|
74
|
+
# Invalid encoding
|
75
|
+
error = assert_raises(ArgumentError) do
|
76
|
+
node.to_s(:encoding => -9999)
|
77
|
+
end
|
78
|
+
assert_equal('Unknown encoding value: -9999', error.to_s)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_inner_xml
|
82
|
+
# Default to_s has indentation
|
83
|
+
node = @doc.root
|
84
|
+
|
85
|
+
assert_equal(Encoding::UTF_8, node.inner_xml.encoding)
|
86
|
+
assert_equal("<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>",
|
87
|
+
node.inner_xml)
|
88
|
+
end
|
89
|
+
|
90
|
+
# --- Debug ---
|
91
|
+
def test_debug
|
92
|
+
assert(@doc.root.debug)
|
93
|
+
end
|
94
94
|
end
|