coupa-libxml-ruby 1.1.4

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.
Files changed (280) hide show
  1. data/CHANGES +488 -0
  2. data/LICENSE +22 -0
  3. data/README +161 -0
  4. data/Rakefile +188 -0
  5. data/doc/css/normal.css +182 -0
  6. data/doc/img/raze-tiny.png +0 -0
  7. data/doc/img/red-cube.jpg +0 -0
  8. data/doc/img/xml-ruby.png +0 -0
  9. data/doc/index.xml +43 -0
  10. data/doc/install.xml +77 -0
  11. data/doc/layout.rhtml +38 -0
  12. data/doc/layout.xsl +67 -0
  13. data/doc/license.xml +32 -0
  14. data/doc/log/changelog.xml +1324 -0
  15. data/doc/log/changelog.xsl +42 -0
  16. data/doc/rdoc/classes/LibXML.html +207 -0
  17. data/doc/rdoc/classes/LibXML/XML.html +407 -0
  18. data/doc/rdoc/classes/LibXML/XML/Attr.html +521 -0
  19. data/doc/rdoc/classes/LibXML/XML/AttrDecl.html +360 -0
  20. data/doc/rdoc/classes/LibXML/XML/Attributes.html +149 -0
  21. data/doc/rdoc/classes/LibXML/XML/Document.html +460 -0
  22. data/doc/rdoc/classes/LibXML/XML/Error.html +129 -0
  23. data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +263 -0
  24. data/doc/rdoc/classes/LibXML/XML/Namespace.html +248 -0
  25. data/doc/rdoc/classes/LibXML/XML/Namespaces.html +200 -0
  26. data/doc/rdoc/classes/LibXML/XML/Node.html +1351 -0
  27. data/doc/rdoc/classes/LibXML/XML/Parser.html +328 -0
  28. data/doc/rdoc/classes/LibXML/XML/Reader.html +172 -0
  29. data/doc/rdoc/classes/LibXML/XML/SaxParser.html +232 -0
  30. data/doc/rdoc/classes/LibXML/XML/SaxParser/Callbacks.html +506 -0
  31. data/doc/rdoc/classes/LibXML/XML/SaxParser/VerboseCallbacks.html +555 -0
  32. data/doc/rdoc/classes/LibXML/XML/XPath.html +111 -0
  33. data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +162 -0
  34. data/doc/rdoc/classes/cXMLDtd.html +114 -0
  35. data/doc/rdoc/classes/cXMLNode.html +114 -0
  36. data/doc/rdoc/created.rid +1 -0
  37. data/doc/rdoc/files/CHANGES.html +794 -0
  38. data/doc/rdoc/files/LICENSE.html +131 -0
  39. data/doc/rdoc/files/README.html +343 -0
  40. data/doc/rdoc/files/ext/libxml/libxml_c.html +101 -0
  41. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +101 -0
  42. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_decl_c.html +101 -0
  43. data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +101 -0
  44. data/doc/rdoc/files/ext/libxml/ruby_xml_c.html +101 -0
  45. data/doc/rdoc/files/ext/libxml/ruby_xml_cbg_c.html +101 -0
  46. data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +101 -0
  47. data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +101 -0
  48. data/doc/rdoc/files/ext/libxml/ruby_xml_encoding_c.html +101 -0
  49. data/doc/rdoc/files/ext/libxml/ruby_xml_error_c.html +101 -0
  50. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +101 -0
  51. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_context_c.html +101 -0
  52. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_options_c.html +101 -0
  53. data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +101 -0
  54. data/doc/rdoc/files/ext/libxml/ruby_xml_io_c.html +101 -0
  55. data/doc/rdoc/files/ext/libxml/ruby_xml_namespace_c.html +101 -0
  56. data/doc/rdoc/files/ext/libxml/ruby_xml_namespaces_c.html +101 -0
  57. data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +101 -0
  58. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +101 -0
  59. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +101 -0
  60. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_options_c.html +101 -0
  61. data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +101 -0
  62. data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +101 -0
  63. data/doc/rdoc/files/ext/libxml/ruby_xml_sax2_handler_c.html +101 -0
  64. data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +101 -0
  65. data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +101 -0
  66. data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +101 -0
  67. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +101 -0
  68. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +101 -0
  69. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_expression_c.html +101 -0
  70. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +101 -0
  71. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +101 -0
  72. data/doc/rdoc/files/lib/libxml/attr_decl_rb.html +101 -0
  73. data/doc/rdoc/files/lib/libxml/attr_rb.html +101 -0
  74. data/doc/rdoc/files/lib/libxml/attributes_rb.html +101 -0
  75. data/doc/rdoc/files/lib/libxml/document_rb.html +101 -0
  76. data/doc/rdoc/files/lib/libxml/error_rb.html +101 -0
  77. data/doc/rdoc/files/lib/libxml/hpricot_rb.html +192 -0
  78. data/doc/rdoc/files/lib/libxml/html_parser_rb.html +101 -0
  79. data/doc/rdoc/files/lib/libxml/namespace_rb.html +101 -0
  80. data/doc/rdoc/files/lib/libxml/namespaces_rb.html +101 -0
  81. data/doc/rdoc/files/lib/libxml/node_rb.html +108 -0
  82. data/doc/rdoc/files/lib/libxml/ns_rb.html +101 -0
  83. data/doc/rdoc/files/lib/libxml/parser_rb.html +101 -0
  84. data/doc/rdoc/files/lib/libxml/properties_rb.html +101 -0
  85. data/doc/rdoc/files/lib/libxml/reader_rb.html +101 -0
  86. data/doc/rdoc/files/lib/libxml/sax_callbacks_rb.html +101 -0
  87. data/doc/rdoc/files/lib/libxml/sax_parser_rb.html +101 -0
  88. data/doc/rdoc/files/lib/libxml/tree_rb.html +101 -0
  89. data/doc/rdoc/files/lib/libxml/xpath_object_rb.html +101 -0
  90. data/doc/rdoc/files/lib/libxml_rb.html +133 -0
  91. data/doc/rdoc/files/lib/xml/libxml_rb.html +124 -0
  92. data/doc/rdoc/files/lib/xml_rb.html +134 -0
  93. data/doc/rdoc/fr_class_index.html +46 -0
  94. data/doc/rdoc/fr_file_index.html +84 -0
  95. data/doc/rdoc/fr_method_index.html +155 -0
  96. data/doc/rdoc/index.html +24 -0
  97. data/doc/rdoc/rdoc-style.css +208 -0
  98. data/ext/libxml/Makefile +157 -0
  99. data/ext/libxml/build.log +4 -0
  100. data/ext/libxml/extconf.h +5 -0
  101. data/ext/libxml/extconf.rb +278 -0
  102. data/ext/libxml/libxml.c +77 -0
  103. data/ext/libxml/libxml.o +0 -0
  104. data/ext/libxml/libxml_ruby.bundle +0 -0
  105. data/ext/libxml/mkmf.log +228 -0
  106. data/ext/libxml/ruby_libxml.h +93 -0
  107. data/ext/libxml/ruby_xml.c +893 -0
  108. data/ext/libxml/ruby_xml.h +10 -0
  109. data/ext/libxml/ruby_xml.o +0 -0
  110. data/ext/libxml/ruby_xml_attr.c +352 -0
  111. data/ext/libxml/ruby_xml_attr.h +14 -0
  112. data/ext/libxml/ruby_xml_attr.o +0 -0
  113. data/ext/libxml/ruby_xml_attr_decl.c +171 -0
  114. data/ext/libxml/ruby_xml_attr_decl.h +13 -0
  115. data/ext/libxml/ruby_xml_attr_decl.o +0 -0
  116. data/ext/libxml/ruby_xml_attributes.c +277 -0
  117. data/ext/libxml/ruby_xml_attributes.h +17 -0
  118. data/ext/libxml/ruby_xml_attributes.o +0 -0
  119. data/ext/libxml/ruby_xml_cbg.c +86 -0
  120. data/ext/libxml/ruby_xml_cbg.o +0 -0
  121. data/ext/libxml/ruby_xml_document.c +1006 -0
  122. data/ext/libxml/ruby_xml_document.c.old +936 -0
  123. data/ext/libxml/ruby_xml_document.h +17 -0
  124. data/ext/libxml/ruby_xml_document.o +0 -0
  125. data/ext/libxml/ruby_xml_dtd.c +257 -0
  126. data/ext/libxml/ruby_xml_dtd.h +9 -0
  127. data/ext/libxml/ruby_xml_dtd.o +0 -0
  128. data/ext/libxml/ruby_xml_encoding.c +134 -0
  129. data/ext/libxml/ruby_xml_encoding.h +12 -0
  130. data/ext/libxml/ruby_xml_encoding.o +0 -0
  131. data/ext/libxml/ruby_xml_error.c +1004 -0
  132. data/ext/libxml/ruby_xml_error.h +14 -0
  133. data/ext/libxml/ruby_xml_error.o +0 -0
  134. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  135. data/ext/libxml/ruby_xml_html_parser.h +12 -0
  136. data/ext/libxml/ruby_xml_html_parser.o +0 -0
  137. data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
  138. data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
  139. data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
  140. data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
  141. data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
  142. data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
  143. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  144. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  145. data/ext/libxml/ruby_xml_input_cbg.o +0 -0
  146. data/ext/libxml/ruby_xml_io.c +30 -0
  147. data/ext/libxml/ruby_xml_io.h +9 -0
  148. data/ext/libxml/ruby_xml_io.o +0 -0
  149. data/ext/libxml/ruby_xml_namespace.c +170 -0
  150. data/ext/libxml/ruby_xml_namespace.h +12 -0
  151. data/ext/libxml/ruby_xml_namespace.o +0 -0
  152. data/ext/libxml/ruby_xml_namespaces.c +295 -0
  153. data/ext/libxml/ruby_xml_namespaces.h +11 -0
  154. data/ext/libxml/ruby_xml_namespaces.o +0 -0
  155. data/ext/libxml/ruby_xml_node.c +1386 -0
  156. data/ext/libxml/ruby_xml_node.h +13 -0
  157. data/ext/libxml/ruby_xml_node.o +0 -0
  158. data/ext/libxml/ruby_xml_parser.c +94 -0
  159. data/ext/libxml/ruby_xml_parser.h +14 -0
  160. data/ext/libxml/ruby_xml_parser.o +0 -0
  161. data/ext/libxml/ruby_xml_parser_context.c +982 -0
  162. data/ext/libxml/ruby_xml_parser_context.h +12 -0
  163. data/ext/libxml/ruby_xml_parser_context.o +0 -0
  164. data/ext/libxml/ruby_xml_parser_options.c +68 -0
  165. data/ext/libxml/ruby_xml_parser_options.h +14 -0
  166. data/ext/libxml/ruby_xml_parser_options.o +0 -0
  167. data/ext/libxml/ruby_xml_reader.c +1002 -0
  168. data/ext/libxml/ruby_xml_reader.h +14 -0
  169. data/ext/libxml/ruby_xml_reader.o +0 -0
  170. data/ext/libxml/ruby_xml_relaxng.c +111 -0
  171. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  172. data/ext/libxml/ruby_xml_relaxng.o +0 -0
  173. data/ext/libxml/ruby_xml_sax2_handler.c +322 -0
  174. data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
  175. data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
  176. data/ext/libxml/ruby_xml_sax_parser.c +137 -0
  177. data/ext/libxml/ruby_xml_sax_parser.h +12 -0
  178. data/ext/libxml/ruby_xml_sax_parser.o +0 -0
  179. data/ext/libxml/ruby_xml_schema.c +159 -0
  180. data/ext/libxml/ruby_xml_schema.h +11 -0
  181. data/ext/libxml/ruby_xml_schema.o +0 -0
  182. data/ext/libxml/ruby_xml_version.h +9 -0
  183. data/ext/libxml/ruby_xml_xinclude.c +18 -0
  184. data/ext/libxml/ruby_xml_xinclude.h +13 -0
  185. data/ext/libxml/ruby_xml_xinclude.o +0 -0
  186. data/ext/libxml/ruby_xml_xpath.c +107 -0
  187. data/ext/libxml/ruby_xml_xpath.h +12 -0
  188. data/ext/libxml/ruby_xml_xpath.o +0 -0
  189. data/ext/libxml/ruby_xml_xpath_context.c +387 -0
  190. data/ext/libxml/ruby_xml_xpath_context.h +11 -0
  191. data/ext/libxml/ruby_xml_xpath_context.o +0 -0
  192. data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
  193. data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
  194. data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
  195. data/ext/libxml/ruby_xml_xpath_object.c +336 -0
  196. data/ext/libxml/ruby_xml_xpath_object.h +19 -0
  197. data/ext/libxml/ruby_xml_xpath_object.o +0 -0
  198. data/ext/libxml/ruby_xml_xpointer.c +101 -0
  199. data/ext/libxml/ruby_xml_xpointer.h +13 -0
  200. data/ext/libxml/ruby_xml_xpointer.o +0 -0
  201. data/ext/mingw/Rakefile +34 -0
  202. data/ext/mingw/build.rake +41 -0
  203. data/ext/vc/libxml_ruby.sln +26 -0
  204. data/lib/libxml.rb +30 -0
  205. data/lib/libxml/attr.rb +111 -0
  206. data/lib/libxml/attr_decl.rb +78 -0
  207. data/lib/libxml/attributes.rb +12 -0
  208. data/lib/libxml/document.rb +190 -0
  209. data/lib/libxml/error.rb +88 -0
  210. data/lib/libxml/hpricot.rb +76 -0
  211. data/lib/libxml/html_parser.rb +94 -0
  212. data/lib/libxml/namespace.rb +60 -0
  213. data/lib/libxml/namespaces.rb +36 -0
  214. data/lib/libxml/node.rb +385 -0
  215. data/lib/libxml/ns.rb +20 -0
  216. data/lib/libxml/parser.rb +365 -0
  217. data/lib/libxml/properties.rb +21 -0
  218. data/lib/libxml/reader.rb +27 -0
  219. data/lib/libxml/sax_callbacks.rb +178 -0
  220. data/lib/libxml/sax_parser.rb +56 -0
  221. data/lib/libxml/tree.rb +27 -0
  222. data/lib/libxml/xpath_object.rb +14 -0
  223. data/lib/xml.rb +14 -0
  224. data/lib/xml/libxml.rb +8 -0
  225. data/setup.rb +1585 -0
  226. data/test/etc_doc_to_s.rb +19 -0
  227. data/test/ets_doc_file.rb +15 -0
  228. data/test/ets_doc_to_s.rb +21 -0
  229. data/test/ets_gpx.rb +26 -0
  230. data/test/ets_node_gc.rb +21 -0
  231. data/test/ets_test.xml +2 -0
  232. data/test/ets_tsr.rb +9 -0
  233. data/test/model/atom.xml +13 -0
  234. data/test/model/bands.xml +5 -0
  235. data/test/model/books.xml +146 -0
  236. data/test/model/merge_bug_data.xml +58 -0
  237. data/test/model/ruby-lang.html +238 -0
  238. data/test/model/rubynet.xml +79 -0
  239. data/test/model/rubynet_project +1 -0
  240. data/test/model/shiporder.rnc +28 -0
  241. data/test/model/shiporder.rng +86 -0
  242. data/test/model/shiporder.xml +23 -0
  243. data/test/model/shiporder.xsd +31 -0
  244. data/test/model/soap.xml +27 -0
  245. data/test/model/xinclude.xml +5 -0
  246. data/test/tc_attr.rb +170 -0
  247. data/test/tc_attr_decl.rb +131 -0
  248. data/test/tc_attributes.rb +133 -0
  249. data/test/tc_deprecated_require.rb +11 -0
  250. data/test/tc_document.rb +113 -0
  251. data/test/tc_document_write.rb +118 -0
  252. data/test/tc_dtd.rb +123 -0
  253. data/test/tc_error.rb +136 -0
  254. data/test/tc_html_parser.rb +138 -0
  255. data/test/tc_namespace.rb +59 -0
  256. data/test/tc_namespaces.rb +174 -0
  257. data/test/tc_node.rb +181 -0
  258. data/test/tc_node_cdata.rb +49 -0
  259. data/test/tc_node_comment.rb +30 -0
  260. data/test/tc_node_copy.rb +40 -0
  261. data/test/tc_node_edit.rb +158 -0
  262. data/test/tc_node_text.rb +69 -0
  263. data/test/tc_node_write.rb +83 -0
  264. data/test/tc_node_xlink.rb +26 -0
  265. data/test/tc_parser.rb +330 -0
  266. data/test/tc_parser_context.rb +186 -0
  267. data/test/tc_properties.rb +36 -0
  268. data/test/tc_reader.rb +284 -0
  269. data/test/tc_relaxng.rb +51 -0
  270. data/test/tc_sax_parser.rb +274 -0
  271. data/test/tc_schema.rb +51 -0
  272. data/test/tc_traversal.rb +220 -0
  273. data/test/tc_xinclude.rb +19 -0
  274. data/test/tc_xml.rb +224 -0
  275. data/test/tc_xpath.rb +193 -0
  276. data/test/tc_xpath_context.rb +78 -0
  277. data/test/tc_xpath_expression.rb +35 -0
  278. data/test/tc_xpointer.rb +72 -0
  279. data/test/test_suite.rb +33 -0
  280. metadata +376 -0
@@ -0,0 +1,158 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ class TestNodeEdit < Test::Unit::TestCase
5
+ def setup
6
+ xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
7
+ @doc = xp.parse
8
+ end
9
+
10
+ def teardown
11
+ @doc = nil
12
+ end
13
+
14
+ def first_node
15
+ @doc.root.child
16
+ end
17
+
18
+ def second_node
19
+ first_node.next
20
+ end
21
+
22
+ def third_node
23
+ second_node.next
24
+ end
25
+
26
+ def test_add_next_01
27
+ first_node.next = XML::Node.new('num', 'one-and-a-half')
28
+ assert_equal('<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
29
+ @doc.root.to_s.gsub(/\n\s*/,''))
30
+ end
31
+
32
+ def test_add_next_02
33
+ second_node.next = XML::Node.new('num', 'two-and-a-half')
34
+ assert_equal('<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
35
+ @doc.root.to_s.gsub(/\n\s*/,''))
36
+ end
37
+
38
+ def test_add_next_03
39
+ third_node.next = XML::Node.new('num', 'four')
40
+ assert_equal '<test><num>one</num><num>two</num><num>three</num><num>four</num></test>',
41
+ @doc.root.to_s.gsub(/\n\s*/,'')
42
+ end
43
+
44
+ def test_add_prev_01
45
+ first_node.prev = XML::Node.new('num', 'half')
46
+ assert_equal '<test><num>half</num><num>one</num><num>two</num><num>three</num></test>',
47
+ @doc.root.to_s.gsub(/\n\s*/,'')
48
+ end
49
+
50
+ def test_add_prev_02
51
+ second_node.prev = XML::Node.new('num', 'one-and-a-half')
52
+ assert_equal '<test><num>one</num><num>one-and-a-half</num><num>two</num><num>three</num></test>',
53
+ @doc.root.to_s.gsub(/\n\s*/,'')
54
+ end
55
+
56
+ def test_add_prev_03
57
+ third_node.prev = XML::Node.new('num', 'two-and-a-half')
58
+ assert_equal '<test><num>one</num><num>two</num><num>two-and-a-half</num><num>three</num></test>',
59
+ @doc.root.to_s.gsub(/\n\s*/,'')
60
+ end
61
+
62
+ def test_remove_node
63
+ first_node.remove!
64
+ assert_equal('<test><num>two</num><num>three</num></test>',
65
+ @doc.root.to_s.gsub(/\n\s*/,''))
66
+ end
67
+
68
+ def test_remove_node_gc
69
+ xp = XML::Parser.string('<test><num>one</num><num>two</num><num>three</num></test>')
70
+ doc = xp.parse
71
+ node = doc.root.child.remove!
72
+ node = nil
73
+ GC.start
74
+ assert_not_nil(doc)
75
+ end
76
+
77
+ def test_remove_node_iteration
78
+ nodes = Array.new
79
+ @doc.root.each_element do |node|
80
+ if node.name == 'num'
81
+ nodes << node
82
+ node.remove!
83
+ end
84
+ end
85
+ assert_equal(3, nodes.length)
86
+ end
87
+
88
+ def test_reuse_removed_node
89
+ # Remove the node
90
+ node = @doc.root.first.remove!
91
+ assert_not_nil(node)
92
+
93
+ # Add it to the end of the documnet
94
+ @doc.root.last.next = node
95
+
96
+ assert_equal('<test><num>two</num><num>three</num><num>one</num></test>',
97
+ @doc.root.to_s.gsub(/\n\s*/,''))
98
+ end
99
+
100
+ def test_append_existing_node
101
+ doc = XML::Parser.string('<top>a<bottom>b<one>first</one><two>second</two>c</bottom>d</top>').parse
102
+ node1 = doc.find_first('//two')
103
+
104
+ doc.root << node1
105
+ assert_equal('<top>a<bottom>b<one>first</one>c</bottom>d<two>second</two></top>',
106
+ doc.root.to_s)
107
+ end
108
+
109
+ def test_wrong_doc
110
+ doc1 = XML::Parser.string('<nums><one></one></nums>').parse
111
+ doc2 = XML::Parser.string('<nums><two></two></nums>').parse
112
+
113
+ node = doc1.root.child
114
+
115
+ error = assert_raise(XML::Error) do
116
+ doc2.root << node
117
+ end
118
+
119
+ assert_equal(' Nodes belong to different documents. You must first import the by calling XML::Document.import.',
120
+ error.to_s)
121
+ end
122
+
123
+
124
+ # This test is to verify that an earlier reported bug has been fixed
125
+ def test_merge
126
+ documents = []
127
+
128
+ # Read in 500 documents
129
+ 500.times do
130
+ documents << XML::Parser.string(File.read(File.join(File.dirname(__FILE__), 'model', 'merge_bug_data.xml'))).parse
131
+ end
132
+
133
+ master_doc = documents.shift
134
+ documents.inject(master_doc) do |master_doc, child_doc|
135
+ master_body = master_doc.find("//body").first
136
+ child_body = child_doc.find("//body").first
137
+
138
+ child_element = child_body.detect do |node|
139
+ node.element?
140
+ end
141
+
142
+ master_body << child_element.copy(true)
143
+ master_doc
144
+ end
145
+ end
146
+
147
+ def test_append_chain
148
+ node = XML::Node.new('foo') << XML::Node.new('bar') << "bars contents"
149
+ assert_equal('<foo><bar/>bars contents</foo>',
150
+ node.to_s)
151
+ end
152
+
153
+ def test_set_base
154
+ @doc.root.base_uri = 'http://www.rubynet.org/'
155
+ assert_equal("<test xml:base=\"http://www.rubynet.org/\">\n <num>one</num>\n <num>two</num>\n <num>three</num>\n</test>",
156
+ @doc.root.to_s)
157
+ end
158
+ end
@@ -0,0 +1,69 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ class TestTextNode < Test::Unit::TestCase
5
+ def test_content
6
+ node = XML::Node.new_text('testdata')
7
+ assert_instance_of(XML::Node, node)
8
+ assert_equal('testdata', node.content)
9
+ end
10
+
11
+ def test_invalid_content
12
+ error = assert_raise(TypeError) do
13
+ node = XML::Node.new_text(nil)
14
+ end
15
+ assert_equal('wrong argument type nil (expected String)', error.to_s)
16
+ end
17
+
18
+ # We use the same facility that libXSLT does here to disable output escaping.
19
+ # This lets you specify that the node's content should be rendered unaltered
20
+ # whenever it is being output. This is useful for things like <script> and
21
+ # <style> nodes in HTML documents if you don't want to be forced to wrap them
22
+ # in CDATA nodes. Or if you are sanitizing existing HTML documents and want
23
+ # to preserve the content of any of the text nodes.
24
+ #
25
+ def test_output_escaping
26
+ textnoenc = 'if (a < b || c > d) return "e";'
27
+ text = "if (a &lt; b || c &gt; d) return \"e\";"
28
+
29
+ node = XML::Node.new_text(textnoenc)
30
+ assert node.output_escaping?
31
+ assert_equal text, node.to_s
32
+
33
+ node.output_escaping = false
34
+ assert_equal textnoenc, node.to_s
35
+
36
+ node.output_escaping = true
37
+ assert_equal text, node.to_s
38
+
39
+ node.output_escaping = nil
40
+ assert_equal textnoenc, node.to_s
41
+
42
+ node.output_escaping = true
43
+ assert_equal text, node.to_s
44
+ end
45
+
46
+ # Just a sanity check for output escaping.
47
+ def test_output_escaping_sanity
48
+ node = XML::Node.new_text('testdata')
49
+ assert_equal 'text', node.name
50
+ assert node.output_escaping?
51
+
52
+ node.output_escaping = false
53
+ assert_equal 'textnoenc', node.name
54
+ assert ! node.output_escaping?
55
+
56
+ node.output_escaping = true
57
+ assert_equal 'text', node.name
58
+ assert node.output_escaping?
59
+
60
+ node.output_escaping = nil
61
+ assert_equal 'textnoenc', node.name
62
+ assert ! node.output_escaping?
63
+
64
+ node.output_escaping = true
65
+ assert_equal 'text', node.name
66
+ assert node.output_escaping?
67
+ end
68
+
69
+ end
@@ -0,0 +1,83 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+
4
+ class TestNodeWrite < Test::Unit::TestCase
5
+ def setup
6
+ # Strip spaces to make testing easier
7
+ XML.default_keep_blanks = false
8
+ file = File.join(File.dirname(__FILE__), 'model/bands.xml')
9
+ @doc = XML::Document.file(file)
10
+ end
11
+
12
+ def teardown
13
+ XML.default_keep_blanks = true
14
+ @doc = nil
15
+ end
16
+
17
+ def test_to_s_default
18
+ # Default to_s has indentation
19
+ node = @doc.root
20
+ assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
21
+ node.to_s)
22
+ end
23
+
24
+ def test_to_s_no_global_indentation
25
+ # No indentation due to global setting
26
+ node = @doc.root
27
+ XML.indent_tree_output = false
28
+ assert_equal("<bands genre=\"metal\">\n<m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n<iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
29
+ node.to_s)
30
+ ensure
31
+ XML.indent_tree_output = true
32
+ end
33
+
34
+ def test_to_s_no_indentation
35
+ # No indentation due to local setting
36
+ node = @doc.root
37
+ assert_equal("<bands genre=\"metal\"><m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden></bands>",
38
+ node.to_s(:indent => false))
39
+ end
40
+
41
+ def test_to_s_level
42
+ # No indentation due to local setting
43
+ node = @doc.root
44
+ assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n </bands>",
45
+ node.to_s(:level => 1))
46
+ end
47
+
48
+ def test_to_s_encoding
49
+ # Test encodings
50
+ node = @doc.root
51
+
52
+ # UTF8:
53
+ # ö - c3 b6 in hex, \303\266 in octal
54
+ # ü - c3 bc in hex, \303\274 in octal
55
+ assert_equal("<bands genre=\"metal\">\n <m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
56
+ node.to_s(:encoding => XML::Encoding::UTF_8))
57
+
58
+ # ISO_8859_1:
59
+ # ö - f6 in hex, \366 in octal
60
+ # ü - fc in hex, \374 in octal
61
+ assert_equal("<bands genre=\"metal\">\n <m\366tley_cr\374e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\366tley_cr\374e>\n <iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>\n</bands>",
62
+ node.to_s(:encoding => XML::Encoding::ISO_8859_1))
63
+
64
+
65
+ # Invalid encoding
66
+ error = assert_raise(ArgumentError) do
67
+ node.to_s(:encoding => -9999)
68
+ end
69
+ assert_equal('Unknown encoding value: -9999', error.to_s)
70
+ end
71
+
72
+ def test_inner_xml
73
+ # Default to_s has indentation
74
+ node = @doc.root
75
+ assert_equal("<m\303\266tley_cr\303\274e country=\"us\">An American heavy metal band formed in Los Angeles, California in 1981.</m\303\266tley_cr\303\274e><iron_maiden country=\"uk\">British heavy metal band formed in 1975.</iron_maiden>",
76
+ node.inner_xml)
77
+ end
78
+
79
+ # --- Debug ---
80
+ def test_debug
81
+ assert(@doc.root.debug)
82
+ end
83
+ end
@@ -0,0 +1,26 @@
1
+ # $Id: tc_node_xlink.rb 710 2009-01-20 05:30:51Z cfis $
2
+ require "xml"
3
+ require 'test/unit'
4
+
5
+ class TC_XML_Node_XLink < Test::Unit::TestCase
6
+ def setup()
7
+ xp = XML::Parser.string('<ruby_array xmlns:xlink="http://www.w3.org/1999/xlink/namespace/"><fixnum xlink:type="simple">one</fixnum></ruby_array>')
8
+ doc = xp.parse
9
+ assert_instance_of(XML::Document, doc)
10
+ @root = doc.root
11
+ assert_instance_of(XML::Node, @root)
12
+ end
13
+
14
+ def teardown()
15
+ @root = nil
16
+ end
17
+
18
+ def test_xml_node_xlink()
19
+ for elem in @root.find('fixnum')
20
+ assert_instance_of(XML::Node, elem)
21
+ assert_instance_of(TrueClass, elem.xlink?)
22
+ assert_equal("simple", elem.xlink_type_name)
23
+ assert_equal(XML::Node::XLINK_TYPE_SIMPLE, elem.xlink_type)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,330 @@
1
+ require 'xml'
2
+ require 'test/unit'
3
+ require 'stringio'
4
+
5
+ class TestParser < Test::Unit::TestCase
6
+ def setup
7
+ XML::Error.set_handler(&XML::Error::QUIET_HANDLER)
8
+ end
9
+
10
+ def teardown
11
+ GC.start
12
+ GC.start
13
+ GC.start
14
+ end
15
+
16
+ # ----- Sources ------
17
+ def test_document
18
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
19
+ parser = XML::Parser.file(file)
20
+ doc = parser.parse
21
+
22
+ parser = XML::Parser.document(doc)
23
+
24
+ doc = parser.parse
25
+
26
+ assert_instance_of(XML::Document, doc)
27
+ assert_instance_of(XML::Parser::Context, parser.context)
28
+ end
29
+
30
+ def test_nil_document
31
+ error = assert_raise(TypeError) do
32
+ XML::Parser.document(nil)
33
+ end
34
+
35
+ assert_equal("Must pass an XML::Document object", error.to_s)
36
+ end
37
+
38
+ def test_file
39
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
40
+
41
+ parser = XML::Parser.file(file)
42
+ doc = parser.parse
43
+ assert_instance_of(XML::Document, doc)
44
+ assert_instance_of(XML::Parser::Context, parser.context)
45
+ end
46
+
47
+ def test_noexistent_file
48
+ error = assert_raise(XML::Error) do
49
+ XML::Parser.file('i_dont_exist.xml')
50
+ end
51
+
52
+ assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
53
+ end
54
+
55
+ def test_nil_file
56
+ error = assert_raise(TypeError) do
57
+ XML::Parser.file(nil)
58
+ end
59
+
60
+ assert_equal("can't convert nil into String", error.to_s)
61
+ end
62
+
63
+ def test_file_encoding
64
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
65
+ parser = XML::Parser.file(file, :encoding => XML::Encoding::ISO_8859_1)
66
+
67
+ error = assert_raise(XML::Error) do
68
+ doc = parser.parse
69
+ end
70
+
71
+ assert(error.to_s.match(/Fatal error: Extra content at the end of the document/))
72
+
73
+ parser = XML::Parser.file(file, :encoding => XML::Encoding::UTF_8)
74
+ doc = parser.parse
75
+ assert_not_nil(doc)
76
+ end
77
+
78
+ def test_file_base_uri
79
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
80
+
81
+ parser = XML::Parser.file(file)
82
+ doc = parser.parse
83
+ assert(doc.child.base.match(/test\/model\/bands.xml/))
84
+
85
+ parser = XML::Parser.file(file, :base_uri => "http://libxml.org")
86
+ doc = parser.parse
87
+ assert(doc.child.base.match(/test\/model\/bands.xml/))
88
+ end
89
+
90
+ def test_io
91
+ File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
92
+ parser = XML::Parser.io(io)
93
+ assert_instance_of(XML::Parser, parser)
94
+
95
+ doc = parser.parse
96
+ assert_instance_of(XML::Document, doc)
97
+ assert_instance_of(XML::Parser::Context, parser.context)
98
+ end
99
+ end
100
+
101
+ def test_io_gc
102
+ # Test that the reader keeps a reference
103
+ # to the io object
104
+ file = File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
105
+ parser = XML::Parser.io(file)
106
+ file = nil
107
+ GC.start
108
+ assert(parser.parse)
109
+ end
110
+
111
+ def test_nil_io
112
+ error = assert_raise(TypeError) do
113
+ XML::Parser.io(nil)
114
+ end
115
+
116
+ assert_equal("Must pass in an IO object", error.to_s)
117
+ end
118
+
119
+ def test_string_io
120
+ data = File.read(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
121
+ string_io = StringIO.new(data)
122
+ parser = XML::Parser.io(string_io)
123
+
124
+ doc = parser.parse
125
+ assert_instance_of(XML::Document, doc)
126
+ assert_instance_of(XML::Parser::Context, parser.context)
127
+ end
128
+
129
+ def test_string
130
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
131
+
132
+ parser = XML::Parser.string(str)
133
+ assert_instance_of(XML::Parser, parser)
134
+
135
+ doc = parser.parse
136
+ assert_instance_of(XML::Document, doc)
137
+ assert_instance_of(XML::Parser::Context, parser.context)
138
+ end
139
+
140
+ def test_nil_string
141
+ error = assert_raise(TypeError) do
142
+ XML::Parser.string(nil)
143
+ end
144
+
145
+ assert_equal("wrong argument type nil (expected String)", error.to_s)
146
+ end
147
+
148
+ def test_string_options
149
+ xml = <<-EOS
150
+ <!DOCTYPE foo [<!ENTITY foo 'bar'>]>
151
+ <test>
152
+ <cdata><![CDATA[something]]></cdata>
153
+ <entity>&foo;</entity>
154
+ </test>
155
+ EOS
156
+
157
+ XML::default_substitute_entities = false
158
+
159
+ # Parse normally
160
+ parser = XML::Parser.string(xml)
161
+ doc = parser.parse
162
+ assert_nil(doc.child.base)
163
+
164
+ # Cdata section should be cdata nodes
165
+ node = doc.find_first('/test/cdata').child
166
+ assert_equal(XML::Node::CDATA_SECTION_NODE, node.node_type)
167
+
168
+ # Entities should not be subtituted
169
+ node = doc.find_first('/test/entity')
170
+ assert_equal('&foo;', node.child.to_s)
171
+
172
+ # Parse with options
173
+ parser = XML::Parser.string(xml, :base_uri => 'http://libxml.rubyforge.org',
174
+ :options => XML::Parser::Options::NOCDATA | XML::Parser::Options::NOENT)
175
+ doc = parser.parse
176
+ assert_equal(doc.child.base_uri, 'http://libxml.rubyforge.org')
177
+
178
+ # Cdata section should be text nodes
179
+ node = doc.find_first('/test/cdata').child
180
+ assert_equal(XML::Node::TEXT_NODE, node.node_type)
181
+
182
+ # Entities should be subtituted
183
+ node = doc.find_first('/test/entity')
184
+ assert_equal('bar', node.child.to_s)
185
+ end
186
+
187
+ def test_string_encoding
188
+ # ISO_8859_1:
189
+ # ö - f6 in hex, \366 in octal
190
+ # ü - fc in hex, \374 in octal
191
+
192
+ xml = <<-EOS
193
+ <bands>
194
+ <metal>m\366tley_cr\374e</metal>
195
+ </bands>
196
+ EOS
197
+
198
+ # Parse as UTF_8
199
+ parser = XML::Parser.string(xml)
200
+
201
+ error = assert_raise(XML::Error) do
202
+ doc = parser.parse
203
+ end
204
+
205
+ assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
206
+ error.to_s)
207
+
208
+ # Parse as ISO_8859_1:
209
+ parser = XML::Parser.string(xml, :encoding => XML::Encoding::ISO_8859_1)
210
+ doc = parser.parse
211
+ node = doc.find_first('//metal')
212
+ assert_equal("m\303\266tley_cr\303\274e", node.content)
213
+ end
214
+
215
+
216
+ def test_fd_gc
217
+ # Test opening # of documents up to the file limit for the OS.
218
+ # Ideally it should run until libxml emits a warning,
219
+ # thereby knowing we've done a GC sweep. For the time being,
220
+ # re-open the same doc `limit descriptors` times.
221
+ # If we make it to the end, then we've succeeded,
222
+ # otherwise an exception will be thrown.
223
+ XML::Error.set_handler {|error|}
224
+
225
+ max_fd = if RUBY_PLATFORM.match(/mswin32/i)
226
+ 500
227
+ else
228
+ (`ulimit -n`.chomp.to_i) + 1
229
+ end
230
+
231
+ file = File.join(File.dirname(__FILE__), 'model/rubynet.xml')
232
+ max_fd.times do
233
+ XML::Parser.file(file).parse
234
+ end
235
+ XML::Error.reset_handler {|error|}
236
+ end
237
+
238
+
239
+ # ----- Errors ------
240
+ def test_error
241
+ error = assert_raise(XML::Error) do
242
+ XML::Parser.string('<foo><bar/></foz>').parse
243
+ end
244
+
245
+ assert_not_nil(error)
246
+ assert_kind_of(XML::Error, error)
247
+ assert_equal("Fatal error: Opening and ending tag mismatch: foo line 1 and foz at :1.", error.message)
248
+ assert_equal(XML::Error::PARSER, error.domain)
249
+ assert_equal(XML::Error::TAG_NAME_MISMATCH, error.code)
250
+ assert_equal(XML::Error::FATAL, error.level)
251
+ assert_nil(error.file)
252
+ assert_equal(1, error.line)
253
+ assert_equal('foo', error.str1)
254
+ assert_equal('foz', error.str2)
255
+ assert_nil(error.str3)
256
+ assert_equal(1, error.int1)
257
+ assert_equal(20, error.int2)
258
+ assert_nil(error.node)
259
+ end
260
+
261
+ def test_bad_xml
262
+ parser = XML::Parser.string('<ruby_array uga="booga" foo="bar"<fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>')
263
+ error = assert_raise(XML::Error) do
264
+ assert_not_nil(parser.parse)
265
+ end
266
+
267
+ assert_not_nil(error)
268
+ assert_kind_of(XML::Error, error)
269
+ assert_equal("Fatal error: Extra content at the end of the document at :1.", error.message)
270
+ assert_equal(XML::Error::PARSER, error.domain)
271
+ assert_equal(XML::Error::DOCUMENT_END, error.code)
272
+ assert_equal(XML::Error::FATAL, error.level)
273
+ assert_nil(error.file)
274
+ assert_equal(1, error.line)
275
+ assert_nil(error.str1)
276
+ assert_nil(error.str2)
277
+ assert_nil(error.str3)
278
+ assert_equal(0, error.int1)
279
+ assert_equal(20, error.int2)
280
+ assert_nil(error.node)
281
+ end
282
+
283
+ # Deprecated methods
284
+ def test_document_deprecated
285
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/bands.xml'))
286
+ parser = XML::Parser.file(file)
287
+ doc = parser.parse
288
+
289
+ parser = XML::Parser.new
290
+ parser.document = doc
291
+ doc = parser.parse
292
+
293
+ assert_instance_of(XML::Document, doc)
294
+ assert_instance_of(XML::Parser::Context, parser.context)
295
+ end
296
+
297
+ def test_file_deprecated
298
+ file = File.expand_path(File.join(File.dirname(__FILE__), 'model/rubynet.xml'))
299
+
300
+ parser = XML::Parser.new
301
+ parser.file = file
302
+ doc = parser.parse
303
+ assert_instance_of(XML::Document, doc)
304
+ assert_instance_of(XML::Parser::Context, parser.context)
305
+ end
306
+
307
+ def test_io_deprecated
308
+ File.open(File.join(File.dirname(__FILE__), 'model/rubynet.xml')) do |io|
309
+ parser = XML::Parser.new
310
+ assert_instance_of(XML::Parser, parser)
311
+ parser.io = io
312
+
313
+ doc = parser.parse
314
+ assert_instance_of(XML::Document, doc)
315
+ assert_instance_of(XML::Parser::Context, parser.context)
316
+ end
317
+ end
318
+
319
+ def test_string_deprecated
320
+ str = '<ruby_array uga="booga" foo="bar"><fixnum>one</fixnum><fixnum>two</fixnum></ruby_array>'
321
+
322
+ parser = XML::Parser.new
323
+ parser.string = str
324
+ assert_instance_of(XML::Parser, parser)
325
+
326
+ doc = parser.parse
327
+ assert_instance_of(XML::Document, doc)
328
+ assert_instance_of(XML::Parser::Context, parser.context)
329
+ end
330
+ end