libxml-ruby 3.2.2-x64-mingw-ucrt
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/HISTORY +848 -0
- data/LICENSE +21 -0
- data/MANIFEST +166 -0
- data/README.rdoc +217 -0
- data/Rakefile +99 -0
- data/ext/libxml/extconf.rb +61 -0
- data/ext/libxml/libxml.c +80 -0
- data/ext/libxml/libxml_ruby.def +35 -0
- data/ext/libxml/ruby_libxml.h +67 -0
- data/ext/libxml/ruby_xml.c +933 -0
- data/ext/libxml/ruby_xml.h +10 -0
- data/ext/libxml/ruby_xml_attr.c +333 -0
- data/ext/libxml/ruby_xml_attr.h +12 -0
- data/ext/libxml/ruby_xml_attr_decl.c +153 -0
- data/ext/libxml/ruby_xml_attr_decl.h +11 -0
- data/ext/libxml/ruby_xml_attributes.c +275 -0
- data/ext/libxml/ruby_xml_attributes.h +15 -0
- data/ext/libxml/ruby_xml_cbg.c +85 -0
- data/ext/libxml/ruby_xml_document.c +1123 -0
- data/ext/libxml/ruby_xml_document.h +11 -0
- data/ext/libxml/ruby_xml_dtd.c +248 -0
- data/ext/libxml/ruby_xml_dtd.h +9 -0
- data/ext/libxml/ruby_xml_encoding.c +250 -0
- data/ext/libxml/ruby_xml_encoding.h +16 -0
- data/ext/libxml/ruby_xml_error.c +996 -0
- data/ext/libxml/ruby_xml_error.h +12 -0
- data/ext/libxml/ruby_xml_html_parser.c +89 -0
- data/ext/libxml/ruby_xml_html_parser.h +10 -0
- data/ext/libxml/ruby_xml_html_parser_context.c +337 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +10 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +46 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +10 -0
- data/ext/libxml/ruby_xml_input_cbg.c +191 -0
- data/ext/libxml/ruby_xml_input_cbg.h +20 -0
- data/ext/libxml/ruby_xml_io.c +47 -0
- data/ext/libxml/ruby_xml_io.h +10 -0
- data/ext/libxml/ruby_xml_namespace.c +153 -0
- data/ext/libxml/ruby_xml_namespace.h +10 -0
- data/ext/libxml/ruby_xml_namespaces.c +293 -0
- data/ext/libxml/ruby_xml_namespaces.h +9 -0
- data/ext/libxml/ruby_xml_node.c +1402 -0
- data/ext/libxml/ruby_xml_node.h +13 -0
- data/ext/libxml/ruby_xml_parser.c +91 -0
- data/ext/libxml/ruby_xml_parser.h +12 -0
- data/ext/libxml/ruby_xml_parser_context.c +999 -0
- data/ext/libxml/ruby_xml_parser_context.h +10 -0
- data/ext/libxml/ruby_xml_parser_options.c +66 -0
- data/ext/libxml/ruby_xml_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_reader.c +1239 -0
- data/ext/libxml/ruby_xml_reader.h +17 -0
- data/ext/libxml/ruby_xml_relaxng.c +110 -0
- data/ext/libxml/ruby_xml_relaxng.h +10 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -0
- data/ext/libxml/ruby_xml_sax2_handler.h +10 -0
- data/ext/libxml/ruby_xml_sax_parser.c +116 -0
- data/ext/libxml/ruby_xml_sax_parser.h +10 -0
- data/ext/libxml/ruby_xml_schema.c +278 -0
- data/ext/libxml/ruby_xml_schema.h +809 -0
- data/ext/libxml/ruby_xml_schema_attribute.c +109 -0
- data/ext/libxml/ruby_xml_schema_attribute.h +15 -0
- data/ext/libxml/ruby_xml_schema_element.c +95 -0
- data/ext/libxml/ruby_xml_schema_element.h +14 -0
- data/ext/libxml/ruby_xml_schema_facet.c +52 -0
- data/ext/libxml/ruby_xml_schema_facet.h +13 -0
- data/ext/libxml/ruby_xml_schema_type.c +232 -0
- data/ext/libxml/ruby_xml_schema_type.h +9 -0
- data/ext/libxml/ruby_xml_version.h +9 -0
- data/ext/libxml/ruby_xml_writer.c +1133 -0
- data/ext/libxml/ruby_xml_writer.h +10 -0
- data/ext/libxml/ruby_xml_xinclude.c +16 -0
- data/ext/libxml/ruby_xml_xinclude.h +11 -0
- data/ext/libxml/ruby_xml_xpath.c +194 -0
- data/ext/libxml/ruby_xml_xpath.h +13 -0
- data/ext/libxml/ruby_xml_xpath_context.c +360 -0
- data/ext/libxml/ruby_xml_xpath_context.h +9 -0
- data/ext/libxml/ruby_xml_xpath_expression.c +81 -0
- data/ext/libxml/ruby_xml_xpath_expression.h +10 -0
- data/ext/libxml/ruby_xml_xpath_object.c +338 -0
- data/ext/libxml/ruby_xml_xpath_object.h +17 -0
- data/ext/libxml/ruby_xml_xpointer.c +99 -0
- data/ext/libxml/ruby_xml_xpointer.h +11 -0
- data/ext/vc/libxml_ruby.sln +28 -0
- data/lib/3.1/libxml_ruby.so +0 -0
- data/lib/libxml/attr.rb +123 -0
- data/lib/libxml/attr_decl.rb +80 -0
- data/lib/libxml/attributes.rb +14 -0
- data/lib/libxml/document.rb +194 -0
- data/lib/libxml/error.rb +95 -0
- data/lib/libxml/hpricot.rb +78 -0
- data/lib/libxml/html_parser.rb +96 -0
- data/lib/libxml/namespace.rb +62 -0
- data/lib/libxml/namespaces.rb +38 -0
- data/lib/libxml/node.rb +323 -0
- data/lib/libxml/parser.rb +101 -0
- data/lib/libxml/sax_callbacks.rb +180 -0
- data/lib/libxml/sax_parser.rb +41 -0
- data/lib/libxml/schema/attribute.rb +19 -0
- data/lib/libxml/schema/element.rb +19 -0
- data/lib/libxml/schema/type.rb +21 -0
- data/lib/libxml/schema.rb +48 -0
- data/lib/libxml/tree.rb +29 -0
- data/lib/libxml-ruby.rb +30 -0
- data/lib/libxml.rb +5 -0
- data/lib/xml/libxml.rb +10 -0
- data/lib/xml.rb +14 -0
- data/libxml-ruby.gemspec +48 -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/setup.rb +1584 -0
- data/test/c14n/given/doc.dtd +1 -0
- data/test/c14n/given/example-1.xml +14 -0
- data/test/c14n/given/example-2.xml +11 -0
- data/test/c14n/given/example-3.xml +18 -0
- data/test/c14n/given/example-4.xml +9 -0
- data/test/c14n/given/example-5.xml +12 -0
- data/test/c14n/given/example-6.xml +2 -0
- data/test/c14n/given/example-7.xml +11 -0
- data/test/c14n/given/example-8.xml +11 -0
- data/test/c14n/given/example-8.xpath +10 -0
- data/test/c14n/given/world.txt +1 -0
- data/test/c14n/result/1-1-without-comments/example-1 +4 -0
- data/test/c14n/result/1-1-without-comments/example-2 +11 -0
- data/test/c14n/result/1-1-without-comments/example-3 +14 -0
- data/test/c14n/result/1-1-without-comments/example-4 +9 -0
- data/test/c14n/result/1-1-without-comments/example-5 +3 -0
- data/test/c14n/result/1-1-without-comments/example-6 +1 -0
- data/test/c14n/result/1-1-without-comments/example-7 +1 -0
- data/test/c14n/result/1-1-without-comments/example-8 +1 -0
- data/test/c14n/result/with-comments/example-1 +6 -0
- data/test/c14n/result/with-comments/example-2 +11 -0
- data/test/c14n/result/with-comments/example-3 +14 -0
- data/test/c14n/result/with-comments/example-4 +9 -0
- data/test/c14n/result/with-comments/example-5 +4 -0
- data/test/c14n/result/with-comments/example-6 +1 -0
- data/test/c14n/result/with-comments/example-7 +1 -0
- data/test/c14n/result/without-comments/example-1 +4 -0
- data/test/c14n/result/without-comments/example-2 +11 -0
- data/test/c14n/result/without-comments/example-3 +14 -0
- data/test/c14n/result/without-comments/example-4 +9 -0
- data/test/c14n/result/without-comments/example-5 +3 -0
- data/test/c14n/result/without-comments/example-6 +1 -0
- data/test/c14n/result/without-comments/example-7 +1 -0
- data/test/model/atom.xml +13 -0
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/model/bands.xml +5 -0
- data/test/model/books.xml +154 -0
- data/test/model/cwm_1_0.xml +11336 -0
- data/test/model/merge_bug_data.xml +58 -0
- data/test/model/ruby-lang.html +238 -0
- data/test/model/rubynet.xml +79 -0
- data/test/model/rubynet_project +1 -0
- data/test/model/shiporder.rnc +28 -0
- data/test/model/shiporder.rng +86 -0
- data/test/model/shiporder.xml +23 -0
- data/test/model/shiporder.xsd +40 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/test_attr.rb +181 -0
- data/test/test_attr_decl.rb +132 -0
- data/test/test_attributes.rb +136 -0
- data/test/test_canonicalize.rb +120 -0
- data/test/test_deprecated_require.rb +12 -0
- data/test/test_document.rb +132 -0
- data/test/test_document_write.rb +146 -0
- data/test/test_dtd.rb +129 -0
- data/test/test_encoding.rb +129 -0
- data/test/test_encoding_sax.rb +115 -0
- data/test/test_error.rb +178 -0
- data/test/test_helper.rb +9 -0
- data/test/test_html_parser.rb +162 -0
- data/test/test_html_parser_context.rb +23 -0
- data/test/test_namespace.rb +60 -0
- data/test/test_namespaces.rb +200 -0
- data/test/test_node.rb +237 -0
- data/test/test_node_cdata.rb +50 -0
- data/test/test_node_comment.rb +32 -0
- data/test/test_node_copy.rb +40 -0
- data/test/test_node_edit.rb +158 -0
- data/test/test_node_pi.rb +37 -0
- data/test/test_node_text.rb +69 -0
- data/test/test_node_write.rb +97 -0
- data/test/test_node_xlink.rb +28 -0
- data/test/test_parser.rb +324 -0
- data/test/test_parser_context.rb +198 -0
- data/test/test_properties.rb +38 -0
- data/test/test_reader.rb +364 -0
- data/test/test_relaxng.rb +53 -0
- data/test/test_sax_parser.rb +326 -0
- data/test/test_schema.rb +168 -0
- data/test/test_suite.rb +48 -0
- data/test/test_traversal.rb +152 -0
- data/test/test_writer.rb +468 -0
- data/test/test_xinclude.rb +20 -0
- data/test/test_xml.rb +263 -0
- data/test/test_xpath.rb +244 -0
- data/test/test_xpath_context.rb +88 -0
- data/test/test_xpath_expression.rb +37 -0
- data/test/test_xpointer.rb +72 -0
- metadata +325 -0
data/test/test_writer.rb
ADDED
@@ -0,0 +1,468 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative './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 = LibXML::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 = LibXML::XML::Writer.string
|
19
|
+
document(writer)
|
20
|
+
assert_equal(writer.result.strip!, '<?xml version="1.0"?>')
|
21
|
+
|
22
|
+
writer = LibXML::XML::Writer.string
|
23
|
+
document(writer, :encoding => LibXML::XML::Encoding::ISO_8859_1)
|
24
|
+
assert_equal(writer.result.strip!, '<?xml version="1.0" encoding="ISO-8859-1"?>')
|
25
|
+
|
26
|
+
writer = LibXML::XML::Writer.string
|
27
|
+
document(writer, :standalone => 1)
|
28
|
+
assert_equal(writer.result.strip!, '<?xml version="1.0" standalone="yes"?>')
|
29
|
+
|
30
|
+
writer = LibXML::XML::Writer.string
|
31
|
+
document(writer, :standalone => 1, :encoding => LibXML::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_file_encoding
|
36
|
+
value = "François".encode(Encoding::UTF_8)
|
37
|
+
|
38
|
+
File.open('test.xml', 'wb', encoding: 'UTF-8') do |file|
|
39
|
+
writer = LibXML::XML::Writer::io(file)
|
40
|
+
document(writer, encoding: LibXML::XML::Encoding::UTF_8) do
|
41
|
+
writer.write_element('Name', value)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_io_encoding
|
47
|
+
value = "François".encode(Encoding::UTF_8)
|
48
|
+
expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Name>François</Name>".encode(Encoding::UTF_8)
|
49
|
+
|
50
|
+
io = StringIO.new
|
51
|
+
writer = LibXML::XML::Writer::io(io)
|
52
|
+
document(writer, encoding: LibXML::XML::Encoding::UTF_8) do
|
53
|
+
writer.write_element('Name', value)
|
54
|
+
end
|
55
|
+
assert_equal(expected, io.string.strip)
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_single_root
|
59
|
+
writer = LibXML::XML::Writer.string
|
60
|
+
document(writer) do
|
61
|
+
element writer, 'root'
|
62
|
+
end
|
63
|
+
|
64
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root/>")
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_pi
|
68
|
+
expected = "<?xml version=\"1.0\"?>\n<?php echo \"foo\";?>"
|
69
|
+
|
70
|
+
writer = LibXML::XML::Writer.string
|
71
|
+
document(writer) do
|
72
|
+
assert(writer.start_pi('php'))
|
73
|
+
assert(writer.write_string('echo "foo";'))
|
74
|
+
assert(writer.end_pi)
|
75
|
+
end
|
76
|
+
assert_equal(writer.result.strip!, expected)
|
77
|
+
|
78
|
+
writer = LibXML::XML::Writer.string
|
79
|
+
document(writer) do
|
80
|
+
assert(writer.write_pi('php', 'echo "foo";'))
|
81
|
+
end
|
82
|
+
assert_equal(writer.result.strip!, expected)
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_comment
|
86
|
+
expected = "<?xml version=\"1.0\"?>\n<!--foo-->"
|
87
|
+
|
88
|
+
writer = LibXML::XML::Writer.string
|
89
|
+
document(writer) do
|
90
|
+
assert(writer.start_comment)
|
91
|
+
assert(writer.write_string 'foo')
|
92
|
+
assert(writer.end_comment)
|
93
|
+
end
|
94
|
+
assert_equal(writer.result.strip!, expected)
|
95
|
+
|
96
|
+
writer = LibXML::XML::Writer.string
|
97
|
+
document(writer) do
|
98
|
+
assert(writer.write_comment 'foo')
|
99
|
+
end
|
100
|
+
assert_equal(writer.result.strip!, expected)
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_cdata
|
104
|
+
expected = "<?xml version=\"1.0\"?>\n<root><![CDATA[<?php echo $foo; ?>]]></root>"
|
105
|
+
|
106
|
+
writer = LibXML::XML::Writer.string
|
107
|
+
document(writer) do
|
108
|
+
element writer, 'root' do
|
109
|
+
assert(writer.start_cdata)
|
110
|
+
assert(writer.write_string '<?php echo $foo; ?>')
|
111
|
+
assert(writer.end_cdata)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
assert_equal(writer.result.strip!, expected)
|
115
|
+
|
116
|
+
writer = LibXML::XML::Writer.string
|
117
|
+
document(writer) do
|
118
|
+
element writer, 'root' do
|
119
|
+
assert(writer.write_cdata '<?php echo $foo; ?>')
|
120
|
+
end
|
121
|
+
end
|
122
|
+
assert_equal(writer.result.strip!, expected)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_write_empty_elements
|
126
|
+
writer = LibXML::XML::Writer.string
|
127
|
+
document(writer) do
|
128
|
+
assert(writer.write_element 'foo')
|
129
|
+
end
|
130
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<foo/>")
|
131
|
+
|
132
|
+
writer = LibXML::XML::Writer.string
|
133
|
+
document(writer) do
|
134
|
+
assert(writer.write_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
135
|
+
end
|
136
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<" + XSL_PREFIX + ":stylesheet xmlns:xsl=\"" + XSL_URI + "\"/>")
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_valued_element
|
140
|
+
expected = "<?xml version=\"1.0\"?>\n<abc>123<def>456<ghi>789</ghi>cueillir des cerises</def>nous irons au bois</abc>"
|
141
|
+
|
142
|
+
writer = LibXML::XML::Writer.string
|
143
|
+
document(writer) do
|
144
|
+
assert(writer.start_element 'abc')
|
145
|
+
assert(writer.write_string '123')
|
146
|
+
assert(writer.start_element 'def')
|
147
|
+
assert(writer.write_string '456')
|
148
|
+
assert(writer.start_element 'ghi')
|
149
|
+
assert(writer.write_string '789')
|
150
|
+
assert(writer.end_element)
|
151
|
+
assert(writer.write_string 'cueillir des cerises')
|
152
|
+
assert(writer.end_element)
|
153
|
+
assert(writer.write_string 'nous irons au bois')
|
154
|
+
assert(writer.end_element)
|
155
|
+
end
|
156
|
+
assert_equal(writer.result.strip!, expected)
|
157
|
+
|
158
|
+
writer = LibXML::XML::Writer.string
|
159
|
+
document(writer) do
|
160
|
+
assert(writer.start_element 'abc')
|
161
|
+
assert(writer.write_string '123')
|
162
|
+
assert(writer.start_element 'def')
|
163
|
+
assert(writer.write_string '456')
|
164
|
+
assert(writer.write_element 'ghi', '789')
|
165
|
+
assert(writer.write_string 'cueillir des cerises')
|
166
|
+
assert(writer.end_element)
|
167
|
+
assert(writer.write_string 'nous irons au bois')
|
168
|
+
assert(writer.end_element)
|
169
|
+
end
|
170
|
+
assert_equal(writer.result.strip!, expected)
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_valued_element_ns
|
174
|
+
expected = "<?xml version=\"1.0\"?>\n" +
|
175
|
+
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
|
176
|
+
"<xsl:attribute-set>" +
|
177
|
+
"<xsl:attribute>20px</xsl:attribute>" +
|
178
|
+
"<xsl:attribute>solid</xsl:attribute>" +
|
179
|
+
"</xsl:attribute-set>" +
|
180
|
+
"</xsl:stylesheet>"
|
181
|
+
|
182
|
+
writer = LibXML::XML::Writer.string
|
183
|
+
document(writer) do
|
184
|
+
assert(writer.start_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
185
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute-set')
|
186
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute')
|
187
|
+
assert(writer.write_string '20px')
|
188
|
+
assert(writer.end_element)
|
189
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute')
|
190
|
+
assert(writer.write_string 'solid')
|
191
|
+
assert(writer.end_element)
|
192
|
+
assert(writer.end_element)
|
193
|
+
assert(writer.end_element)
|
194
|
+
end
|
195
|
+
assert_equal(writer.result.strip!, expected)
|
196
|
+
|
197
|
+
writer = LibXML::XML::Writer.string
|
198
|
+
document(writer) do
|
199
|
+
assert(writer.start_element_ns XSL_PREFIX, 'stylesheet', XSL_URI)
|
200
|
+
assert(writer.start_element_ns XSL_PREFIX, 'attribute-set')
|
201
|
+
assert(writer.write_element_ns XSL_PREFIX, 'attribute', nil, '20px')
|
202
|
+
assert(writer.write_element_ns XSL_PREFIX, 'attribute', nil, 'solid')
|
203
|
+
assert(writer.end_element)
|
204
|
+
assert(writer.end_element)
|
205
|
+
end
|
206
|
+
assert_equal(writer.result.strip!, expected)
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_attribute
|
210
|
+
writer = LibXML::XML::Writer.string
|
211
|
+
document(writer) do
|
212
|
+
element writer, 'root' do
|
213
|
+
element writer, 'child' do
|
214
|
+
assert(writer.start_attribute 'foo')
|
215
|
+
assert(writer.write_string 'bar')
|
216
|
+
assert(writer.end_attribute)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root><child foo=\"bar\"/></root>")
|
221
|
+
|
222
|
+
writer = LibXML::XML::Writer.string
|
223
|
+
document(writer) do
|
224
|
+
element writer, 'root' do
|
225
|
+
element writer, 'child' do
|
226
|
+
assert(writer.write_attribute 'abc', 'def')
|
227
|
+
assert(writer.write_string 'ghi') # must be done after attributes
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root><child abc=\"def\">ghi</child></root>")
|
232
|
+
end
|
233
|
+
|
234
|
+
def test_attribute_ns
|
235
|
+
expected = "<?xml version=\"1.0\"?>\n<root><link xlink:href=\"abc\" xhtml:class=\"def\"/></root>"
|
236
|
+
|
237
|
+
writer = LibXML::XML::Writer.string
|
238
|
+
document(writer) do
|
239
|
+
element writer, 'root' do
|
240
|
+
element writer, 'link' do
|
241
|
+
assert(writer.write_attribute_ns 'xlink', 'href', nil, 'abc')
|
242
|
+
assert(writer.write_attribute_ns 'xhtml', 'class', nil, 'def')
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
assert_equal(writer.result.strip!, expected)
|
247
|
+
|
248
|
+
writer = LibXML::XML::Writer.string
|
249
|
+
document(writer) do
|
250
|
+
element writer, 'root' do
|
251
|
+
element writer, 'link' do
|
252
|
+
assert(writer.start_attribute_ns 'xlink', 'href')
|
253
|
+
assert(writer.write_string 'abc')
|
254
|
+
assert(writer.end_attribute)
|
255
|
+
assert(writer.start_attribute_ns 'xhtml', 'class')
|
256
|
+
assert(writer.write_string 'def')
|
257
|
+
assert(writer.end_attribute)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
assert_equal(writer.result.strip!, expected)
|
262
|
+
end
|
263
|
+
|
264
|
+
def test_quote_char
|
265
|
+
if LibXML::XML::Writer.method_defined? :set_quote_char
|
266
|
+
writer = LibXML::XML::Writer.string
|
267
|
+
writer.set_quote_char "'"
|
268
|
+
document(writer) do
|
269
|
+
element writer, 'root' do
|
270
|
+
assert(writer.start_attribute 'abc')
|
271
|
+
assert(writer.write_string 'def')
|
272
|
+
assert(writer.end_attribute)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
assert(writer.result.strip!.end_with? "<root abc='def'/>")
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
def test_indentation_on
|
280
|
+
if LibXML::XML::Writer.method_defined? :set_indent
|
281
|
+
writer = LibXML::XML::Writer.string
|
282
|
+
assert(writer.set_indent true)
|
283
|
+
document(writer) do
|
284
|
+
element writer, 'root' do
|
285
|
+
element writer, 'child' do
|
286
|
+
assert(writer.start_attribute 'abc')
|
287
|
+
assert(writer.write_string 'def')
|
288
|
+
assert(writer.end_attribute)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root>\n <child abc=\"def\"/>\n</root>")
|
293
|
+
end
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_indentation_string
|
297
|
+
if LibXML::XML::Writer.method_defined? :set_indent_string
|
298
|
+
writer = LibXML::XML::Writer.string
|
299
|
+
assert(writer.set_indent true)
|
300
|
+
assert(writer.set_indent_string ' ' * 4)
|
301
|
+
document(writer) do
|
302
|
+
element writer, 'root' do
|
303
|
+
element writer, 'child' do
|
304
|
+
assert(writer.start_attribute 'abc')
|
305
|
+
assert(writer.write_string 'def')
|
306
|
+
assert(writer.end_attribute)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<root>\n <child abc=\"def\"/>\n</root>")
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_dtd_declaration
|
315
|
+
writer = LibXML::XML::Writer.string
|
316
|
+
dtd writer, 'html'
|
317
|
+
assert_equal(writer.result, '<!DOCTYPE html>')
|
318
|
+
|
319
|
+
writer = LibXML::XML::Writer.string
|
320
|
+
dtd writer, 'html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'
|
321
|
+
assert_equal(writer.result, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">')
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_dtd_attlist
|
325
|
+
expected = '<!DOCTYPE http [<!ATTLIST method (get|post) "get">]>'
|
326
|
+
|
327
|
+
writer = LibXML::XML::Writer.string
|
328
|
+
dtd writer, 'http' do
|
329
|
+
assert(writer.start_dtd_attlist 'method')
|
330
|
+
assert(writer.write_string '(get|post) "get"')
|
331
|
+
assert(writer.end_dtd_attlist)
|
332
|
+
end
|
333
|
+
assert_equal(writer.result, expected)
|
334
|
+
|
335
|
+
writer = LibXML::XML::Writer.string
|
336
|
+
dtd writer, 'http' do
|
337
|
+
assert(writer.write_dtd_attlist 'method', '(get|post) "get"')
|
338
|
+
end
|
339
|
+
assert_equal(writer.result, expected)
|
340
|
+
end
|
341
|
+
|
342
|
+
def test_dtd_element
|
343
|
+
expected = '<!DOCTYPE html [<!ELEMENT dl (dt|dd)+>]>'
|
344
|
+
|
345
|
+
writer = LibXML::XML::Writer.string
|
346
|
+
dtd writer, 'html' do
|
347
|
+
assert(writer.start_dtd_element 'dl')
|
348
|
+
assert(writer.write_string '(dt|dd)+')
|
349
|
+
assert(writer.end_dtd_element)
|
350
|
+
end
|
351
|
+
assert_equal(writer.result, expected)
|
352
|
+
|
353
|
+
writer = LibXML::XML::Writer.string
|
354
|
+
dtd writer, 'html' do
|
355
|
+
assert(writer.write_dtd_element 'dl', '(dt|dd)+')
|
356
|
+
end
|
357
|
+
assert_equal(writer.result, expected)
|
358
|
+
end
|
359
|
+
|
360
|
+
def test_dtd_entity
|
361
|
+
# parameterized entity
|
362
|
+
expected = '<!DOCTYPE html [<!ENTITY % special.pre "br | span | bdo | map"><!ENTITY % special "%special.pre; | object | img">]>'
|
363
|
+
|
364
|
+
writer = LibXML::XML::Writer.string
|
365
|
+
dtd writer, 'html' do
|
366
|
+
assert(writer.start_dtd_entity 'special.pre', true)
|
367
|
+
assert(writer.write_string 'br | span | bdo | map')
|
368
|
+
assert(writer.end_dtd_entity)
|
369
|
+
assert(writer.start_dtd_entity 'special', true)
|
370
|
+
assert(writer.write_string '%special.pre; | object | img')
|
371
|
+
assert(writer.end_dtd_entity)
|
372
|
+
end
|
373
|
+
assert_equal(writer.result, expected)
|
374
|
+
|
375
|
+
writer = LibXML::XML::Writer.string
|
376
|
+
dtd writer, 'html' do
|
377
|
+
assert(writer.write_dtd_internal_entity 'special.pre', 'br | span | bdo | map', true)
|
378
|
+
assert(writer.write_dtd_internal_entity 'special', '%special.pre; | object | img', true)
|
379
|
+
end
|
380
|
+
assert_equal(writer.result, expected)
|
381
|
+
|
382
|
+
# non parameterized entity
|
383
|
+
expected = '<!DOCTYPE html [<!ENTITY Alpha "Α">]>'
|
384
|
+
|
385
|
+
writer = LibXML::XML::Writer.string
|
386
|
+
dtd writer, 'html' do
|
387
|
+
assert(writer.start_dtd_entity 'Alpha')
|
388
|
+
assert(writer.write_string 'Α')
|
389
|
+
assert(writer.end_dtd_entity)
|
390
|
+
end
|
391
|
+
assert_equal(writer.result, expected)
|
392
|
+
|
393
|
+
writer = LibXML::XML::Writer.string
|
394
|
+
dtd writer, 'html' do
|
395
|
+
assert(writer.start_dtd_entity 'Alpha', false)
|
396
|
+
assert(writer.write_string 'Α')
|
397
|
+
assert(writer.end_dtd_entity)
|
398
|
+
end
|
399
|
+
assert_equal(writer.result, expected)
|
400
|
+
|
401
|
+
writer = LibXML::XML::Writer.string
|
402
|
+
dtd writer, 'html' do
|
403
|
+
assert(writer.write_dtd_internal_entity 'Alpha', 'Α', false)
|
404
|
+
end
|
405
|
+
assert_equal(writer.result, expected)
|
406
|
+
end
|
407
|
+
|
408
|
+
def test_dtd_notation
|
409
|
+
writer = LibXML::XML::Writer.string
|
410
|
+
dtd writer, 'pictures' do
|
411
|
+
assert(writer.write_dtd_notation 'GIF89a', '-//Compuserve//NOTATION Graphics Interchange Format 89a//EN', nil)
|
412
|
+
assert(writer.write_dtd_external_entity 'pictures', nil, 'images/plage.gif', 'GIF89a', false)
|
413
|
+
end
|
414
|
+
assert_equal(writer.result, '<!DOCTYPE pictures [<!NOTATION GIF89a PUBLIC "-//Compuserve//NOTATION Graphics Interchange Format 89a//EN"><!ENTITY pictures SYSTEM "images/plage.gif" NDATA GIF89a>]>')
|
415
|
+
end
|
416
|
+
|
417
|
+
def test_encoding
|
418
|
+
iso = 'éloïse'.encode 'ISO-8859-1'
|
419
|
+
|
420
|
+
writer = LibXML::XML::Writer.string
|
421
|
+
document(writer) do
|
422
|
+
assert(writer.write_element iso)
|
423
|
+
end
|
424
|
+
assert_equal(writer.result.strip!, "<?xml version=\"1.0\"?>\n<éloïse/>")
|
425
|
+
end
|
426
|
+
|
427
|
+
def test_flush
|
428
|
+
writer = LibXML::XML::Writer.string
|
429
|
+
assert(writer.start_document)
|
430
|
+
assert_equal(writer.flush.strip!, '<?xml version="1.0"?>')
|
431
|
+
assert(writer.start_element 'foo')
|
432
|
+
assert(writer.end_element)
|
433
|
+
assert(writer.end_document)
|
434
|
+
writer.flush false
|
435
|
+
assert_equal(writer.result.strip, '<foo/>')
|
436
|
+
end
|
437
|
+
|
438
|
+
def test_nil_pe_issue
|
439
|
+
expected = '<!DOCTYPE html [<!ENTITY special.pre "br | span | bdo | map"><!ENTITY special "%special.pre; | object | img">]>'
|
440
|
+
|
441
|
+
writer = LibXML::XML::Writer.string
|
442
|
+
dtd writer, 'html' do
|
443
|
+
assert(writer.write_dtd_internal_entity 'special.pre', 'br | span | bdo | map', nil)
|
444
|
+
assert(writer.write_dtd_internal_entity 'special', '%special.pre; | object | img', nil)
|
445
|
+
end
|
446
|
+
assert_equal(writer.result, expected)
|
447
|
+
end
|
448
|
+
|
449
|
+
private
|
450
|
+
|
451
|
+
def document(writer, options = {})
|
452
|
+
assert(writer.start_document options)
|
453
|
+
yield if block_given?
|
454
|
+
assert(writer.end_document)
|
455
|
+
end
|
456
|
+
|
457
|
+
def dtd(writer, name, pubid = nil, sysid = nil)
|
458
|
+
assert(writer.start_dtd name, pubid, sysid)
|
459
|
+
yield if block_given?
|
460
|
+
assert(writer.end_dtd)
|
461
|
+
end
|
462
|
+
|
463
|
+
def element(writer, localname)
|
464
|
+
assert(writer.start_element localname)
|
465
|
+
yield if block_given?
|
466
|
+
assert(writer.end_element)
|
467
|
+
end
|
468
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require_relative './test_helper'
|
4
|
+
|
5
|
+
class TestXInclude < Minitest::Test
|
6
|
+
def setup
|
7
|
+
@doc = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'model/xinclude.xml'))
|
8
|
+
assert_instance_of(LibXML::XML::Document, @doc)
|
9
|
+
end
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
@doc = nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_ruby_xml_xinclude
|
16
|
+
assert_equal(1, @doc.xinclude)
|
17
|
+
assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<document xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n <p>This libxml2 binding has the following project information:\n <code>This is some text to include in an xml file via XInclude.</code></p>\n</document>\n",
|
18
|
+
@doc.to_s)
|
19
|
+
end
|
20
|
+
end
|