libxml-ruby 2.9.0-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY +790 -0
  3. data/LICENSE +21 -0
  4. data/MANIFEST +166 -0
  5. data/README.rdoc +184 -0
  6. data/Rakefile +81 -0
  7. data/ext/libxml/extconf.h +4 -0
  8. data/ext/libxml/extconf.rb +57 -0
  9. data/ext/libxml/libxml.c +80 -0
  10. data/ext/libxml/libxml_ruby.def +35 -0
  11. data/ext/libxml/ruby_libxml.h +75 -0
  12. data/ext/libxml/ruby_xml.c +977 -0
  13. data/ext/libxml/ruby_xml.h +20 -0
  14. data/ext/libxml/ruby_xml_attr.c +333 -0
  15. data/ext/libxml/ruby_xml_attr.h +12 -0
  16. data/ext/libxml/ruby_xml_attr_decl.c +153 -0
  17. data/ext/libxml/ruby_xml_attr_decl.h +11 -0
  18. data/ext/libxml/ruby_xml_attributes.c +275 -0
  19. data/ext/libxml/ruby_xml_attributes.h +15 -0
  20. data/ext/libxml/ruby_xml_cbg.c +85 -0
  21. data/ext/libxml/ruby_xml_document.c +1133 -0
  22. data/ext/libxml/ruby_xml_document.h +11 -0
  23. data/ext/libxml/ruby_xml_dtd.c +261 -0
  24. data/ext/libxml/ruby_xml_dtd.h +9 -0
  25. data/ext/libxml/ruby_xml_encoding.c +262 -0
  26. data/ext/libxml/ruby_xml_encoding.h +19 -0
  27. data/ext/libxml/ruby_xml_error.c +996 -0
  28. data/ext/libxml/ruby_xml_error.h +12 -0
  29. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  30. data/ext/libxml/ruby_xml_html_parser.h +10 -0
  31. data/ext/libxml/ruby_xml_html_parser_context.c +337 -0
  32. data/ext/libxml/ruby_xml_html_parser_context.h +10 -0
  33. data/ext/libxml/ruby_xml_html_parser_options.c +46 -0
  34. data/ext/libxml/ruby_xml_html_parser_options.h +10 -0
  35. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  36. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  37. data/ext/libxml/ruby_xml_io.c +52 -0
  38. data/ext/libxml/ruby_xml_io.h +10 -0
  39. data/ext/libxml/ruby_xml_namespace.c +153 -0
  40. data/ext/libxml/ruby_xml_namespace.h +10 -0
  41. data/ext/libxml/ruby_xml_namespaces.c +293 -0
  42. data/ext/libxml/ruby_xml_namespaces.h +9 -0
  43. data/ext/libxml/ruby_xml_node.c +1446 -0
  44. data/ext/libxml/ruby_xml_node.h +11 -0
  45. data/ext/libxml/ruby_xml_parser.c +94 -0
  46. data/ext/libxml/ruby_xml_parser.h +12 -0
  47. data/ext/libxml/ruby_xml_parser_context.c +999 -0
  48. data/ext/libxml/ruby_xml_parser_context.h +10 -0
  49. data/ext/libxml/ruby_xml_parser_options.c +66 -0
  50. data/ext/libxml/ruby_xml_parser_options.h +12 -0
  51. data/ext/libxml/ruby_xml_reader.c +1226 -0
  52. data/ext/libxml/ruby_xml_reader.h +17 -0
  53. data/ext/libxml/ruby_xml_relaxng.c +110 -0
  54. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  55. data/ext/libxml/ruby_xml_sax2_handler.c +326 -0
  56. data/ext/libxml/ruby_xml_sax2_handler.h +10 -0
  57. data/ext/libxml/ruby_xml_sax_parser.c +120 -0
  58. data/ext/libxml/ruby_xml_sax_parser.h +10 -0
  59. data/ext/libxml/ruby_xml_schema.c +300 -0
  60. data/ext/libxml/ruby_xml_schema.h +809 -0
  61. data/ext/libxml/ruby_xml_schema_attribute.c +109 -0
  62. data/ext/libxml/ruby_xml_schema_attribute.h +15 -0
  63. data/ext/libxml/ruby_xml_schema_element.c +94 -0
  64. data/ext/libxml/ruby_xml_schema_element.h +14 -0
  65. data/ext/libxml/ruby_xml_schema_facet.c +52 -0
  66. data/ext/libxml/ruby_xml_schema_facet.h +13 -0
  67. data/ext/libxml/ruby_xml_schema_type.c +259 -0
  68. data/ext/libxml/ruby_xml_schema_type.h +9 -0
  69. data/ext/libxml/ruby_xml_version.h +9 -0
  70. data/ext/libxml/ruby_xml_writer.c +1136 -0
  71. data/ext/libxml/ruby_xml_writer.h +10 -0
  72. data/ext/libxml/ruby_xml_xinclude.c +16 -0
  73. data/ext/libxml/ruby_xml_xinclude.h +11 -0
  74. data/ext/libxml/ruby_xml_xpath.c +188 -0
  75. data/ext/libxml/ruby_xml_xpath.h +13 -0
  76. data/ext/libxml/ruby_xml_xpath_context.c +360 -0
  77. data/ext/libxml/ruby_xml_xpath_context.h +9 -0
  78. data/ext/libxml/ruby_xml_xpath_expression.c +81 -0
  79. data/ext/libxml/ruby_xml_xpath_expression.h +10 -0
  80. data/ext/libxml/ruby_xml_xpath_object.c +335 -0
  81. data/ext/libxml/ruby_xml_xpath_object.h +17 -0
  82. data/ext/libxml/ruby_xml_xpointer.c +99 -0
  83. data/ext/libxml/ruby_xml_xpointer.h +11 -0
  84. data/ext/vc/libxml_ruby.sln +26 -0
  85. data/lib/2.3/libxml_ruby.so +0 -0
  86. data/lib/libs/libiconv-2.dll +0 -0
  87. data/lib/libs/libxml2-2.dll +0 -0
  88. data/lib/libs/zlib1.dll +0 -0
  89. data/lib/libxml.rb +35 -0
  90. data/lib/libxml/attr.rb +123 -0
  91. data/lib/libxml/attr_decl.rb +80 -0
  92. data/lib/libxml/attributes.rb +14 -0
  93. data/lib/libxml/document.rb +194 -0
  94. data/lib/libxml/error.rb +95 -0
  95. data/lib/libxml/hpricot.rb +78 -0
  96. data/lib/libxml/html_parser.rb +96 -0
  97. data/lib/libxml/namespace.rb +62 -0
  98. data/lib/libxml/namespaces.rb +38 -0
  99. data/lib/libxml/node.rb +399 -0
  100. data/lib/libxml/ns.rb +22 -0
  101. data/lib/libxml/parser.rb +367 -0
  102. data/lib/libxml/properties.rb +23 -0
  103. data/lib/libxml/reader.rb +29 -0
  104. data/lib/libxml/sax_callbacks.rb +180 -0
  105. data/lib/libxml/sax_parser.rb +58 -0
  106. data/lib/libxml/schema.rb +67 -0
  107. data/lib/libxml/schema/attribute.rb +19 -0
  108. data/lib/libxml/schema/element.rb +27 -0
  109. data/lib/libxml/schema/type.rb +29 -0
  110. data/lib/libxml/tree.rb +29 -0
  111. data/lib/libxml/xpath_object.rb +16 -0
  112. data/lib/xml.rb +14 -0
  113. data/lib/xml/libxml.rb +10 -0
  114. data/libxml-ruby.gemspec +47 -0
  115. data/script/benchmark/depixelate +634 -0
  116. data/script/benchmark/hamlet.xml +9055 -0
  117. data/script/benchmark/parsecount +170 -0
  118. data/script/benchmark/sock_entries.xml +507 -0
  119. data/script/benchmark/throughput +41 -0
  120. data/script/test +6 -0
  121. data/setup.rb +1585 -0
  122. data/test/c14n/given/doc.dtd +1 -0
  123. data/test/c14n/given/example-1.xml +14 -0
  124. data/test/c14n/given/example-2.xml +11 -0
  125. data/test/c14n/given/example-3.xml +18 -0
  126. data/test/c14n/given/example-4.xml +9 -0
  127. data/test/c14n/given/example-5.xml +12 -0
  128. data/test/c14n/given/example-6.xml +2 -0
  129. data/test/c14n/given/example-7.xml +11 -0
  130. data/test/c14n/given/example-8.xml +11 -0
  131. data/test/c14n/given/example-8.xpath +10 -0
  132. data/test/c14n/given/world.txt +1 -0
  133. data/test/c14n/result/1-1-without-comments/example-1 +4 -0
  134. data/test/c14n/result/1-1-without-comments/example-2 +11 -0
  135. data/test/c14n/result/1-1-without-comments/example-3 +14 -0
  136. data/test/c14n/result/1-1-without-comments/example-4 +9 -0
  137. data/test/c14n/result/1-1-without-comments/example-5 +3 -0
  138. data/test/c14n/result/1-1-without-comments/example-6 +1 -0
  139. data/test/c14n/result/1-1-without-comments/example-7 +1 -0
  140. data/test/c14n/result/1-1-without-comments/example-8 +1 -0
  141. data/test/c14n/result/with-comments/example-1 +6 -0
  142. data/test/c14n/result/with-comments/example-2 +11 -0
  143. data/test/c14n/result/with-comments/example-3 +14 -0
  144. data/test/c14n/result/with-comments/example-4 +9 -0
  145. data/test/c14n/result/with-comments/example-5 +4 -0
  146. data/test/c14n/result/with-comments/example-6 +1 -0
  147. data/test/c14n/result/with-comments/example-7 +1 -0
  148. data/test/c14n/result/without-comments/example-1 +4 -0
  149. data/test/c14n/result/without-comments/example-2 +11 -0
  150. data/test/c14n/result/without-comments/example-3 +14 -0
  151. data/test/c14n/result/without-comments/example-4 +9 -0
  152. data/test/c14n/result/without-comments/example-5 +3 -0
  153. data/test/c14n/result/without-comments/example-6 +1 -0
  154. data/test/c14n/result/without-comments/example-7 +1 -0
  155. data/test/model/atom.xml +13 -0
  156. data/test/model/bands.iso-8859-1.xml +5 -0
  157. data/test/model/bands.utf-8.xml +5 -0
  158. data/test/model/bands.xml +5 -0
  159. data/test/model/books.xml +154 -0
  160. data/test/model/merge_bug_data.xml +58 -0
  161. data/test/model/ruby-lang.html +238 -0
  162. data/test/model/rubynet.xml +79 -0
  163. data/test/model/rubynet_project +1 -0
  164. data/test/model/shiporder.rnc +28 -0
  165. data/test/model/shiporder.rng +86 -0
  166. data/test/model/shiporder.xml +23 -0
  167. data/test/model/shiporder.xsd +40 -0
  168. data/test/model/soap.xml +27 -0
  169. data/test/model/xinclude.xml +5 -0
  170. data/test/tc_attr.rb +181 -0
  171. data/test/tc_attr_decl.rb +132 -0
  172. data/test/tc_attributes.rb +142 -0
  173. data/test/tc_canonicalize.rb +124 -0
  174. data/test/tc_deprecated_require.rb +12 -0
  175. data/test/tc_document.rb +125 -0
  176. data/test/tc_document_write.rb +195 -0
  177. data/test/tc_dtd.rb +128 -0
  178. data/test/tc_encoding.rb +126 -0
  179. data/test/tc_encoding_sax.rb +115 -0
  180. data/test/tc_error.rb +179 -0
  181. data/test/tc_html_parser.rb +161 -0
  182. data/test/tc_html_parser_context.rb +23 -0
  183. data/test/tc_namespace.rb +61 -0
  184. data/test/tc_namespaces.rb +209 -0
  185. data/test/tc_node.rb +215 -0
  186. data/test/tc_node_cdata.rb +50 -0
  187. data/test/tc_node_comment.rb +32 -0
  188. data/test/tc_node_copy.rb +41 -0
  189. data/test/tc_node_edit.rb +174 -0
  190. data/test/tc_node_pi.rb +39 -0
  191. data/test/tc_node_text.rb +70 -0
  192. data/test/tc_node_write.rb +107 -0
  193. data/test/tc_node_xlink.rb +28 -0
  194. data/test/tc_parser.rb +375 -0
  195. data/test/tc_parser_context.rb +204 -0
  196. data/test/tc_properties.rb +38 -0
  197. data/test/tc_reader.rb +399 -0
  198. data/test/tc_relaxng.rb +53 -0
  199. data/test/tc_sax_parser.rb +319 -0
  200. data/test/tc_schema.rb +161 -0
  201. data/test/tc_traversal.rb +152 -0
  202. data/test/tc_writer.rb +447 -0
  203. data/test/tc_xinclude.rb +20 -0
  204. data/test/tc_xml.rb +225 -0
  205. data/test/tc_xpath.rb +244 -0
  206. data/test/tc_xpath_context.rb +88 -0
  207. data/test/tc_xpath_expression.rb +37 -0
  208. data/test/tc_xpointer.rb +72 -0
  209. data/test/test_helper.rb +16 -0
  210. data/test/test_suite.rb +49 -0
  211. metadata +344 -0
@@ -0,0 +1,152 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+
5
+ class TestTranversal < Minitest::Test
6
+ ROOT_NODES_LENGTH = 27
7
+ ROOT_ELEMENTS_LENGTH = 13
8
+
9
+ def setup
10
+ filename = File.join(File.dirname(__FILE__), 'model/books.xml')
11
+ @doc = XML::Document.file(filename)
12
+ end
13
+
14
+ def teardown
15
+ @doc = nil
16
+ end
17
+
18
+ def test_children
19
+ # Includes text nodes and such
20
+ assert_equal(ROOT_NODES_LENGTH, @doc.root.children.length)
21
+ end
22
+
23
+ def test_children_iteration
24
+ # Includes text nodes and such
25
+ nodes = @doc.root.children.inject([]) do |arr, node|
26
+ arr << node
27
+ arr
28
+ end
29
+
30
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
31
+ end
32
+
33
+ def test_no_children
34
+ # Get a node with no children
35
+ node = @doc.find_first('/catalog/book[@id="bk113"]/price')
36
+ assert_equal(0, node.children.length)
37
+ end
38
+
39
+ def test_no_children_inner_xml
40
+ # Get a node with no children
41
+ node = @doc.find_first('/catalog/book[@id="bk113"]/price')
42
+ assert_nil(node.inner_xml)
43
+ end
44
+ def test_each
45
+ # Includes text nodes and such
46
+ nodes = @doc.root.inject([]) do |arr, node|
47
+ arr << node
48
+ arr
49
+ end
50
+
51
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
52
+ end
53
+
54
+ def test_each_element
55
+ # Includes text nodes and such
56
+ nodes = []
57
+ @doc.root.each_element do |node|
58
+ nodes << node
59
+ end
60
+
61
+ assert_equal(ROOT_ELEMENTS_LENGTH, nodes.length)
62
+ end
63
+
64
+ def test_next
65
+ nodes = []
66
+
67
+ node = @doc.root.first
68
+
69
+ while node
70
+ nodes << node
71
+ node = node.next
72
+ end
73
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
74
+ end
75
+
76
+ def test_next?
77
+ first_node = @doc.root.first
78
+ assert(first_node.next?)
79
+
80
+ last_node = @doc.root.last
81
+ assert(!last_node.next?)
82
+ end
83
+
84
+ def test_prev
85
+ nodes = []
86
+
87
+ node = @doc.root.last
88
+
89
+ while node
90
+ nodes << node
91
+ node = node.prev
92
+ end
93
+ assert_equal(ROOT_NODES_LENGTH, nodes.length)
94
+ end
95
+
96
+ def test_prev?
97
+ first_node = @doc.root.first
98
+ assert(!first_node.prev?)
99
+
100
+ last_node = @doc.root.last
101
+ assert(last_node.prev?)
102
+ end
103
+
104
+ def test_parent?
105
+ assert(!@doc.parent?)
106
+ assert(@doc.root.parent?)
107
+ end
108
+
109
+ def test_child?
110
+ assert(@doc.child?)
111
+ assert(!@doc.root.first.child?)
112
+ end
113
+
114
+ def test_next_prev_equivalence
115
+ next_nodes = []
116
+ last_nodes = []
117
+
118
+ node = @doc.root.first
119
+ while node
120
+ next_nodes << node
121
+ node = node.next
122
+ end
123
+
124
+ node = @doc.root.last
125
+ while node
126
+ last_nodes << node
127
+ node = node.prev
128
+ end
129
+
130
+ assert_equal(next_nodes, last_nodes.reverse)
131
+ end
132
+
133
+ def test_next_children_equivalence
134
+ next_nodes = []
135
+
136
+ node = @doc.root.first
137
+ while node
138
+ next_nodes << node
139
+ node = node.next
140
+ end
141
+
142
+ assert_equal(@doc.root.children, next_nodes)
143
+ end
144
+
145
+ def test_doc_class
146
+ assert_instance_of(XML::Document, @doc)
147
+ end
148
+
149
+ def test_root_class
150
+ assert_instance_of(XML::Node, @doc.root)
151
+ end
152
+ end
@@ -0,0 +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 "&#913;">]>'
361
+
362
+ writer = XML::Writer.string
363
+ dtd writer, 'html' do
364
+ assert(writer.start_dtd_entity 'Alpha')
365
+ assert(writer.write_string '&#913;')
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 '&#913;')
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', '&#913;', 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