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_node.rb
CHANGED
@@ -1,181 +1,258 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
def
|
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
|
-
assert_instance_of(XML::
|
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
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class TestNode < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
load_encoding("utf-8")
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
XML.default_keep_blanks = true
|
13
|
+
@doc = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def load_encoding(name)
|
17
|
+
@encoding = Encoding.find(name) if defined?(Encoding)
|
18
|
+
@file_name = "model/bands.#{name.downcase}.xml"
|
19
|
+
|
20
|
+
# Strip spaces to make testing easier
|
21
|
+
XML.default_keep_blanks = false
|
22
|
+
file = File.join(File.dirname(__FILE__), @file_name)
|
23
|
+
@doc = XML::Document.file(file)
|
24
|
+
end
|
25
|
+
|
26
|
+
def nodes
|
27
|
+
# Find all nodes with a country attributes
|
28
|
+
@doc.find('*[@country]')
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_doc_class
|
32
|
+
assert_instance_of(XML::Document, @doc)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_doc_node_type
|
36
|
+
assert_equal XML::Node::DOCUMENT_NODE, @doc.node_type
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_root_class
|
40
|
+
assert_instance_of(XML::Node, @doc.root)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_root_node_type
|
44
|
+
assert_equal XML::Node::ELEMENT_NODE, @doc.root.node_type
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_node_class
|
48
|
+
for n in nodes
|
49
|
+
assert_instance_of(XML::Node, n)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_context
|
54
|
+
node = @doc.root
|
55
|
+
context = node.context
|
56
|
+
assert_instance_of(XML::XPath::Context, context)
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_find
|
60
|
+
assert_instance_of(XML::XPath::Object, self.nodes)
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_node_child_get
|
64
|
+
assert_instance_of(TrueClass, @doc.root.child?)
|
65
|
+
assert_instance_of(XML::Node, @doc.root.child)
|
66
|
+
|
67
|
+
if defined?(Encoding)
|
68
|
+
assert_equal(@encoding, @doc.root.child.name.encoding)
|
69
|
+
assert_equal("m\u00F6tley_cr\u00FCe", @doc.root.child.name)
|
70
|
+
else
|
71
|
+
assert_equal("m\303\266tley_cr\303\274e", @doc.root.child.name)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_node_doc
|
76
|
+
for n in nodes
|
77
|
+
assert_instance_of(XML::Document, n.doc) if n.document?
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_name
|
82
|
+
if defined?(Encoding)
|
83
|
+
assert_equal(@encoding, nodes[0].name.encoding)
|
84
|
+
assert_equal("m\u00F6tley_cr\u00FCe", nodes[0].name)
|
85
|
+
else
|
86
|
+
assert_equal("m\303\266tley_cr\303\274e", nodes[0].name)
|
87
|
+
end
|
88
|
+
assert_equal("iron_maiden", nodes[1].name)
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_name_iso_8859_1
|
92
|
+
load_encoding("iso-8859-1")
|
93
|
+
|
94
|
+
if defined?(Encoding)
|
95
|
+
assert_equal(@encoding, nodes[0].name.encoding)
|
96
|
+
assert_equal("m\303\266tley_cr\303\274e".force_encoding(@encoding), nodes[0].name)
|
97
|
+
else
|
98
|
+
assert_equal("m\303\266tley_cr\303\274e", nodes[0].name)
|
99
|
+
end
|
100
|
+
assert_equal("iron_maiden", nodes[1].name)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_node_find
|
104
|
+
nodes = @doc.root.find('./fixnum')
|
105
|
+
for node in nodes
|
106
|
+
assert_instance_of(XML::Node, node)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_equality
|
111
|
+
node_a = @doc.find_first('*[@country]')
|
112
|
+
node_b = @doc.root.child
|
113
|
+
|
114
|
+
assert(node_a == node_b)
|
115
|
+
assert(node_a.eql?(node_b))
|
116
|
+
assert(node_a.equal?(node_b))
|
117
|
+
|
118
|
+
file = File.join(File.dirname(__FILE__), @file_name)
|
119
|
+
doc2 = XML::Document.file(file)
|
120
|
+
|
121
|
+
node_a2 = doc2.find_first('*[@country]')
|
122
|
+
|
123
|
+
assert_equal(node_a.to_s, node_a2.to_s)
|
124
|
+
assert_equal(node_a, node_a2)
|
125
|
+
assert(node_a.eql?(node_a2))
|
126
|
+
assert(!node_a.equal?(node_a2))
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_equality_nil
|
130
|
+
node = @doc.root
|
131
|
+
assert(node != nil)
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_equality_wrong_type
|
135
|
+
node = @doc.root
|
136
|
+
|
137
|
+
assert_raise(TypeError) do
|
138
|
+
assert(node != 'abc')
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_content
|
143
|
+
if defined?(Encoding)
|
144
|
+
assert_equal(@encoding, @doc.root.content.encoding)
|
145
|
+
assert_equal("M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.",
|
146
|
+
@doc.root.content)
|
147
|
+
|
148
|
+
first = @doc.root.child
|
149
|
+
assert_equal("M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.",
|
150
|
+
first.content)
|
151
|
+
assert_equal("Iron Maiden is a British heavy metal band formed in 1975.", first.next.content)
|
152
|
+
else
|
153
|
+
assert_equal("M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.",
|
154
|
+
@doc.root.content)
|
155
|
+
|
156
|
+
first = @doc.root.child
|
157
|
+
assert_equal("M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.",
|
158
|
+
first.content)
|
159
|
+
assert_equal("Iron Maiden is a British heavy metal band formed in 1975.",
|
160
|
+
first.next.content)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_content_iso_8859_1
|
165
|
+
load_encoding("iso-8859-1")
|
166
|
+
if defined?(Encoding)
|
167
|
+
assert_equal(@encoding, @doc.root.content.encoding)
|
168
|
+
assert_equal("M\xC3\xB6tley Cr\xC3\xBCe is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.".force_encoding(@encoding),
|
169
|
+
@doc.root.content)
|
170
|
+
|
171
|
+
first = @doc.root.child
|
172
|
+
assert_equal("M\xC3\xB6tley Cr\xC3\xBCe is an American heavy metal band formed in Los Angeles, California in 1981.".force_encoding(@encoding),
|
173
|
+
first.content)
|
174
|
+
assert_equal("Iron Maiden is a British heavy metal band formed in 1975.", first.next.content)
|
175
|
+
else
|
176
|
+
assert_equal("M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.Iron Maiden is a British heavy metal band formed in 1975.",
|
177
|
+
@doc.root.content)
|
178
|
+
|
179
|
+
first = @doc.root.child
|
180
|
+
assert_equal("M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.",
|
181
|
+
first.content)
|
182
|
+
assert_equal("Iron Maiden is a British heavy metal band formed in 1975.", first.next.content)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_base
|
187
|
+
doc = XML::Parser.string('<person />').parse
|
188
|
+
assert_nil(doc.root.base_uri)
|
189
|
+
end
|
190
|
+
|
191
|
+
# We use the same facility that libXSLT does here to disable output escaping.
|
192
|
+
# This lets you specify that the node's content should be rendered unaltered
|
193
|
+
# whenever it is being output. This is useful for things like <script> and
|
194
|
+
# <style> nodes in HTML documents if you don't want to be forced to wrap them
|
195
|
+
# in CDATA nodes. Or if you are sanitizing existing HTML documents and want
|
196
|
+
# to preserve the content of any of the text nodes.
|
197
|
+
#
|
198
|
+
def test_output_escaping
|
199
|
+
text = '<bad-script>if (a < b || b > c) { return "text"; }<stop/>return ">>>snip<<<";</bad-script>'
|
200
|
+
node = XML::Parser.string(text).parse.root
|
201
|
+
assert_equal text, node.to_s
|
202
|
+
|
203
|
+
text_noenc = '<bad-script>if (a < b || b > c) { return "text"; }<stop/>return ">>>snip<<<";</bad-script>'
|
204
|
+
node.output_escaping = false
|
205
|
+
assert_equal text_noenc, node.to_s
|
206
|
+
|
207
|
+
node.output_escaping = true
|
208
|
+
assert_equal text, node.to_s
|
209
|
+
|
210
|
+
node.output_escaping = nil
|
211
|
+
assert_equal text_noenc, node.to_s
|
212
|
+
|
213
|
+
node.output_escaping = true
|
214
|
+
assert_equal text, node.to_s
|
215
|
+
end
|
216
|
+
|
217
|
+
# Just a sanity check for output escaping.
|
218
|
+
def test_output_escaping_sanity
|
219
|
+
text = '<bad-script>if (a < b || b > c) { return "text"; }<stop/>return ">>>snip<<<";</bad-script>'
|
220
|
+
node = XML::Parser.string(text).parse.root
|
221
|
+
affected = node.find('//text()')
|
222
|
+
|
223
|
+
check_escaping = lambda do |flag|
|
224
|
+
assert_equal('bad-script', node.name)
|
225
|
+
assert_equal(flag, node.output_escaping?)
|
226
|
+
affected.each do |x|
|
227
|
+
assert_equal(flag ? 'text' : 'textnoenc', x.name)
|
228
|
+
assert_equal(flag, x.output_escaping?)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
node.output_escaping = false
|
233
|
+
check_escaping[false]
|
234
|
+
|
235
|
+
node.output_escaping = true
|
236
|
+
check_escaping[true]
|
237
|
+
|
238
|
+
node.output_escaping = nil
|
239
|
+
check_escaping[false]
|
240
|
+
|
241
|
+
node.output_escaping = true
|
242
|
+
check_escaping[true]
|
243
|
+
|
244
|
+
affected.first.output_escaping = true
|
245
|
+
affected.last.output_escaping = false
|
246
|
+
assert node.output_escaping?.nil?
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_space_preserve
|
250
|
+
node = @doc.root
|
251
|
+
|
252
|
+
node.space_preserve = false
|
253
|
+
assert_equal XML::Node::SPACE_DEFAULT, node.space_preserve
|
254
|
+
|
255
|
+
node.space_preserve = true
|
256
|
+
assert_equal XML::Node::SPACE_PRESERVE, node.space_preserve
|
257
|
+
end
|
181
258
|
end
|
data/test/tc_node_cdata.rb
CHANGED
@@ -1,49 +1,51 @@
|
|
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
|
-
@root.
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
require 'test/unit'
|
5
|
+
|
6
|
+
class CDataCommentTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
xp = XML::Parser.string('<root></root>')
|
9
|
+
@doc = xp.parse
|
10
|
+
assert_instance_of(XML::Document, @doc)
|
11
|
+
@root = @doc.root
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_node_type
|
15
|
+
cnode = XML::Node.new_cdata('test cdata')
|
16
|
+
assert_equal(XML::Node::CDATA_SECTION_NODE, cnode.node_type)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_add_cdata
|
20
|
+
@root << XML::Node.new_cdata('mycdata')
|
21
|
+
assert_equal '<root><![CDATA[mycdata]]></root>',
|
22
|
+
@root.to_s.gsub(/\n\s*/,'')
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_add_cdata_2
|
26
|
+
@root << XML::Node.new_cdata('mycdata')
|
27
|
+
assert_equal 'cdata',
|
28
|
+
@root.child.node_type_name
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_add_cdata_3
|
32
|
+
@root << el = XML::Node.new_cdata('mycdata')
|
33
|
+
el << "_this_is_added"
|
34
|
+
assert_equal '<root><![CDATA[mycdata_this_is_added]]></root>',
|
35
|
+
@root.to_s.gsub(/\n\s*/,'')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_attributes
|
39
|
+
cnode = XML::Node.new_cdata('test cdata')
|
40
|
+
assert_equal(0, cnode.attributes.length)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_set_cdata_attribute
|
44
|
+
cnode = XML::Node.new_cdata('test cdata')
|
45
|
+
|
46
|
+
# Can't create attributes on non-element nodes
|
47
|
+
assert_raise(ArgumentError) do
|
48
|
+
cnode['attr'] = '123'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|