libxml-ruby 2.9.0-x64-mingw32 → 3.0.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY +811 -790
- data/LICENSE +20 -20
- data/MANIFEST +166 -166
- data/README.rdoc +188 -184
- data/Rakefile +1 -1
- data/ext/libxml/libxml.c +80 -80
- data/ext/libxml/ruby_libxml.h +75 -75
- data/ext/libxml/ruby_xml.c +0 -84
- data/ext/libxml/ruby_xml.h +0 -10
- data/ext/libxml/ruby_xml_attr.h +12 -12
- data/ext/libxml/ruby_xml_attr_decl.c +153 -153
- data/ext/libxml/ruby_xml_attr_decl.h +11 -11
- data/ext/libxml/ruby_xml_attributes.c +275 -275
- data/ext/libxml/ruby_xml_attributes.h +15 -15
- data/ext/libxml/ruby_xml_document.c +21 -27
- data/ext/libxml/ruby_xml_document.h +11 -11
- data/ext/libxml/ruby_xml_dtd.c +2 -13
- data/ext/libxml/ruby_xml_dtd.h +9 -9
- data/ext/libxml/ruby_xml_error.c +996 -996
- data/ext/libxml/ruby_xml_error.h +12 -12
- data/ext/libxml/ruby_xml_html_parser.c +89 -92
- data/ext/libxml/ruby_xml_html_parser.h +10 -10
- data/ext/libxml/ruby_xml_html_parser_context.h +10 -10
- data/ext/libxml/ruby_xml_html_parser_options.c +46 -46
- data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_input_cbg.h +20 -20
- data/ext/libxml/ruby_xml_io.c +0 -1
- data/ext/libxml/ruby_xml_io.h +10 -10
- data/ext/libxml/ruby_xml_namespace.c +153 -153
- data/ext/libxml/ruby_xml_namespace.h +10 -10
- data/ext/libxml/ruby_xml_namespaces.c +293 -293
- data/ext/libxml/ruby_xml_namespaces.h +9 -9
- data/ext/libxml/ruby_xml_node.c +100 -143
- data/ext/libxml/ruby_xml_node.h +13 -11
- data/ext/libxml/ruby_xml_parser.c +91 -94
- data/ext/libxml/ruby_xml_parser.h +12 -12
- data/ext/libxml/ruby_xml_parser_context.h +10 -10
- data/ext/libxml/ruby_xml_parser_options.c +66 -66
- data/ext/libxml/ruby_xml_parser_options.h +12 -12
- data/ext/libxml/ruby_xml_reader.c +45 -37
- data/ext/libxml/ruby_xml_reader.h +17 -17
- data/ext/libxml/ruby_xml_relaxng.h +10 -10
- data/ext/libxml/ruby_xml_sax2_handler.c +3 -3
- data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
- data/ext/libxml/ruby_xml_sax_parser.c +116 -120
- data/ext/libxml/ruby_xml_sax_parser.h +10 -10
- data/ext/libxml/ruby_xml_schema.h +809 -809
- data/ext/libxml/ruby_xml_schema_attribute.c +109 -109
- data/ext/libxml/ruby_xml_schema_attribute.h +15 -15
- data/ext/libxml/ruby_xml_schema_element.c +94 -94
- data/ext/libxml/ruby_xml_schema_element.h +14 -14
- data/ext/libxml/ruby_xml_schema_facet.c +52 -52
- data/ext/libxml/ruby_xml_schema_facet.h +13 -13
- data/ext/libxml/ruby_xml_schema_type.c +259 -259
- data/ext/libxml/ruby_xml_schema_type.h +9 -9
- data/ext/libxml/ruby_xml_version.h +9 -9
- data/ext/libxml/ruby_xml_writer.c +1136 -1136
- data/ext/libxml/ruby_xml_writer.h +10 -10
- data/ext/libxml/ruby_xml_xinclude.c +16 -16
- data/ext/libxml/ruby_xml_xinclude.h +11 -11
- data/ext/libxml/ruby_xml_xpath.c +42 -36
- data/ext/libxml/ruby_xml_xpath.h +13 -13
- data/ext/libxml/ruby_xml_xpath_context.c +1 -1
- data/ext/libxml/ruby_xml_xpath_context.h +9 -9
- data/ext/libxml/ruby_xml_xpath_expression.c +81 -81
- data/ext/libxml/ruby_xml_xpath_expression.h +10 -10
- data/ext/libxml/ruby_xml_xpath_object.c +5 -2
- data/ext/libxml/ruby_xml_xpath_object.h +17 -17
- data/ext/libxml/ruby_xml_xpointer.c +99 -99
- data/ext/libxml/ruby_xml_xpointer.h +11 -11
- data/ext/vc/libxml_ruby.sln +17 -15
- data/lib/2.4/libxml_ruby.so +0 -0
- data/lib/libs/libxml2-2.dll +0 -0
- data/lib/libs/zlib1.dll +0 -0
- data/lib/libxml.rb +1 -6
- data/lib/libxml/node.rb +2 -78
- data/lib/libxml/parser.rb +0 -266
- data/lib/libxml/sax_parser.rb +0 -17
- data/lib/libxml/schema.rb +66 -66
- data/lib/libxml/schema/attribute.rb +19 -19
- data/lib/libxml/schema/element.rb +27 -27
- data/lib/libxml/schema/type.rb +29 -29
- data/script/benchmark/depixelate +634 -634
- data/script/benchmark/hamlet.xml +9054 -9054
- data/script/benchmark/parsecount +170 -170
- data/script/benchmark/throughput +41 -41
- data/script/test +6 -6
- data/test/c14n/given/example-1.xml +14 -14
- data/test/c14n/given/example-2.xml +11 -11
- data/test/c14n/given/example-3.xml +18 -18
- data/test/c14n/given/example-4.xml +9 -9
- data/test/c14n/given/example-5.xml +12 -12
- data/test/c14n/given/example-6.xml +2 -2
- data/test/c14n/given/example-7.xml +11 -11
- data/test/c14n/given/example-8.xml +11 -11
- data/test/c14n/given/example-8.xpath +9 -9
- data/test/c14n/result/1-1-without-comments/example-1 +3 -3
- data/test/c14n/result/1-1-without-comments/example-2 +10 -10
- data/test/c14n/result/1-1-without-comments/example-3 +13 -13
- data/test/c14n/result/1-1-without-comments/example-4 +8 -8
- data/test/c14n/result/1-1-without-comments/example-5 +2 -2
- data/test/c14n/result/with-comments/example-1 +5 -5
- data/test/c14n/result/with-comments/example-2 +10 -10
- data/test/c14n/result/with-comments/example-3 +13 -13
- data/test/c14n/result/with-comments/example-4 +8 -8
- data/test/c14n/result/with-comments/example-5 +3 -3
- data/test/c14n/result/without-comments/example-1 +3 -3
- data/test/c14n/result/without-comments/example-2 +10 -10
- data/test/c14n/result/without-comments/example-3 +13 -13
- data/test/c14n/result/without-comments/example-4 +8 -8
- data/test/c14n/result/without-comments/example-5 +2 -2
- data/test/model/atom.xml +12 -12
- data/test/model/bands.iso-8859-1.xml +4 -4
- data/test/model/bands.utf-8.xml +4 -4
- data/test/model/bands.xml +4 -4
- data/test/model/books.xml +153 -153
- data/test/model/merge_bug_data.xml +58 -58
- data/test/model/ruby-lang.html +238 -238
- data/test/model/rubynet.xml +79 -79
- data/test/model/shiporder.rnc +28 -28
- data/test/model/shiporder.rng +86 -86
- data/test/model/shiporder.xml +22 -22
- data/test/model/shiporder.xsd +39 -39
- data/test/model/soap.xml +27 -27
- data/test/model/xinclude.xml +4 -4
- data/test/tc_attributes.rb +0 -6
- data/test/tc_error.rb +157 -158
- data/test/tc_node.rb +33 -17
- data/test/tc_node_edit.rb +0 -15
- data/test/tc_node_pi.rb +39 -39
- data/test/tc_parser.rb +0 -48
- data/test/tc_reader.rb +12 -53
- data/test/tc_writer.rb +447 -447
- data/test/tc_xpath.rb +1 -1
- data/test/test_helper.rb +2 -2
- metadata +4 -9
- data/ext/libxml/extconf.h +0 -4
- data/lib/2.3/libxml_ruby.so +0 -0
- data/lib/libxml/ns.rb +0 -22
- data/lib/libxml/properties.rb +0 -23
- data/lib/libxml/reader.rb +0 -29
- data/lib/libxml/xpath_object.rb +0 -16
data/test/tc_node_edit.rb
CHANGED
@@ -66,21 +66,6 @@ class TestNodeEdit < Minitest::Test
|
|
66
66
|
@doc.root.to_s.gsub(/\n\s*/,''))
|
67
67
|
end
|
68
68
|
|
69
|
-
def test_freed_node
|
70
|
-
root = XML::Node.new("root")
|
71
|
-
|
72
|
-
a = XML::Node.new("a")
|
73
|
-
root << a
|
74
|
-
|
75
|
-
a.parent.remove!
|
76
|
-
|
77
|
-
# Node a has now been freed from under us
|
78
|
-
error = assert_raises(RuntimeError) do
|
79
|
-
a.to_s
|
80
|
-
end
|
81
|
-
assert_equal('This node has already been freed.', error.to_s)
|
82
|
-
end
|
83
|
-
|
84
69
|
def test_remove_node_gc
|
85
70
|
xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
|
86
71
|
doc = xp.parse
|
data/test/tc_node_pi.rb
CHANGED
@@ -1,39 +1,39 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require './test_helper'
|
4
|
-
|
5
|
-
|
6
|
-
class NodeCommentTest < Minitest::Test
|
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_libxml_node_add_pi_01
|
15
|
-
@root << XML::Node.new_pi('mypi')
|
16
|
-
assert_equal '<root><?mypi?></root>',
|
17
|
-
@root.to_s.gsub(/\n\s*/,'')
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_libxml_node_add_pi_02
|
21
|
-
@root << XML::Node.new_pi('mypi')
|
22
|
-
assert_equal 'pi',
|
23
|
-
@root.child.node_type_name
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_libxml_node_add_pi_03
|
27
|
-
@root << el = XML::Node.new_pi('mypi')
|
28
|
-
el << "_this_is_added"
|
29
|
-
assert_equal '<root><?mypi _this_is_added?></root>',
|
30
|
-
@root.to_s.gsub(/\n\s*/,'')
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_libxml_node_add_pi_04
|
34
|
-
@root << XML::Node.new_pi('mypi','mycontent')
|
35
|
-
assert_equal '<root><?mypi mycontent?></root>',
|
36
|
-
@root.to_s.gsub(/\n\s*/,'')
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
|
5
|
+
|
6
|
+
class NodeCommentTest < Minitest::Test
|
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_libxml_node_add_pi_01
|
15
|
+
@root << XML::Node.new_pi('mypi')
|
16
|
+
assert_equal '<root><?mypi?></root>',
|
17
|
+
@root.to_s.gsub(/\n\s*/,'')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_libxml_node_add_pi_02
|
21
|
+
@root << XML::Node.new_pi('mypi')
|
22
|
+
assert_equal 'pi',
|
23
|
+
@root.child.node_type_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_libxml_node_add_pi_03
|
27
|
+
@root << el = XML::Node.new_pi('mypi')
|
28
|
+
el << "_this_is_added"
|
29
|
+
assert_equal '<root><?mypi _this_is_added?></root>',
|
30
|
+
@root.to_s.gsub(/\n\s*/,'')
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_libxml_node_add_pi_04
|
34
|
+
@root << XML::Node.new_pi('mypi','mycontent')
|
35
|
+
assert_equal '<root><?mypi mycontent?></root>',
|
36
|
+
@root.to_s.gsub(/\n\s*/,'')
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/test/tc_parser.rb
CHANGED
@@ -300,54 +300,6 @@ class TestParser < Minitest::Test
|
|
300
300
|
assert_nil(error.node)
|
301
301
|
end
|
302
302
|
|
303
|
-
# Deprecated methods
|
304
|
-
def test_document_deprecated
|
305
|
-
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.utf-8.xml'))
|
306
|
-
parser = XML::Parser.file(file)
|
307
|
-
doc = parser.parse
|
308
|
-
|
309
|
-
parser = XML::Parser.new
|
310
|
-
parser.document = doc
|
311
|
-
doc = parser.parse
|
312
|
-
|
313
|
-
assert_instance_of(XML::Document, doc)
|
314
|
-
assert_instance_of(XML::Parser::Context, parser.context)
|
315
|
-
end
|
316
|
-
|
317
|
-
def test_file_deprecated
|
318
|
-
file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
|
319
|
-
|
320
|
-
parser = XML::Parser.new
|
321
|
-
parser.file = file
|
322
|
-
doc = parser.parse
|
323
|
-
assert_instance_of(XML::Document, doc)
|
324
|
-
assert_instance_of(XML::Parser::Context, parser.context)
|
325
|
-
end
|
326
|
-
|
327
|
-
def test_io_deprecated
|
328
|
-
File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
|
329
|
-
parser = XML::Parser.new
|
330
|
-
assert_instance_of(XML::Parser, parser)
|
331
|
-
parser.io = io
|
332
|
-
|
333
|
-
doc = parser.parse
|
334
|
-
assert_instance_of(XML::Document, doc)
|
335
|
-
assert_instance_of(XML::Parser::Context, parser.context)
|
336
|
-
end
|
337
|
-
end
|
338
|
-
|
339
|
-
def test_string_deprecated
|
340
|
-
str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
|
341
|
-
|
342
|
-
parser = XML::Parser.new
|
343
|
-
parser.string = str
|
344
|
-
assert_instance_of(XML::Parser, parser)
|
345
|
-
|
346
|
-
doc = parser.parse
|
347
|
-
assert_instance_of(XML::Document, doc)
|
348
|
-
assert_instance_of(XML::Parser::Context, parser.context)
|
349
|
-
end
|
350
|
-
|
351
303
|
def test_errors_from_background_thread
|
352
304
|
errors = []
|
353
305
|
background_errors = []
|
data/test/tc_reader.rb
CHANGED
@@ -103,35 +103,6 @@ class TestReader < Minitest::Test
|
|
103
103
|
assert_equal("Fatal error: Couldn't find end of Start Tag foo at :1.", error.to_s)
|
104
104
|
end
|
105
105
|
|
106
|
-
def test_deprecated_error_handler
|
107
|
-
called = false
|
108
|
-
reader = XML::Reader.string('<foo blah')
|
109
|
-
reader.set_error_handler do |error|
|
110
|
-
called = true
|
111
|
-
end
|
112
|
-
|
113
|
-
assert_raises(XML::Error) do
|
114
|
-
reader.read
|
115
|
-
end
|
116
|
-
|
117
|
-
assert(called)
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_deprecated_reset_error_handler
|
121
|
-
called = false
|
122
|
-
reader = XML::Reader.string('<foo blah')
|
123
|
-
reader.set_error_handler do |error|
|
124
|
-
called = true
|
125
|
-
end
|
126
|
-
reader.reset_error_handler
|
127
|
-
|
128
|
-
assert_raises(XML::Error) do
|
129
|
-
reader.read
|
130
|
-
end
|
131
|
-
|
132
|
-
assert(!called)
|
133
|
-
end
|
134
|
-
|
135
106
|
def test_attr
|
136
107
|
parser = XML::Reader.string("<foo x='1' y='2'/>")
|
137
108
|
assert(parser.read)
|
@@ -140,18 +111,8 @@ class TestReader < Minitest::Test
|
|
140
111
|
assert_equal('1', parser[0])
|
141
112
|
assert_equal('2', parser['y'])
|
142
113
|
assert_equal('2', parser[1])
|
143
|
-
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
def test_move_to_attribute_depreciation
|
148
|
-
previous_stderr, $stderr = $stderr, StringIO.new
|
149
|
-
reader = XML::Reader.string("<foo x='1' y='2'/>")
|
150
|
-
assert(reader.read)
|
151
|
-
assert(reader.move_to_attribute 1)
|
152
|
-
assert($stderr.string =~ /deprecated/)
|
153
|
-
ensure
|
154
|
-
$stderr = previous_stderr
|
114
|
+
assert_nil(parser['z'])
|
115
|
+
assert_nil(parser[2])
|
155
116
|
end
|
156
117
|
|
157
118
|
def test_move_attr
|
@@ -235,6 +196,9 @@ class TestReader < Minitest::Test
|
|
235
196
|
node = reader.expand
|
236
197
|
assert_equal('feed', node.name)
|
237
198
|
|
199
|
+
# We need to create document to use xpath
|
200
|
+
reader.doc
|
201
|
+
|
238
202
|
# Search for entries
|
239
203
|
entries = node.find('atom:entry', 'atom:http://www.w3.org/2005/Atom')
|
240
204
|
|
@@ -245,16 +209,14 @@ class TestReader < Minitest::Test
|
|
245
209
|
reader = XML::Reader.file(XML_FILE)
|
246
210
|
|
247
211
|
# Expand a node before one has been read
|
248
|
-
|
249
|
-
|
250
|
-
end
|
251
|
-
assert_equal("The reader does not have a document. Did you forget to call read?", error.to_s)
|
212
|
+
node = reader.expand
|
213
|
+
assert_nil(node)
|
252
214
|
end
|
253
215
|
|
254
|
-
def
|
216
|
+
def test_expand_should_be_invalid
|
255
217
|
reader = XML::Reader.file(XML_FILE)
|
256
218
|
|
257
|
-
# Read a
|
219
|
+
# Read a couple of nodes
|
258
220
|
reader.read
|
259
221
|
reader.read
|
260
222
|
|
@@ -265,11 +227,8 @@ class TestReader < Minitest::Test
|
|
265
227
|
# Read another node, this makes the last node invalid
|
266
228
|
reader.next
|
267
229
|
|
268
|
-
# The previous node is now invalid
|
269
|
-
|
270
|
-
assert_equal('feed', node.name)
|
271
|
-
end
|
272
|
-
assert_equal("This node has already been freed.", error.to_s)
|
230
|
+
# The previous node is now invalid - this should be an error but isn't
|
231
|
+
assert_equal('feed', node.name)
|
273
232
|
end
|
274
233
|
|
275
234
|
def test_mode
|
@@ -282,7 +241,7 @@ class TestReader < Minitest::Test
|
|
282
241
|
def test_bytes_consumed
|
283
242
|
reader = XML::Reader.file(XML_FILE)
|
284
243
|
reader.read
|
285
|
-
assert_equal(
|
244
|
+
assert_equal(428, reader.byte_consumed)
|
286
245
|
end
|
287
246
|
|
288
247
|
def test_node
|
data/test/tc_writer.rb
CHANGED
@@ -1,447 +1,447 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require './test_helper'
|
4
|
-
require 'stringio'
|
5
|
-
|
6
|
-
class TestWriter < Minitest::Test
|
7
|
-
XSL_PREFIX = 'xsl'
|
8
|
-
XSL_URI = 'http://www.w3.org/1999/XSL/Transform'
|
9
|
-
|
10
|
-
def test_generic_failure
|
11
|
-
writer = XML::Writer.string
|
12
|
-
writer.start_document
|
13
|
-
assert(!writer.end_element)
|
14
|
-
writer.end_document
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_empty_doc
|
18
|
-
writer = XML::Writer.string
|
19
|
-
document writer
|
20
|
-
assert_equal(writer.result.strip!, '<?xml version="1.0"?>')
|
21
|
-
|
22
|
-
writer = XML::Writer.string
|
23
|
-
document writer, { :encoding => XML::Encoding::ISO_8859_1 }
|
24
|
-
assert_equal(writer.result.strip!, '<?xml version="1.0" encoding="ISO-8859-1"?>')
|
25
|
-
|
26
|
-
writer = XML::Writer.string
|
27
|
-
document writer, { :standalone => 1 }
|
28
|
-
assert_equal(writer.result.strip!, '<?xml version="1.0" standalone="yes"?>')
|
29
|
-
|
30
|
-
writer = XML::Writer.string
|
31
|
-
document writer, { :standalone => 1, :encoding => XML::Encoding::ISO_8859_1, :foo => :bar }
|
32
|
-
assert_equal(writer.result.strip!, '<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>')
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_single_root
|
36
|
-
writer = XML::Writer.string
|
37
|
-
document writer do
|
38
|
-
element writer, 'root'
|
39
|
-
end
|
40
|
-
|
41
|
-
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root/>")
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_pi
|
45
|
-
expected = "<?xml version=\"1.0\"?>\n<?php echo \"foo\";?>"
|
46
|
-
|
47
|
-
writer = XML::Writer.string
|
48
|
-
document writer do
|
49
|
-
assert(writer.start_pi('php'))
|
50
|
-
assert(writer.write_string('echo "foo";'))
|
51
|
-
assert(writer.end_pi)
|
52
|
-
end
|
53
|
-
assert_equal(writer.result.strip!, expected)
|
54
|
-
|
55
|
-
writer = XML::Writer.string
|
56
|
-
document writer do
|
57
|
-
assert(writer.write_pi('php', 'echo "foo";'))
|
58
|
-
end
|
59
|
-
assert_equal(writer.result.strip!, expected)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_comment
|
63
|
-
expected = "<?xml version=\"1.0\"?>\n<!--foo-->"
|
64
|
-
|
65
|
-
writer = XML::Writer.string
|
66
|
-
document writer do
|
67
|
-
assert(writer.start_comment)
|
68
|
-
assert(writer.write_string 'foo')
|
69
|
-
assert(writer.end_comment)
|
70
|
-
end
|
71
|
-
assert_equal(writer.result.strip!, expected)
|
72
|
-
|
73
|
-
writer = XML::Writer.string
|
74
|
-
document writer do
|
75
|
-
assert(writer.write_comment 'foo')
|
76
|
-
end
|
77
|
-
assert_equal(writer.result.strip!, expected)
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_cdata
|
81
|
-
expected = "<?xml version=\"1.0\"?>\n<root><![CDATA[<?php echo $foo; ?>]]></root>"
|
82
|
-
|
83
|
-
writer = XML::Writer.string
|
84
|
-
document writer do
|
85
|
-
element writer, 'root' do
|
86
|
-
assert(writer.start_cdata)
|
87
|
-
assert(writer.write_string '<?php echo $foo; ?>')
|
88
|
-
assert(writer.end_cdata)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
assert_equal(writer.result.strip!, expected)
|
92
|
-
|
93
|
-
writer = XML::Writer.string
|
94
|
-
document writer do
|
95
|
-
element writer, 'root' do
|
96
|
-
assert(writer.write_cdata '<?php echo $foo; ?>')
|
97
|
-
end
|
98
|
-
end
|
99
|
-
assert_equal(writer.result.strip!, expected)
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_write_empty_elements
|
103
|
-
writer = XML::Writer.string
|
104
|
-
document writer do
|
105
|
-
assert(writer.write_element 'foo')
|
106
|
-
end
|
107
|
-
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<foo/>")
|
108
|
-
|
109
|
-
writer = XML::Writer.string
|
110
|
-
document writer do
|
111
|
-
assert(writer.write_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
112
|
-
end
|
113
|
-
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<" + XSL_PREFIX + ":stylesheet xmlns:xsl=\"" + XSL_URI + "\"/>")
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_valued_element
|
117
|
-
expected = "<?xml version=\"1.0\"?>\n<abc>123<def>456<ghi>789</ghi>cueillir des cerises</def>nous irons au bois</abc>"
|
118
|
-
|
119
|
-
writer = XML::Writer.string
|
120
|
-
document writer do
|
121
|
-
assert(writer.start_element 'abc')
|
122
|
-
assert(writer.write_string '123')
|
123
|
-
assert(writer.start_element 'def')
|
124
|
-
assert(writer.write_string '456')
|
125
|
-
assert(writer.start_element 'ghi')
|
126
|
-
assert(writer.write_string '789')
|
127
|
-
assert(writer.end_element)
|
128
|
-
assert(writer.write_string 'cueillir des cerises')
|
129
|
-
assert(writer.end_element)
|
130
|
-
assert(writer.write_string 'nous irons au bois')
|
131
|
-
assert(writer.end_element)
|
132
|
-
end
|
133
|
-
assert_equal(writer.result.strip!, expected)
|
134
|
-
|
135
|
-
writer = XML::Writer.string
|
136
|
-
document writer do
|
137
|
-
assert(writer.start_element 'abc')
|
138
|
-
assert(writer.write_string '123')
|
139
|
-
assert(writer.start_element 'def')
|
140
|
-
assert(writer.write_string '456')
|
141
|
-
assert(writer.write_element 'ghi', '789')
|
142
|
-
assert(writer.write_string 'cueillir des cerises')
|
143
|
-
assert(writer.end_element)
|
144
|
-
assert(writer.write_string 'nous irons au bois')
|
145
|
-
assert(writer.end_element)
|
146
|
-
end
|
147
|
-
assert_equal(writer.result.strip!, expected)
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_valued_element_ns
|
151
|
-
expected = "<?xml version=\"1.0\"?>\n" +
|
152
|
-
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
|
153
|
-
"<xsl:attribute-set>" +
|
154
|
-
"<xsl:attribute>20px</xsl:attribute>" +
|
155
|
-
"<xsl:attribute>solid</xsl:attribute>" +
|
156
|
-
"</xsl:attribute-set>" +
|
157
|
-
"</xsl:stylesheet>"
|
158
|
-
|
159
|
-
writer = XML::Writer.string
|
160
|
-
document writer do
|
161
|
-
assert(writer.start_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
162
|
-
assert(writer.start_element_ns XSL_PREFIX, 'attribute-set')
|
163
|
-
assert(writer.start_element_ns XSL_PREFIX, 'attribute')
|
164
|
-
assert(writer.write_string '20px')
|
165
|
-
assert(writer.end_element)
|
166
|
-
assert(writer.start_element_ns XSL_PREFIX, 'attribute')
|
167
|
-
assert(writer.write_string 'solid')
|
168
|
-
assert(writer.end_element)
|
169
|
-
assert(writer.end_element)
|
170
|
-
assert(writer.end_element)
|
171
|
-
end
|
172
|
-
assert_equal(writer.result.strip!, expected)
|
173
|
-
|
174
|
-
writer = XML::Writer.string
|
175
|
-
document writer do
|
176
|
-
assert(writer.start_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
177
|
-
assert(writer.start_element_ns XSL_PREFIX, 'attribute-set')
|
178
|
-
assert(writer.write_element_ns XSL_PREFIX, 'attribute', nil, '20px')
|
179
|
-
assert(writer.write_element_ns XSL_PREFIX, 'attribute', nil, 'solid')
|
180
|
-
assert(writer.end_element)
|
181
|
-
assert(writer.end_element)
|
182
|
-
end
|
183
|
-
assert_equal(writer.result.strip!, expected)
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_attribute
|
187
|
-
writer = XML::Writer.string
|
188
|
-
document writer do
|
189
|
-
element writer, 'root' do
|
190
|
-
element writer, 'child' do
|
191
|
-
assert(writer.start_attribute 'foo')
|
192
|
-
assert(writer.write_string 'bar')
|
193
|
-
assert(writer.end_attribute)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
end
|
197
|
-
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root><child foo=\"bar\"/></root>")
|
198
|
-
|
199
|
-
writer = XML::Writer.string
|
200
|
-
document writer do
|
201
|
-
element writer, 'root' do
|
202
|
-
element writer, 'child' do
|
203
|
-
assert(writer.write_attribute 'abc', 'def')
|
204
|
-
assert(writer.write_string 'ghi') # must be done after attributes
|
205
|
-
end
|
206
|
-
end
|
207
|
-
end
|
208
|
-
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root><child abc=\"def\">ghi</child></root>")
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_attribute_ns
|
212
|
-
expected = "<?xml version=\"1.0\"?>\n<root><link xlink:href=\"abc\" xhtml:class=\"def\"/></root>"
|
213
|
-
|
214
|
-
writer = XML::Writer.string
|
215
|
-
document writer do
|
216
|
-
element writer, 'root' do
|
217
|
-
element writer, 'link' do
|
218
|
-
assert(writer.write_attribute_ns 'xlink', 'href', nil, 'abc')
|
219
|
-
assert(writer.write_attribute_ns 'xhtml', 'class', nil, 'def')
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
assert_equal(writer.result.strip!, expected)
|
224
|
-
|
225
|
-
writer = XML::Writer.string
|
226
|
-
document writer do
|
227
|
-
element writer, 'root' do
|
228
|
-
element writer, 'link' do
|
229
|
-
assert(writer.start_attribute_ns 'xlink', 'href')
|
230
|
-
assert(writer.write_string 'abc')
|
231
|
-
assert(writer.end_attribute)
|
232
|
-
assert(writer.start_attribute_ns 'xhtml', 'class')
|
233
|
-
assert(writer.write_string 'def')
|
234
|
-
assert(writer.end_attribute)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
238
|
-
assert_equal(writer.result.strip!, expected)
|
239
|
-
end
|
240
|
-
|
241
|
-
def test_quote_char
|
242
|
-
if XML::Writer.method_defined? :set_quote_char
|
243
|
-
writer = XML::Writer.string
|
244
|
-
writer.set_quote_char "'"
|
245
|
-
document writer do
|
246
|
-
element writer, 'root' do
|
247
|
-
assert(writer.start_attribute 'abc')
|
248
|
-
assert(writer.write_string 'def')
|
249
|
-
assert(writer.end_attribute)
|
250
|
-
end
|
251
|
-
end
|
252
|
-
assert(writer.result.strip!.end_with? "<root abc='def'/>")
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
def test_indentation_on
|
257
|
-
if XML::Writer.method_defined? :set_indent
|
258
|
-
writer = XML::Writer.string
|
259
|
-
assert(writer.set_indent true)
|
260
|
-
document writer do
|
261
|
-
element writer, 'root' do
|
262
|
-
element writer, 'child' do
|
263
|
-
assert(writer.start_attribute 'abc')
|
264
|
-
assert(writer.write_string 'def')
|
265
|
-
assert(writer.end_attribute)
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|
269
|
-
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root>\n <child abc=\"def\"/>\n</root>")
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
def test_indentation_string
|
274
|
-
if XML::Writer.method_defined? :set_indent_string
|
275
|
-
writer = XML::Writer.string
|
276
|
-
assert(writer.set_indent true)
|
277
|
-
assert(writer.set_indent_string ' ' * 4)
|
278
|
-
document writer do
|
279
|
-
element writer, 'root' do
|
280
|
-
element writer, 'child' do
|
281
|
-
assert(writer.start_attribute 'abc')
|
282
|
-
assert(writer.write_string 'def')
|
283
|
-
assert(writer.end_attribute)
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root>\n <child abc=\"def\"/>\n</root>")
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
def test_dtd_declaration
|
292
|
-
writer = XML::Writer.string
|
293
|
-
dtd writer, 'html'
|
294
|
-
assert_equal(writer.result, '<!DOCTYPE html>')
|
295
|
-
|
296
|
-
writer = XML::Writer.string
|
297
|
-
dtd writer, 'html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
|
298
|
-
assert_equal(writer.result, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">')
|
299
|
-
end
|
300
|
-
|
301
|
-
def test_dtd_attlist
|
302
|
-
expected = '<!DOCTYPE http [<!ATTLIST method (get|post) "get">]>'
|
303
|
-
|
304
|
-
writer = XML::Writer.string
|
305
|
-
dtd writer, 'http' do
|
306
|
-
assert(writer.start_dtd_attlist 'method')
|
307
|
-
assert(writer.write_string '(get|post) "get"')
|
308
|
-
assert(writer.end_dtd_attlist)
|
309
|
-
end
|
310
|
-
assert_equal(writer.result, expected)
|
311
|
-
|
312
|
-
writer = XML::Writer.string
|
313
|
-
dtd writer, 'http' do
|
314
|
-
assert(writer.write_dtd_attlist 'method', '(get|post) "get"')
|
315
|
-
end
|
316
|
-
assert_equal(writer.result, expected)
|
317
|
-
end
|
318
|
-
|
319
|
-
def test_dtd_element
|
320
|
-
expected = '<!DOCTYPE html [<!ELEMENT dl (dt|dd)+>]>'
|
321
|
-
|
322
|
-
writer = XML::Writer.string
|
323
|
-
dtd writer, 'html' do
|
324
|
-
assert(writer.start_dtd_element 'dl')
|
325
|
-
assert(writer.write_string '(dt|dd)+')
|
326
|
-
assert(writer.end_dtd_element)
|
327
|
-
end
|
328
|
-
assert_equal(writer.result, expected)
|
329
|
-
|
330
|
-
writer = XML::Writer.string
|
331
|
-
dtd writer, 'html' do
|
332
|
-
assert(writer.write_dtd_element 'dl', '(dt|dd)+')
|
333
|
-
end
|
334
|
-
assert_equal(writer.result, expected)
|
335
|
-
end
|
336
|
-
|
337
|
-
def test_dtd_entity
|
338
|
-
# parameterized entity
|
339
|
-
expected = '<!DOCTYPE html [<!ENTITY % special.pre "br | span | bdo | map"><!ENTITY % special "%special.pre; | object | img">]>'
|
340
|
-
|
341
|
-
writer = XML::Writer.string
|
342
|
-
dtd writer, 'html' do
|
343
|
-
assert(writer.start_dtd_entity 'special.pre', true)
|
344
|
-
assert(writer.write_string 'br | span | bdo | map')
|
345
|
-
assert(writer.end_dtd_entity)
|
346
|
-
assert(writer.start_dtd_entity 'special', true)
|
347
|
-
assert(writer.write_string '%special.pre; | object | img')
|
348
|
-
assert(writer.end_dtd_entity)
|
349
|
-
end
|
350
|
-
assert_equal(writer.result, expected)
|
351
|
-
|
352
|
-
writer = XML::Writer.string
|
353
|
-
dtd writer, 'html' do
|
354
|
-
assert(writer.write_dtd_internal_entity 'special.pre', 'br | span | bdo | map', true)
|
355
|
-
assert(writer.write_dtd_internal_entity 'special', '%special.pre; | object | img', true)
|
356
|
-
end
|
357
|
-
assert_equal(writer.result, expected)
|
358
|
-
|
359
|
-
# non parameterized entity
|
360
|
-
expected = '<!DOCTYPE html [<!ENTITY Alpha "Α">]>'
|
361
|
-
|
362
|
-
writer = XML::Writer.string
|
363
|
-
dtd writer, 'html' do
|
364
|
-
assert(writer.start_dtd_entity 'Alpha')
|
365
|
-
assert(writer.write_string 'Α')
|
366
|
-
assert(writer.end_dtd_entity)
|
367
|
-
end
|
368
|
-
assert_equal(writer.result, expected)
|
369
|
-
|
370
|
-
writer = XML::Writer.string
|
371
|
-
dtd writer, 'html' do
|
372
|
-
assert(writer.start_dtd_entity 'Alpha', false)
|
373
|
-
assert(writer.write_string 'Α')
|
374
|
-
assert(writer.end_dtd_entity)
|
375
|
-
end
|
376
|
-
assert_equal(writer.result, expected)
|
377
|
-
|
378
|
-
writer = XML::Writer.string
|
379
|
-
dtd writer, 'html' do
|
380
|
-
assert(writer.write_dtd_internal_entity 'Alpha', 'Α', false)
|
381
|
-
end
|
382
|
-
assert_equal(writer.result, expected)
|
383
|
-
end
|
384
|
-
|
385
|
-
def test_dtd_notation
|
386
|
-
writer = XML::Writer.string
|
387
|
-
dtd writer, 'pictures' do
|
388
|
-
assert(writer.write_dtd_notation 'GIF89a', '-//Compuserve//NOTATION Graphics Interchange Format 89a//EN', nil)
|
389
|
-
assert(writer.write_dtd_external_entity 'pictures', nil, 'images/plage.gif', 'GIF89a', false)
|
390
|
-
end
|
391
|
-
assert_equal(writer.result, '<!DOCTYPE pictures [<!NOTATION GIF89a PUBLIC "-//Compuserve//NOTATION Graphics Interchange Format 89a//EN"><!ENTITY pictures SYSTEM "images/plage.gif" NDATA GIF89a>]>')
|
392
|
-
end
|
393
|
-
|
394
|
-
def test_encoding
|
395
|
-
if defined?(Encoding)
|
396
|
-
iso = 'éloïse'.encode 'ISO-8859-1'
|
397
|
-
|
398
|
-
writer = XML::Writer.string
|
399
|
-
document writer do
|
400
|
-
assert(writer.write_element iso)
|
401
|
-
end
|
402
|
-
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<éloïse/>")
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
def test_flush
|
407
|
-
writer = XML::Writer.string
|
408
|
-
assert(writer.start_document)
|
409
|
-
assert_equal(writer.flush.strip!, '<?xml version="1.0"?>')
|
410
|
-
assert(writer.start_element 'foo')
|
411
|
-
assert(writer.end_element)
|
412
|
-
assert(writer.end_document)
|
413
|
-
writer.flush false
|
414
|
-
assert_equal(writer.result.strip, '<foo/>')
|
415
|
-
end
|
416
|
-
|
417
|
-
def test_nil_pe_issue
|
418
|
-
expected = '<!DOCTYPE html [<!ENTITY special.pre "br | span | bdo | map"><!ENTITY special "%special.pre; | object | img">]>'
|
419
|
-
|
420
|
-
writer = XML::Writer.string
|
421
|
-
dtd writer, 'html' do
|
422
|
-
assert(writer.write_dtd_internal_entity 'special.pre', 'br | span | bdo | map', nil)
|
423
|
-
assert(writer.write_dtd_internal_entity 'special', '%special.pre; | object | img', nil)
|
424
|
-
end
|
425
|
-
assert_equal(writer.result, expected)
|
426
|
-
end
|
427
|
-
|
428
|
-
private
|
429
|
-
|
430
|
-
def document(writer, options = {})
|
431
|
-
assert(writer.start_document options)
|
432
|
-
yield if block_given?
|
433
|
-
assert(writer.end_document)
|
434
|
-
end
|
435
|
-
|
436
|
-
def dtd(writer, name, pubid = nil, sysid = nil)
|
437
|
-
assert(writer.start_dtd name, pubid, sysid)
|
438
|
-
yield if block_given?
|
439
|
-
assert(writer.end_dtd)
|
440
|
-
end
|
441
|
-
|
442
|
-
def element(writer, localname)
|
443
|
-
assert(writer.start_element localname)
|
444
|
-
yield if block_given?
|
445
|
-
assert(writer.end_element)
|
446
|
-
end
|
447
|
-
end
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require './test_helper'
|
4
|
+
require 'stringio'
|
5
|
+
|
6
|
+
class TestWriter < Minitest::Test
|
7
|
+
XSL_PREFIX = 'xsl'
|
8
|
+
XSL_URI = 'http://www.w3.org/1999/XSL/Transform'
|
9
|
+
|
10
|
+
def test_generic_failure
|
11
|
+
writer = XML::Writer.string
|
12
|
+
writer.start_document
|
13
|
+
assert(!writer.end_element)
|
14
|
+
writer.end_document
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_empty_doc
|
18
|
+
writer = XML::Writer.string
|
19
|
+
document writer
|
20
|
+
assert_equal(writer.result.strip!, '<?xml version="1.0"?>')
|
21
|
+
|
22
|
+
writer = XML::Writer.string
|
23
|
+
document writer, { :encoding => XML::Encoding::ISO_8859_1 }
|
24
|
+
assert_equal(writer.result.strip!, '<?xml version="1.0" encoding="ISO-8859-1"?>')
|
25
|
+
|
26
|
+
writer = XML::Writer.string
|
27
|
+
document writer, { :standalone => 1 }
|
28
|
+
assert_equal(writer.result.strip!, '<?xml version="1.0" standalone="yes"?>')
|
29
|
+
|
30
|
+
writer = XML::Writer.string
|
31
|
+
document writer, { :standalone => 1, :encoding => XML::Encoding::ISO_8859_1, :foo => :bar }
|
32
|
+
assert_equal(writer.result.strip!, '<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_single_root
|
36
|
+
writer = XML::Writer.string
|
37
|
+
document writer do
|
38
|
+
element writer, 'root'
|
39
|
+
end
|
40
|
+
|
41
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root/>")
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_pi
|
45
|
+
expected = "<?xml version=\"1.0\"?>\n<?php echo \"foo\";?>"
|
46
|
+
|
47
|
+
writer = XML::Writer.string
|
48
|
+
document writer do
|
49
|
+
assert(writer.start_pi('php'))
|
50
|
+
assert(writer.write_string('echo "foo";'))
|
51
|
+
assert(writer.end_pi)
|
52
|
+
end
|
53
|
+
assert_equal(writer.result.strip!, expected)
|
54
|
+
|
55
|
+
writer = XML::Writer.string
|
56
|
+
document writer do
|
57
|
+
assert(writer.write_pi('php', 'echo "foo";'))
|
58
|
+
end
|
59
|
+
assert_equal(writer.result.strip!, expected)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_comment
|
63
|
+
expected = "<?xml version=\"1.0\"?>\n<!--foo-->"
|
64
|
+
|
65
|
+
writer = XML::Writer.string
|
66
|
+
document writer do
|
67
|
+
assert(writer.start_comment)
|
68
|
+
assert(writer.write_string 'foo')
|
69
|
+
assert(writer.end_comment)
|
70
|
+
end
|
71
|
+
assert_equal(writer.result.strip!, expected)
|
72
|
+
|
73
|
+
writer = XML::Writer.string
|
74
|
+
document writer do
|
75
|
+
assert(writer.write_comment 'foo')
|
76
|
+
end
|
77
|
+
assert_equal(writer.result.strip!, expected)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_cdata
|
81
|
+
expected = "<?xml version=\"1.0\"?>\n<root><![CDATA[<?php echo $foo; ?>]]></root>"
|
82
|
+
|
83
|
+
writer = XML::Writer.string
|
84
|
+
document writer do
|
85
|
+
element writer, 'root' do
|
86
|
+
assert(writer.start_cdata)
|
87
|
+
assert(writer.write_string '<?php echo $foo; ?>')
|
88
|
+
assert(writer.end_cdata)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
assert_equal(writer.result.strip!, expected)
|
92
|
+
|
93
|
+
writer = XML::Writer.string
|
94
|
+
document writer do
|
95
|
+
element writer, 'root' do
|
96
|
+
assert(writer.write_cdata '<?php echo $foo; ?>')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
assert_equal(writer.result.strip!, expected)
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_write_empty_elements
|
103
|
+
writer = XML::Writer.string
|
104
|
+
document writer do
|
105
|
+
assert(writer.write_element 'foo')
|
106
|
+
end
|
107
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<foo/>")
|
108
|
+
|
109
|
+
writer = XML::Writer.string
|
110
|
+
document writer do
|
111
|
+
assert(writer.write_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
112
|
+
end
|
113
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<" + XSL_PREFIX + ":stylesheet xmlns:xsl=\"" + XSL_URI + "\"/>")
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_valued_element
|
117
|
+
expected = "<?xml version=\"1.0\"?>\n<abc>123<def>456<ghi>789</ghi>cueillir des cerises</def>nous irons au bois</abc>"
|
118
|
+
|
119
|
+
writer = XML::Writer.string
|
120
|
+
document writer do
|
121
|
+
assert(writer.start_element 'abc')
|
122
|
+
assert(writer.write_string '123')
|
123
|
+
assert(writer.start_element 'def')
|
124
|
+
assert(writer.write_string '456')
|
125
|
+
assert(writer.start_element 'ghi')
|
126
|
+
assert(writer.write_string '789')
|
127
|
+
assert(writer.end_element)
|
128
|
+
assert(writer.write_string 'cueillir des cerises')
|
129
|
+
assert(writer.end_element)
|
130
|
+
assert(writer.write_string 'nous irons au bois')
|
131
|
+
assert(writer.end_element)
|
132
|
+
end
|
133
|
+
assert_equal(writer.result.strip!, expected)
|
134
|
+
|
135
|
+
writer = XML::Writer.string
|
136
|
+
document writer do
|
137
|
+
assert(writer.start_element 'abc')
|
138
|
+
assert(writer.write_string '123')
|
139
|
+
assert(writer.start_element 'def')
|
140
|
+
assert(writer.write_string '456')
|
141
|
+
assert(writer.write_element 'ghi', '789')
|
142
|
+
assert(writer.write_string 'cueillir des cerises')
|
143
|
+
assert(writer.end_element)
|
144
|
+
assert(writer.write_string 'nous irons au bois')
|
145
|
+
assert(writer.end_element)
|
146
|
+
end
|
147
|
+
assert_equal(writer.result.strip!, expected)
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_valued_element_ns
|
151
|
+
expected = "<?xml version=\"1.0\"?>\n" +
|
152
|
+
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
|
153
|
+
"<xsl:attribute-set>" +
|
154
|
+
"<xsl:attribute>20px</xsl:attribute>" +
|
155
|
+
"<xsl:attribute>solid</xsl:attribute>" +
|
156
|
+
"</xsl:attribute-set>" +
|
157
|
+
"</xsl:stylesheet>"
|
158
|
+
|
159
|
+
writer = XML::Writer.string
|
160
|
+
document writer do
|
161
|
+
assert(writer.start_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
162
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute-set')
|
163
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute')
|
164
|
+
assert(writer.write_string '20px')
|
165
|
+
assert(writer.end_element)
|
166
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute')
|
167
|
+
assert(writer.write_string 'solid')
|
168
|
+
assert(writer.end_element)
|
169
|
+
assert(writer.end_element)
|
170
|
+
assert(writer.end_element)
|
171
|
+
end
|
172
|
+
assert_equal(writer.result.strip!, expected)
|
173
|
+
|
174
|
+
writer = XML::Writer.string
|
175
|
+
document writer do
|
176
|
+
assert(writer.start_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
177
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute-set')
|
178
|
+
assert(writer.write_element_ns XSL_PREFIX, 'attribute', nil, '20px')
|
179
|
+
assert(writer.write_element_ns XSL_PREFIX, 'attribute', nil, 'solid')
|
180
|
+
assert(writer.end_element)
|
181
|
+
assert(writer.end_element)
|
182
|
+
end
|
183
|
+
assert_equal(writer.result.strip!, expected)
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_attribute
|
187
|
+
writer = XML::Writer.string
|
188
|
+
document writer do
|
189
|
+
element writer, 'root' do
|
190
|
+
element writer, 'child' do
|
191
|
+
assert(writer.start_attribute 'foo')
|
192
|
+
assert(writer.write_string 'bar')
|
193
|
+
assert(writer.end_attribute)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
197
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root><child foo=\"bar\"/></root>")
|
198
|
+
|
199
|
+
writer = XML::Writer.string
|
200
|
+
document writer do
|
201
|
+
element writer, 'root' do
|
202
|
+
element writer, 'child' do
|
203
|
+
assert(writer.write_attribute 'abc', 'def')
|
204
|
+
assert(writer.write_string 'ghi') # must be done after attributes
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root><child abc=\"def\">ghi</child></root>")
|
209
|
+
end
|
210
|
+
|
211
|
+
def test_attribute_ns
|
212
|
+
expected = "<?xml version=\"1.0\"?>\n<root><link xlink:href=\"abc\" xhtml:class=\"def\"/></root>"
|
213
|
+
|
214
|
+
writer = XML::Writer.string
|
215
|
+
document writer do
|
216
|
+
element writer, 'root' do
|
217
|
+
element writer, 'link' do
|
218
|
+
assert(writer.write_attribute_ns 'xlink', 'href', nil, 'abc')
|
219
|
+
assert(writer.write_attribute_ns 'xhtml', 'class', nil, 'def')
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
assert_equal(writer.result.strip!, expected)
|
224
|
+
|
225
|
+
writer = XML::Writer.string
|
226
|
+
document writer do
|
227
|
+
element writer, 'root' do
|
228
|
+
element writer, 'link' do
|
229
|
+
assert(writer.start_attribute_ns 'xlink', 'href')
|
230
|
+
assert(writer.write_string 'abc')
|
231
|
+
assert(writer.end_attribute)
|
232
|
+
assert(writer.start_attribute_ns 'xhtml', 'class')
|
233
|
+
assert(writer.write_string 'def')
|
234
|
+
assert(writer.end_attribute)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
assert_equal(writer.result.strip!, expected)
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_quote_char
|
242
|
+
if XML::Writer.method_defined? :set_quote_char
|
243
|
+
writer = XML::Writer.string
|
244
|
+
writer.set_quote_char "'"
|
245
|
+
document writer do
|
246
|
+
element writer, 'root' do
|
247
|
+
assert(writer.start_attribute 'abc')
|
248
|
+
assert(writer.write_string 'def')
|
249
|
+
assert(writer.end_attribute)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
assert(writer.result.strip!.end_with? "<root abc='def'/>")
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def test_indentation_on
|
257
|
+
if XML::Writer.method_defined? :set_indent
|
258
|
+
writer = XML::Writer.string
|
259
|
+
assert(writer.set_indent true)
|
260
|
+
document writer do
|
261
|
+
element writer, 'root' do
|
262
|
+
element writer, 'child' do
|
263
|
+
assert(writer.start_attribute 'abc')
|
264
|
+
assert(writer.write_string 'def')
|
265
|
+
assert(writer.end_attribute)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root>\n <child abc=\"def\"/>\n</root>")
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
def test_indentation_string
|
274
|
+
if XML::Writer.method_defined? :set_indent_string
|
275
|
+
writer = XML::Writer.string
|
276
|
+
assert(writer.set_indent true)
|
277
|
+
assert(writer.set_indent_string ' ' * 4)
|
278
|
+
document writer do
|
279
|
+
element writer, 'root' do
|
280
|
+
element writer, 'child' do
|
281
|
+
assert(writer.start_attribute 'abc')
|
282
|
+
assert(writer.write_string 'def')
|
283
|
+
assert(writer.end_attribute)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root>\n <child abc=\"def\"/>\n</root>")
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_dtd_declaration
|
292
|
+
writer = XML::Writer.string
|
293
|
+
dtd writer, 'html'
|
294
|
+
assert_equal(writer.result, '<!DOCTYPE html>')
|
295
|
+
|
296
|
+
writer = XML::Writer.string
|
297
|
+
dtd writer, 'html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
|
298
|
+
assert_equal(writer.result, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">')
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_dtd_attlist
|
302
|
+
expected = '<!DOCTYPE http [<!ATTLIST method (get|post) "get">]>'
|
303
|
+
|
304
|
+
writer = XML::Writer.string
|
305
|
+
dtd writer, 'http' do
|
306
|
+
assert(writer.start_dtd_attlist 'method')
|
307
|
+
assert(writer.write_string '(get|post) "get"')
|
308
|
+
assert(writer.end_dtd_attlist)
|
309
|
+
end
|
310
|
+
assert_equal(writer.result, expected)
|
311
|
+
|
312
|
+
writer = XML::Writer.string
|
313
|
+
dtd writer, 'http' do
|
314
|
+
assert(writer.write_dtd_attlist 'method', '(get|post) "get"')
|
315
|
+
end
|
316
|
+
assert_equal(writer.result, expected)
|
317
|
+
end
|
318
|
+
|
319
|
+
def test_dtd_element
|
320
|
+
expected = '<!DOCTYPE html [<!ELEMENT dl (dt|dd)+>]>'
|
321
|
+
|
322
|
+
writer = XML::Writer.string
|
323
|
+
dtd writer, 'html' do
|
324
|
+
assert(writer.start_dtd_element 'dl')
|
325
|
+
assert(writer.write_string '(dt|dd)+')
|
326
|
+
assert(writer.end_dtd_element)
|
327
|
+
end
|
328
|
+
assert_equal(writer.result, expected)
|
329
|
+
|
330
|
+
writer = XML::Writer.string
|
331
|
+
dtd writer, 'html' do
|
332
|
+
assert(writer.write_dtd_element 'dl', '(dt|dd)+')
|
333
|
+
end
|
334
|
+
assert_equal(writer.result, expected)
|
335
|
+
end
|
336
|
+
|
337
|
+
def test_dtd_entity
|
338
|
+
# parameterized entity
|
339
|
+
expected = '<!DOCTYPE html [<!ENTITY % special.pre "br | span | bdo | map"><!ENTITY % special "%special.pre; | object | img">]>'
|
340
|
+
|
341
|
+
writer = XML::Writer.string
|
342
|
+
dtd writer, 'html' do
|
343
|
+
assert(writer.start_dtd_entity 'special.pre', true)
|
344
|
+
assert(writer.write_string 'br | span | bdo | map')
|
345
|
+
assert(writer.end_dtd_entity)
|
346
|
+
assert(writer.start_dtd_entity 'special', true)
|
347
|
+
assert(writer.write_string '%special.pre; | object | img')
|
348
|
+
assert(writer.end_dtd_entity)
|
349
|
+
end
|
350
|
+
assert_equal(writer.result, expected)
|
351
|
+
|
352
|
+
writer = XML::Writer.string
|
353
|
+
dtd writer, 'html' do
|
354
|
+
assert(writer.write_dtd_internal_entity 'special.pre', 'br | span | bdo | map', true)
|
355
|
+
assert(writer.write_dtd_internal_entity 'special', '%special.pre; | object | img', true)
|
356
|
+
end
|
357
|
+
assert_equal(writer.result, expected)
|
358
|
+
|
359
|
+
# non parameterized entity
|
360
|
+
expected = '<!DOCTYPE html [<!ENTITY Alpha "Α">]>'
|
361
|
+
|
362
|
+
writer = XML::Writer.string
|
363
|
+
dtd writer, 'html' do
|
364
|
+
assert(writer.start_dtd_entity 'Alpha')
|
365
|
+
assert(writer.write_string 'Α')
|
366
|
+
assert(writer.end_dtd_entity)
|
367
|
+
end
|
368
|
+
assert_equal(writer.result, expected)
|
369
|
+
|
370
|
+
writer = XML::Writer.string
|
371
|
+
dtd writer, 'html' do
|
372
|
+
assert(writer.start_dtd_entity 'Alpha', false)
|
373
|
+
assert(writer.write_string 'Α')
|
374
|
+
assert(writer.end_dtd_entity)
|
375
|
+
end
|
376
|
+
assert_equal(writer.result, expected)
|
377
|
+
|
378
|
+
writer = XML::Writer.string
|
379
|
+
dtd writer, 'html' do
|
380
|
+
assert(writer.write_dtd_internal_entity 'Alpha', 'Α', false)
|
381
|
+
end
|
382
|
+
assert_equal(writer.result, expected)
|
383
|
+
end
|
384
|
+
|
385
|
+
def test_dtd_notation
|
386
|
+
writer = XML::Writer.string
|
387
|
+
dtd writer, 'pictures' do
|
388
|
+
assert(writer.write_dtd_notation 'GIF89a', '-//Compuserve//NOTATION Graphics Interchange Format 89a//EN', nil)
|
389
|
+
assert(writer.write_dtd_external_entity 'pictures', nil, 'images/plage.gif', 'GIF89a', false)
|
390
|
+
end
|
391
|
+
assert_equal(writer.result, '<!DOCTYPE pictures [<!NOTATION GIF89a PUBLIC "-//Compuserve//NOTATION Graphics Interchange Format 89a//EN"><!ENTITY pictures SYSTEM "images/plage.gif" NDATA GIF89a>]>')
|
392
|
+
end
|
393
|
+
|
394
|
+
def test_encoding
|
395
|
+
if defined?(Encoding)
|
396
|
+
iso = 'éloïse'.encode 'ISO-8859-1'
|
397
|
+
|
398
|
+
writer = XML::Writer.string
|
399
|
+
document writer do
|
400
|
+
assert(writer.write_element iso)
|
401
|
+
end
|
402
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<éloïse/>")
|
403
|
+
end
|
404
|
+
end
|
405
|
+
|
406
|
+
def test_flush
|
407
|
+
writer = XML::Writer.string
|
408
|
+
assert(writer.start_document)
|
409
|
+
assert_equal(writer.flush.strip!, '<?xml version="1.0"?>')
|
410
|
+
assert(writer.start_element 'foo')
|
411
|
+
assert(writer.end_element)
|
412
|
+
assert(writer.end_document)
|
413
|
+
writer.flush false
|
414
|
+
assert_equal(writer.result.strip, '<foo/>')
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_nil_pe_issue
|
418
|
+
expected = '<!DOCTYPE html [<!ENTITY special.pre "br | span | bdo | map"><!ENTITY special "%special.pre; | object | img">]>'
|
419
|
+
|
420
|
+
writer = XML::Writer.string
|
421
|
+
dtd writer, 'html' do
|
422
|
+
assert(writer.write_dtd_internal_entity 'special.pre', 'br | span | bdo | map', nil)
|
423
|
+
assert(writer.write_dtd_internal_entity 'special', '%special.pre; | object | img', nil)
|
424
|
+
end
|
425
|
+
assert_equal(writer.result, expected)
|
426
|
+
end
|
427
|
+
|
428
|
+
private
|
429
|
+
|
430
|
+
def document(writer, options = {})
|
431
|
+
assert(writer.start_document options)
|
432
|
+
yield if block_given?
|
433
|
+
assert(writer.end_document)
|
434
|
+
end
|
435
|
+
|
436
|
+
def dtd(writer, name, pubid = nil, sysid = nil)
|
437
|
+
assert(writer.start_dtd name, pubid, sysid)
|
438
|
+
yield if block_given?
|
439
|
+
assert(writer.end_dtd)
|
440
|
+
end
|
441
|
+
|
442
|
+
def element(writer, localname)
|
443
|
+
assert(writer.start_element localname)
|
444
|
+
yield if block_given?
|
445
|
+
assert(writer.end_element)
|
446
|
+
end
|
447
|
+
end
|