libxml-ruby 1.1.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → HISTORY} +35 -0
- data/LICENSE +1 -0
- data/MANIFEST +165 -0
- data/{README → README.rdoc} +2 -2
- data/Rakefile +47 -147
- data/ext/libxml/libxml.c +17 -1
- data/ext/libxml/ruby_libxml.h +9 -1
- data/ext/libxml/ruby_xml_attr.c +3 -3
- data/ext/libxml/ruby_xml_attr_decl.c +32 -32
- data/ext/libxml/ruby_xml_attributes.c +1 -1
- data/ext/libxml/ruby_xml_cbg.c +1 -2
- data/ext/libxml/ruby_xml_document.c +26 -4
- data/ext/libxml/ruby_xml_dtd.c +3 -3
- data/ext/libxml/ruby_xml_encoding.c +92 -5
- data/ext/libxml/ruby_xml_encoding.h +4 -0
- data/ext/libxml/ruby_xml_namespace.c +2 -2
- data/ext/libxml/ruby_xml_node.c +14 -14
- data/ext/libxml/ruby_xml_parser_context.c +8 -8
- data/ext/libxml/ruby_xml_reader.c +98 -43
- data/ext/libxml/ruby_xml_sax2_handler.c +13 -1
- data/ext/libxml/ruby_xml_sax_parser.c +4 -5
- data/ext/libxml/ruby_xml_version.h +5 -5
- data/ext/libxml/ruby_xml_xpath_context.c +9 -6
- data/ext/libxml/ruby_xml_xpath_object.c +1 -1
- data/ext/vc/libxml_ruby.sln +4 -4
- data/lib/libxml.rb +29 -29
- data/lib/libxml/attr.rb +112 -110
- data/lib/libxml/attr_decl.rb +2 -0
- data/lib/libxml/attributes.rb +13 -11
- data/lib/libxml/document.rb +192 -190
- data/lib/libxml/error.rb +89 -87
- data/lib/libxml/hpricot.rb +77 -75
- data/lib/libxml/html_parser.rb +96 -94
- data/lib/libxml/namespace.rb +61 -59
- data/lib/libxml/namespaces.rb +37 -35
- data/lib/libxml/node.rb +398 -384
- data/lib/libxml/ns.rb +21 -19
- data/lib/libxml/parser.rb +366 -364
- data/lib/libxml/properties.rb +22 -20
- data/lib/libxml/reader.rb +2 -0
- data/lib/libxml/sax_callbacks.rb +179 -177
- data/lib/libxml/sax_parser.rb +57 -55
- data/lib/libxml/tree.rb +28 -26
- data/lib/libxml/xpath_object.rb +15 -13
- data/lib/xml.rb +16 -14
- data/lib/xml/libxml.rb +10 -8
- data/libxml-ruby.gemspec +50 -0
- data/script/benchmark/depixelate +634 -0
- data/script/benchmark/hamlet.xml +9055 -0
- data/script/benchmark/parsecount +170 -0
- data/script/benchmark/sock_entries.xml +507 -0
- data/script/benchmark/throughput +41 -0
- data/script/test +6 -0
- data/test/etc_doc_to_s.rb +21 -19
- data/test/ets_doc_file.rb +17 -15
- data/test/ets_doc_to_s.rb +23 -21
- data/test/ets_gpx.rb +28 -26
- data/test/ets_node_gc.rb +23 -21
- data/test/ets_tsr.rb +11 -9
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/rb-magic-comment.rb +33 -0
- data/test/tc_attr.rb +181 -170
- data/test/tc_attr_decl.rb +3 -1
- data/test/tc_attributes.rb +134 -132
- data/test/tc_deprecated_require.rb +13 -11
- data/test/tc_document.rb +119 -113
- data/test/tc_document_write.rb +186 -117
- data/test/tc_dtd.rb +125 -123
- data/test/tc_error.rb +3 -1
- data/test/tc_html_parser.rb +139 -137
- data/test/tc_namespace.rb +61 -58
- data/test/tc_namespaces.rb +176 -173
- data/test/tc_node.rb +257 -180
- data/test/tc_node_cdata.rb +51 -49
- data/test/tc_node_comment.rb +33 -30
- data/test/tc_node_copy.rb +42 -40
- data/test/tc_node_edit.rb +159 -157
- data/test/tc_node_text.rb +71 -69
- data/test/tc_node_write.rb +41 -16
- data/test/tc_node_xlink.rb +29 -26
- data/test/tc_parser.rb +335 -329
- data/test/tc_parser_context.rb +188 -185
- data/test/tc_properties.rb +39 -36
- data/test/tc_reader.rb +297 -283
- data/test/tc_relaxng.rb +54 -51
- data/test/tc_sax_parser.rb +275 -273
- data/test/tc_schema.rb +53 -51
- data/test/tc_traversal.rb +222 -220
- data/test/tc_xinclude.rb +21 -19
- data/test/tc_xml.rb +3 -1
- data/test/tc_xpath.rb +195 -193
- data/test/tc_xpath_context.rb +80 -78
- data/test/tc_xpath_expression.rb +38 -35
- data/test/tc_xpointer.rb +74 -72
- data/test/test_helper.rb +14 -0
- data/test/test_suite.rb +39 -33
- metadata +65 -105
- data/doc/css/normal.css +0 -182
- data/doc/img/raze-tiny.png +0 -0
- data/doc/img/red-cube.jpg +0 -0
- data/doc/img/xml-ruby.png +0 -0
- data/doc/index.xml +0 -43
- data/doc/install.xml +0 -77
- data/doc/layout.rhtml +0 -38
- data/doc/layout.xsl +0 -67
- data/doc/license.xml +0 -32
- data/doc/log/changelog.xml +0 -1324
- data/doc/log/changelog.xsl +0 -42
- data/ext/libxml/Makefile +0 -156
- data/ext/libxml/extconf.h +0 -5
- data/ext/libxml/libxml-ruby.so.a +0 -0
- data/ext/libxml/libxml.o +0 -0
- data/ext/libxml/libxml_ruby.so +0 -0
- data/ext/libxml/mkmf.log +0 -129
- data/ext/libxml/ruby_xml.o +0 -0
- data/ext/libxml/ruby_xml_attr.o +0 -0
- data/ext/libxml/ruby_xml_attr_decl.o +0 -0
- data/ext/libxml/ruby_xml_attributes.o +0 -0
- data/ext/libxml/ruby_xml_cbg.o +0 -0
- data/ext/libxml/ruby_xml_document.o +0 -0
- data/ext/libxml/ruby_xml_dtd.o +0 -0
- data/ext/libxml/ruby_xml_encoding.o +0 -0
- data/ext/libxml/ruby_xml_error.o +0 -0
- data/ext/libxml/ruby_xml_html_parser.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
- data/ext/libxml/ruby_xml_input_cbg.o +0 -0
- data/ext/libxml/ruby_xml_io.o +0 -0
- data/ext/libxml/ruby_xml_namespace.o +0 -0
- data/ext/libxml/ruby_xml_namespaces.o +0 -0
- data/ext/libxml/ruby_xml_node.o +0 -0
- data/ext/libxml/ruby_xml_parser.o +0 -0
- data/ext/libxml/ruby_xml_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_parser_options.o +0 -0
- data/ext/libxml/ruby_xml_reader.o +0 -0
- data/ext/libxml/ruby_xml_relaxng.o +0 -0
- data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
- data/ext/libxml/ruby_xml_sax_parser.o +0 -0
- data/ext/libxml/ruby_xml_schema.o +0 -0
- data/ext/libxml/ruby_xml_xinclude.o +0 -0
- data/ext/libxml/ruby_xml_xpath.o +0 -0
- data/ext/libxml/ruby_xml_xpath_context.o +0 -0
- data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
- data/ext/libxml/ruby_xml_xpath_object.o +0 -0
- data/ext/libxml/ruby_xml_xpointer.o +0 -0
data/test/tc_document_write.rb
CHANGED
@@ -1,118 +1,187 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
require 'tmpdir'
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TestDocumentWrite < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
load_encoding("utf-8")
|
10
|
+
end
|
11
|
+
|
12
|
+
def teardown
|
13
|
+
XML.default_keep_blanks = true
|
14
|
+
@doc = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_encoding(name)
|
18
|
+
@encoding = Encoding.find(name) if defined?(Encoding)
|
19
|
+
@file_name = "model/bands.#{name.downcase}.xml"
|
20
|
+
|
21
|
+
# Strip spaces to make testing easier
|
22
|
+
XML.default_keep_blanks = false
|
23
|
+
file = File.join(File.dirname(__FILE__), @file_name)
|
24
|
+
@doc = XML::Document.file(file)
|
25
|
+
end
|
26
|
+
|
27
|
+
# --- to_s tests ---
|
28
|
+
def test_to_s_default
|
29
|
+
# Default to_s has indentation
|
30
|
+
if defined?(Encoding)
|
31
|
+
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",
|
32
|
+
@doc.to_s)
|
33
|
+
else
|
34
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<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>\n",
|
35
|
+
@doc.to_s)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_to_s_no_global_indentation
|
40
|
+
# No indentation due to global setting
|
41
|
+
XML.indent_tree_output = false
|
42
|
+
value = @doc.to_s
|
43
|
+
|
44
|
+
if defined?(Encoding)
|
45
|
+
assert_equal(Encoding::UTF_8, value.encoding)
|
46
|
+
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",
|
47
|
+
value)
|
48
|
+
else
|
49
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<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>\n",
|
50
|
+
value)
|
51
|
+
end
|
52
|
+
ensure
|
53
|
+
XML.indent_tree_output = true
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_to_s_no_indentation
|
57
|
+
# No indentation due to local setting
|
58
|
+
value = @doc.to_s(:indent => false)
|
59
|
+
if defined?(Encoding)
|
60
|
+
assert_equal(Encoding::UTF_8, value.encoding)
|
61
|
+
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",
|
62
|
+
value)
|
63
|
+
else
|
64
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<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>\n",
|
65
|
+
value)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_to_s_encoding
|
70
|
+
# Test encodings
|
71
|
+
|
72
|
+
# UTF8:
|
73
|
+
# ö - c3 b6 in hex, \303\266 in octal
|
74
|
+
# ü - c3 bc in hex, \303\274 in octal
|
75
|
+
value = @doc.to_s(:encoding => XML::Encoding::UTF_8)
|
76
|
+
if defined?(Encoding)
|
77
|
+
assert_equal(Encoding::UTF_8, value.encoding)
|
78
|
+
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",
|
79
|
+
value)
|
80
|
+
else
|
81
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<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>\n",
|
82
|
+
value)
|
83
|
+
end
|
84
|
+
|
85
|
+
# ISO_8859_1:
|
86
|
+
# ö - f6 in hex, \366 in octal
|
87
|
+
# ü - fc in hex, \374 in octal
|
88
|
+
value = @doc.to_s(:encoding => XML::Encoding::ISO_8859_1)
|
89
|
+
if defined?(Encoding)
|
90
|
+
assert_equal(Encoding::ISO8859_1, value.encoding)
|
91
|
+
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),
|
92
|
+
@doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
|
93
|
+
else
|
94
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">M\366tley Cr\374e is an American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
|
95
|
+
@doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
|
96
|
+
end
|
97
|
+
|
98
|
+
# Invalid encoding
|
99
|
+
error = assert_raise(ArgumentError) do
|
100
|
+
@doc.to_s(:encoding => -9999)
|
101
|
+
end
|
102
|
+
assert_equal('Unknown encoding value: -9999', error.to_s)
|
103
|
+
end
|
104
|
+
|
105
|
+
# --- save tests -----
|
106
|
+
def test_save_utf8
|
107
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8.xml")
|
108
|
+
|
109
|
+
bytes = @doc.save(temp_filename)
|
110
|
+
assert_equal(305, bytes)
|
111
|
+
|
112
|
+
if defined?(Encoding)
|
113
|
+
contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
|
114
|
+
assert_equal(Encoding::UTF_8, contents.encoding)
|
115
|
+
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",
|
116
|
+
contents)
|
117
|
+
else
|
118
|
+
contents = File.read(temp_filename)
|
119
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<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>\n",
|
120
|
+
contents)
|
121
|
+
end
|
122
|
+
ensure
|
123
|
+
File.delete(temp_filename)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_save_utf8_no_indents
|
127
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8_no_indents.xml")
|
128
|
+
|
129
|
+
bytes = @doc.save(temp_filename, :indent => false)
|
130
|
+
assert_equal(298, bytes)
|
131
|
+
|
132
|
+
if defined?(Encoding)
|
133
|
+
contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
|
134
|
+
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",
|
135
|
+
contents)
|
136
|
+
else
|
137
|
+
contents = File.read(temp_filename)
|
138
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<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>\n",
|
139
|
+
contents)
|
140
|
+
end
|
141
|
+
ensure
|
142
|
+
File.delete(temp_filename)
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_save_iso_8859_1
|
146
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml")
|
147
|
+
bytes = @doc.save(temp_filename, :encoding => XML::Encoding::ISO_8859_1)
|
148
|
+
assert_equal(304, bytes)
|
149
|
+
|
150
|
+
if defined?(Encoding)
|
151
|
+
contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
|
152
|
+
assert_equal(Encoding::ISO8859_1, contents.encoding)
|
153
|
+
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),
|
154
|
+
contents)
|
155
|
+
else
|
156
|
+
contents = File.read(temp_filename)
|
157
|
+
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",
|
158
|
+
contents)
|
159
|
+
end
|
160
|
+
ensure
|
161
|
+
File.delete(temp_filename)
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_save_iso_8859_1_no_indent
|
165
|
+
temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml")
|
166
|
+
bytes = @doc.save(temp_filename, :indent => false, :encoding => XML::Encoding::ISO_8859_1)
|
167
|
+
assert_equal(297, bytes)
|
168
|
+
|
169
|
+
if defined?(Encoding)
|
170
|
+
contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
|
171
|
+
assert_equal(Encoding::ISO8859_1, contents.encoding)
|
172
|
+
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),
|
173
|
+
contents)
|
174
|
+
else
|
175
|
+
contents = File.read(temp_filename)
|
176
|
+
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",
|
177
|
+
contents)
|
178
|
+
end
|
179
|
+
ensure
|
180
|
+
File.delete(temp_filename)
|
181
|
+
end
|
182
|
+
|
183
|
+
# --- Debug ---
|
184
|
+
def test_debug
|
185
|
+
assert(@doc.debug)
|
186
|
+
end
|
118
187
|
end
|
data/test/tc_dtd.rb
CHANGED
@@ -1,123 +1,125 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
assert_equal "xhtml1", xhtml_dtd.
|
40
|
-
|
41
|
-
|
42
|
-
assert_equal "
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
assert_equal "xhtml1", xhtml_dtd.
|
54
|
-
|
55
|
-
|
56
|
-
assert_equal "
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
assert_equal(
|
78
|
-
assert_equal(XML::Error::
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
assert_equal(
|
85
|
-
|
86
|
-
|
87
|
-
assert_equal(
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
errors.
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
class TestDtd < Test::Unit::TestCase
|
8
|
+
def setup
|
9
|
+
xp = XML::Parser.string(<<-EOS)
|
10
|
+
<root>
|
11
|
+
<head a="ee" id="1">Colorado</head>
|
12
|
+
<descr>Lots of nice mountains</descr>
|
13
|
+
</root>
|
14
|
+
EOS
|
15
|
+
@doc = xp.parse
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown
|
19
|
+
@doc = nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def dtd
|
23
|
+
XML::Dtd.new(<<-EOS)
|
24
|
+
<!ELEMENT root (head, descr)>
|
25
|
+
<!ELEMENT head (#PCDATA)>
|
26
|
+
<!ATTLIST head
|
27
|
+
id NMTOKEN #REQUIRED
|
28
|
+
a CDATA #IMPLIED
|
29
|
+
>
|
30
|
+
<!ELEMENT descr (#PCDATA)>
|
31
|
+
EOS
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_internal_subset
|
35
|
+
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
|
36
|
+
assert xhtml_dtd.name.nil?
|
37
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
38
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
39
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
40
|
+
|
41
|
+
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
|
42
|
+
assert_equal "xhtml1", xhtml_dtd.name
|
43
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
44
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
45
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_external_subset
|
49
|
+
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil
|
50
|
+
assert xhtml_dtd.name.nil?
|
51
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
52
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
53
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
54
|
+
|
55
|
+
xhtml_dtd = XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", "xhtml1"
|
56
|
+
assert_equal "xhtml1", xhtml_dtd.name
|
57
|
+
assert_equal "-//W3C//DTD XHTML 1.0 Transitional//EN", xhtml_dtd.external_id
|
58
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.uri
|
59
|
+
assert_equal "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", xhtml_dtd.system_id
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_valid
|
63
|
+
assert(@doc.validate(dtd))
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_invalid
|
67
|
+
new_node = XML::Node.new('invalid', 'this will mess up validation')
|
68
|
+
@doc.root << new_node
|
69
|
+
|
70
|
+
error = assert_raise(XML::Error) do
|
71
|
+
@doc.validate(dtd)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Check the error worked
|
75
|
+
assert_not_nil(error)
|
76
|
+
assert_kind_of(XML::Error, error)
|
77
|
+
assert_equal("Error: No declaration for element invalid.", error.message)
|
78
|
+
assert_equal(XML::Error::VALID, error.domain)
|
79
|
+
assert_equal(XML::Error::DTD_UNKNOWN_ELEM, error.code)
|
80
|
+
assert_equal(XML::Error::ERROR, error.level)
|
81
|
+
assert_nil(error.file)
|
82
|
+
assert_nil(error.line)
|
83
|
+
assert_equal('invalid', error.str1)
|
84
|
+
assert_equal('invalid', error.str2)
|
85
|
+
assert_nil(error.str3)
|
86
|
+
assert_equal(0, error.int1)
|
87
|
+
assert_equal(0, error.int2)
|
88
|
+
assert_not_nil(error.node)
|
89
|
+
assert_equal('invalid', error.node.name)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_external_dtd
|
93
|
+
xml = <<-EOS
|
94
|
+
<!DOCTYPE test PUBLIC "-//TEST" "test.dtd" []>
|
95
|
+
<test>
|
96
|
+
<title>T1</title>
|
97
|
+
</test>
|
98
|
+
EOS
|
99
|
+
|
100
|
+
errors = Array.new
|
101
|
+
XML::Error.set_handler do |error|
|
102
|
+
errors << error
|
103
|
+
end
|
104
|
+
|
105
|
+
XML.default_load_external_dtd = false
|
106
|
+
doc = XML::Parser.string(xml).parse
|
107
|
+
assert_equal(0, errors.length)
|
108
|
+
|
109
|
+
errors.clear
|
110
|
+
XML.default_load_external_dtd = true
|
111
|
+
doc = XML::Parser.string(xml).parse
|
112
|
+
assert_equal(1, errors.length)
|
113
|
+
assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
|
114
|
+
errors[0].to_s)
|
115
|
+
|
116
|
+
errors = Array.new
|
117
|
+
doc = XML::Parser.string(xml, :options => XML::Parser::Options::DTDLOAD).parse
|
118
|
+
assert_equal(1, errors.length)
|
119
|
+
assert_equal("Warning: failed to load external entity \"test.dtd\" at :1.",
|
120
|
+
errors[0].to_s)
|
121
|
+
ensure
|
122
|
+
XML.default_load_external_dtd = false
|
123
|
+
XML::Error.reset_handler
|
124
|
+
end
|
125
|
+
end
|