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,124 @@
1
+ # encoding: UTF-8
2
+ require './test_helper'
3
+
4
+ class TestCanonicalize < Minitest::Test
5
+ # (www.w3.org) 3.1 PIs, Comments, and Outside of Document Element
6
+ # http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
7
+ def test_canonicalize_with_w3c_c14n_3_1
8
+ given_doc = XML::Document.file('c14n/given/example-1.xml')
9
+
10
+ # With Comments
11
+ expected_with_comments = IO.read('c14n/result/with-comments/example-1')
12
+ assert_equal(expected_with_comments, given_doc.canonicalize(:comments => true))
13
+
14
+ # Without Comments
15
+ expected_without_comments = IO.read('c14n/result/without-comments/example-1')
16
+ assert_equal(expected_without_comments, given_doc.canonicalize)
17
+ assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
18
+
19
+ # Without Comments (XML_C14N_1_1)
20
+ expected_1_1_without_comments = IO.read('c14n/result/1-1-without-comments/example-1')
21
+ mode = XML::Document::XML_C14N_1_1
22
+ assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
23
+ end#test_canonicalize_with_w3c_c14n_3_1
24
+
25
+
26
+ # (www.w3.org) 3.2 Whitespace in Document Content
27
+ # http://www.w3.org/TR/xml-c14n#Example-WhitespaceInContent
28
+ def test_canonicalize_with_w3c_c14n_3_2
29
+ given_doc = XML::Document.file('c14n/given/example-2.xml')
30
+ expected = IO.read('c14n/result/without-comments/example-2')
31
+ assert_equal(expected, given_doc.canonicalize)
32
+
33
+ expected_1_1_without_comments = IO.read('c14n/result/1-1-without-comments/example-2')
34
+ mode = XML::Document::XML_C14N_1_1
35
+ assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
36
+ end
37
+
38
+ # (www.w3.org) 3.3 Start and End Tags
39
+ # http://www.w3.org/TR/xml-c14n#Example-SETags
40
+ # (2012-02-20) Test failing due to missing 'attr' in 'e9' node.
41
+ # - Embedded DTD not parsed out of XML, therefore default attributes are
42
+ # not applied to canonicalization.
43
+ def test_canonicalize_with_w3c_c14n_3_3
44
+ given_doc = XML::Document.file('c14n/given/example-3.xml')
45
+ expected = IO.read('c14n/result/without-comments/example-3')
46
+ assert_equal(expected, given_doc.canonicalize)
47
+
48
+ expected_1_1_without_comments = IO.read('c14n/result/1-1-without-comments/example-3')
49
+ mode = XML::Document::XML_C14N_1_1
50
+ assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
51
+ end
52
+
53
+ # (www.w3.org) 3.4 Character Modifications and Character References
54
+ # http://www.w3.org/TR/xml-c14n#Example-Chars
55
+ def test_canonicalize_with_w3c_c14n_3_4
56
+ given_doc = XML::Document.file('c14n/given/example-4.xml')
57
+ expected = IO.read('c14n/result/without-comments/example-4')
58
+ assert_equal(expected, given_doc.canonicalize)
59
+
60
+ expected_1_1_without_comments = IO.read('c14n/result/1-1-without-comments/example-4')
61
+ mode = XML::Document::XML_C14N_1_1
62
+ assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
63
+ end
64
+
65
+ # (www.w3.org) 3.5 Entity References
66
+ # http://www.w3.org/TR/xml-c14n#Example-Entities
67
+ # (2012-02-20) Failing likely due to a logic error
68
+ # - libxml2(c14n.c:1788) XML_ENTITY_REF_NODE is invalid node for parsing.
69
+ def test_canonicalize_with_w3c_c14n_3_5
70
+ given_doc = XML::Document.file('c14n/given/example-5.xml')
71
+
72
+ # With Comments
73
+ expected_with_comments = IO.read('c14n/result/with-comments/example-5')
74
+
75
+ # TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
76
+ #assert_equal(expected_with_comments, given_doc.canonicalize(:comments => true))
77
+
78
+ # Without Comments
79
+ expected_without_comments = IO.read('c14n/result/without-comments/example-5')
80
+ # TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
81
+ #assert_equal(expected_without_comments, given_doc.canonicalize(:comments => false))
82
+ expected_1_1_without_comments = IO.read('c14n/result/1-1-without-comments/example-5')
83
+ mode = XML::Document::XML_C14N_1_1
84
+
85
+ # TODO - CANNOT COMPLETE TEST unless libxml2 supports additional node types.
86
+ #assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
87
+ end
88
+
89
+ # (www.w3.org) 3.6 UTF-8 Encoding
90
+ # http://www.w3.org/TR/xml-c14n#Example-UTF8
91
+ def test_canonicalize_with_w3c_c14n_3_6
92
+ given_doc = XML::Document.file('c14n/given/example-6.xml')
93
+ if defined?(Encoding)
94
+ expected = IO.read('c14n/result/without-comments/example-6', :encoding => Encoding::UTF_8)
95
+ else
96
+ expected = IO.read('c14n/result/without-comments/example-6')
97
+ end
98
+ assert_equal(expected, given_doc.canonicalize)
99
+
100
+ if defined?(Encoding)
101
+ expected_1_1_without_comments = IO.read('c14n/result/1-1-without-comments/example-6', :encoding => Encoding::UTF_8)
102
+ else
103
+ expected_1_1_without_comments = IO.read('c14n/result/1-1-without-comments/example-6')
104
+ end
105
+ mode = XML::Document::XML_C14N_1_1
106
+ assert_equal(expected_1_1_without_comments, given_doc.canonicalize(:mode => mode))
107
+ end
108
+
109
+ # (www.w3.org) 3.7 Document Subsets
110
+ # http://www.w3.org/TR/xml-c14n#Example-DocSubsets
111
+ def test_canonicalize_with_w3c_c14n_3_7
112
+ # Non Canonicalized Document
113
+ given_doc = XML::Document.file('c14n/given/example-7.xml')
114
+ expected = IO.read('c14n/result/without-comments/example-7')
115
+
116
+ e1_node = given_doc.find_first('ietf:e1', 'ietf:http://www.ietf.org')
117
+
118
+ # Select current node, all child nodes, all attributes and namespace nodes
119
+ subdoc_nodes = e1_node.find("(.//.|.//@id|namespace::*)")
120
+
121
+ # TODO - This fails because the namespace nodes aren't taken into account
122
+ # assert_equal(expected, given_doc.canonicalize(:nodes => subdoc_nodes))
123
+ end
124
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'xml/libxml'
4
+
5
+ class TestDeprecatedRequire < Minitest::Test
6
+ def test_basic
7
+ xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
8
+ assert_instance_of(XML::Parser, xp)
9
+ @doc = xp.parse
10
+ assert_instance_of(XML::Document, @doc)
11
+ end
12
+ end
@@ -0,0 +1,125 @@
1
+ # encoding: UTF-8
2
+ require './test_helper'
3
+
4
+ class TestDocument < Minitest::Test
5
+ def setup
6
+ xp = XML::Parser.string('<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
7
+ assert_instance_of(XML::Parser, xp)
8
+ @doc = xp.parse
9
+ assert_instance_of(XML::Document, @doc)
10
+ end
11
+
12
+ def teardown
13
+ @doc = nil
14
+ end
15
+
16
+ def test_klass
17
+ assert_instance_of(XML::Document, @doc)
18
+ end
19
+
20
+ def test_context
21
+ context = @doc.context
22
+ assert_instance_of(XML::XPath::Context, context)
23
+ end
24
+
25
+ def test_find
26
+ set = @doc.find('/ruby_array/fixnum')
27
+ assert_instance_of(XML::XPath::Object, set)
28
+ assert_raises(NoMethodError) {
29
+ xpt = set.xpath
30
+ }
31
+ end
32
+
33
+ def test_compression
34
+ if XML.enabled_zlib?
35
+ 0.upto(9) do |i|
36
+ assert_equal(i, @doc.compression = i)
37
+ assert_equal(i, @doc.compression)
38
+ end
39
+
40
+ 9.downto(0) do |i|
41
+ assert_equal(i, @doc.compression = i)
42
+ assert_equal(i, @doc.compression)
43
+ end
44
+
45
+ 10.upto(20) do |i|
46
+ # assert_equal(9, @doc.compression = i)
47
+ assert_equal(i, @doc.compression = i) # This works around a bug in Ruby 1.8
48
+ assert_equal(9, @doc.compression)
49
+ end
50
+
51
+ -1.downto(-10) do |i|
52
+ # assert_equal(0, @doc.compression = i)
53
+ assert_equal(i, @doc.compression = i) # FIXME This bug should get fixed ASAP
54
+ assert_equal(0, @doc.compression)
55
+ end
56
+ end
57
+ end
58
+
59
+ def test_version
60
+ assert_equal('1.0', @doc.version)
61
+
62
+ doc = XML::Document.new('6.9')
63
+ assert_equal('6.9', doc.version)
64
+ end
65
+
66
+ def test_write_root
67
+ @doc.root = XML::Node.new('rubynet')
68
+ assert_instance_of(XML::Node, @doc.root)
69
+ assert_instance_of(XML::Document, @doc.root.doc)
70
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<rubynet/>\n",
71
+ @doc.to_s(:indent => false))
72
+ end
73
+
74
+ def test_doc_node_type
75
+ assert_equal(XML::Node::DOCUMENT_NODE, XML::Document.new.node_type)
76
+ end
77
+
78
+ def test_doc_node_type_name
79
+ assert_equal('document_xml', XML::Document.new.node_type_name)
80
+ end
81
+
82
+ def test_xhtml
83
+ doc = XML::Document.new
84
+ assert(!doc.xhtml?)
85
+ XML::Dtd.new "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd", nil, doc, true
86
+ assert(doc.xhtml?)
87
+ end
88
+
89
+ def test_document_root
90
+ doc1 = LibXML::XML::Document.string("<one/>")
91
+ doc2 = LibXML::XML::Document.string("<two/>")
92
+
93
+ error = assert_raises(XML::Error) do
94
+ doc1.root = doc2.root
95
+ end
96
+ assert_equal(" Nodes belong to different documents. You must first import the node by calling XML::Document.import.",
97
+ error.to_s)
98
+
99
+ doc2.root << doc2.import(doc1.root)
100
+ assert_equal('<one/>', doc1.root.to_s)
101
+ assert_equal('<two><one/></two>', doc2.root.to_s(:indent => false))
102
+
103
+ assert(!doc1.root.equal?(doc2.root))
104
+ assert(doc1.root.doc != doc2.root.doc)
105
+ end
106
+
107
+ def test_import_node
108
+ doc1 = XML::Parser.string('<nums><one></one></nums>').parse
109
+ doc2 = XML::Parser.string('<nums><two></two></nums>').parse
110
+
111
+ node = doc1.root.child
112
+
113
+ error = assert_raises(XML::Error) do
114
+ doc2.root << node
115
+ end
116
+
117
+ assert_equal(" Nodes belong to different documents. You must first import the node by calling XML::Document.import.",
118
+ error.to_s)
119
+
120
+ doc2.root << doc2.import(node)
121
+
122
+ assert_equal("<nums><two/><one/></nums>",
123
+ doc2.root.to_s(:indent => false))
124
+ end
125
+ end
@@ -0,0 +1,195 @@
1
+ # encoding: UTF-8
2
+
3
+ require './test_helper'
4
+ require 'tmpdir'
5
+
6
+ class TestDocumentWrite < Minitest::Test
7
+ def setup
8
+ @file_name = "model/bands.utf-8.xml"
9
+
10
+ # Strip spaces to make testing easier
11
+ XML.default_keep_blanks = false
12
+ file = File.join(File.dirname(__FILE__), @file_name)
13
+ @doc = XML::Document.file(file)
14
+ end
15
+
16
+ def teardown
17
+ XML.default_keep_blanks = true
18
+ @doc = nil
19
+ end
20
+
21
+ # --- to_s tests ---
22
+ def test_to_s_default
23
+ # Default to_s has indentation
24
+ if defined?(Encoding)
25
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
26
+ @doc.to_s)
27
+ else
28
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
29
+ @doc.to_s)
30
+ end
31
+ end
32
+
33
+ def test_to_s_no_global_indentation
34
+ # No indentation due to global setting
35
+ XML.indent_tree_output = false
36
+ value = @doc.to_s
37
+
38
+ if defined?(Encoding)
39
+ assert_equal(Encoding::UTF_8, value.encoding)
40
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n<m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n<iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
41
+ value)
42
+ else
43
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n<m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n<iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
44
+ value)
45
+ end
46
+ ensure
47
+ XML.indent_tree_output = true
48
+ end
49
+
50
+ def test_to_s_no_indentation
51
+ # No indentation due to local setting
52
+ value = @doc.to_s(:indent => false)
53
+ if defined?(Encoding)
54
+ assert_equal(Encoding::UTF_8, value.encoding)
55
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\"><m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
56
+ value)
57
+ else
58
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
59
+ value)
60
+ end
61
+ end
62
+
63
+ def test_to_s_encoding
64
+ # Test encodings
65
+
66
+ # UTF8:
67
+ # ö - c3 b6 in hex, \303\266 in octal
68
+ # ü - c3 bc in hex, \303\274 in octal
69
+ value = @doc.to_s(:encoding => XML::Encoding::UTF_8)
70
+ if defined?(Encoding)
71
+ assert_equal(Encoding::UTF_8, value.encoding)
72
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
73
+ value)
74
+ else
75
+ assert_equal("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
76
+ value)
77
+ end
78
+
79
+ # ISO_8859_1:
80
+ # ö - f6 in hex, \366 in octal
81
+ # ü - fc in hex, \374 in octal
82
+ value = @doc.to_s(:encoding => XML::Encoding::ISO_8859_1)
83
+ if defined?(Encoding)
84
+ assert_equal(Encoding::ISO8859_1, value.encoding)
85
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n".force_encoding(Encoding::ISO8859_1),
86
+ @doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
87
+ else
88
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">M\366tley Cr\374e is an American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
89
+ @doc.to_s(:encoding => XML::Encoding::ISO_8859_1))
90
+ end
91
+
92
+ # Invalid encoding
93
+ error = assert_raises(ArgumentError) do
94
+ @doc.to_s(:encoding => -9999)
95
+ end
96
+ assert_equal('Unknown encoding value: -9999', error.to_s)
97
+ end
98
+
99
+ # --- save tests -----
100
+ def test_save_utf8
101
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8.xml")
102
+
103
+ bytes = @doc.save(temp_filename)
104
+ assert_equal(305, bytes)
105
+
106
+ if defined?(Encoding)
107
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
108
+ assert_equal(Encoding::UTF_8, contents.encoding)
109
+ assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\">\n <m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
110
+ contents)
111
+ else
112
+ contents = File.read(temp_filename)
113
+ assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
114
+ contents)
115
+ end
116
+ ensure
117
+ File.delete(temp_filename)
118
+ end
119
+
120
+ def test_save_utf8_no_indents
121
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_utf8_no_indents.xml")
122
+
123
+ bytes = @doc.save(temp_filename, :indent => false)
124
+ assert_equal(298, bytes)
125
+
126
+ if defined?(Encoding)
127
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::UTF_8)
128
+ assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\"><m\u00F6tley_cr\u00FCe country=\"us\">M\u00F6tley Cr\u00FCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\u00F6tley_cr\u00FCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
129
+ contents)
130
+ else
131
+ contents = File.read(temp_filename)
132
+ assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">M\303\266tley Cr\303\274e is an American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
133
+ contents)
134
+ end
135
+ ensure
136
+ File.delete(temp_filename)
137
+ end
138
+
139
+ def test_save_iso_8859_1
140
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1.xml")
141
+ bytes = @doc.save(temp_filename, :encoding => XML::Encoding::ISO_8859_1)
142
+ assert_equal(304, bytes)
143
+
144
+ if defined?(Encoding)
145
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
146
+ assert_equal(Encoding::ISO8859_1, contents.encoding)
147
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n".force_encoding(Encoding::ISO8859_1),
148
+ contents)
149
+ else
150
+ contents = File.read(temp_filename)
151
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\">\n <m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe>\n <iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden>\n</bands>\n",
152
+ contents)
153
+ end
154
+ ensure
155
+ File.delete(temp_filename)
156
+ end
157
+
158
+ def test_save_iso_8859_1_no_indent
159
+ temp_filename = File.join(Dir.tmpdir, "tc_document_write_test_save_iso_8859_1_no_indent.xml")
160
+ bytes = @doc.save(temp_filename, :indent => false, :encoding => XML::Encoding::ISO_8859_1)
161
+ assert_equal(297, bytes)
162
+
163
+ if defined?(Encoding)
164
+ contents = File.read(temp_filename, nil, nil, :encoding => Encoding::ISO8859_1)
165
+ assert_equal(Encoding::ISO8859_1, contents.encoding)
166
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\"><m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n".force_encoding(Encoding::ISO8859_1),
167
+ contents)
168
+ else
169
+ contents = File.read(temp_filename)
170
+ assert_equal("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<bands genre=\"metal\"><m\xF6tley_cr\xFCe country=\"us\">M\xF6tley Cr\xFCe is an American heavy metal band formed in Los Angeles, California in 1981.</m\xF6tley_cr\xFCe><iron_maiden country=\"uk\">Iron Maiden is a British heavy metal band formed in 1975.</iron_maiden></bands>\n",
171
+ contents)
172
+ end
173
+ ensure
174
+ File.delete(temp_filename)
175
+ end
176
+
177
+ def test_thread_set_root
178
+ # Previously a segmentation fault occurred when running libxml in
179
+ # background threads.
180
+ thread = Thread.new do
181
+ 100000.times do |i|
182
+ document = LibXML::XML::Document.new
183
+ node = LibXML::XML::Node.new('test')
184
+ document.root = node
185
+ end
186
+ end
187
+ thread.join
188
+ assert(true)
189
+ end
190
+
191
+ # --- Debug ---
192
+ def test_debug
193
+ assert(@doc.debug)
194
+ end
195
+ end