nokogiri 1.6.0 → 1.13.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (340) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -19
  3. data/LICENSE-DEPENDENCIES.md +1903 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +280 -0
  6. data/bin/nokogiri +84 -31
  7. data/dependencies.yml +23 -4
  8. data/ext/nokogiri/depend +38 -358
  9. data/ext/nokogiri/extconf.rb +952 -132
  10. data/ext/nokogiri/gumbo.c +584 -0
  11. data/ext/nokogiri/html4_document.c +166 -0
  12. data/ext/nokogiri/html4_element_description.c +294 -0
  13. data/ext/nokogiri/html4_entity_lookup.c +37 -0
  14. data/ext/nokogiri/html4_sax_parser_context.c +120 -0
  15. data/ext/nokogiri/html4_sax_push_parser.c +95 -0
  16. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  17. data/ext/nokogiri/nokogiri.c +231 -96
  18. data/ext/nokogiri/nokogiri.h +188 -129
  19. data/ext/nokogiri/test_global_handlers.c +40 -0
  20. data/ext/nokogiri/xml_attr.c +49 -40
  21. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  22. data/ext/nokogiri/xml_cdata.c +24 -23
  23. data/ext/nokogiri/xml_comment.c +29 -21
  24. data/ext/nokogiri/xml_document.c +327 -223
  25. data/ext/nokogiri/xml_document_fragment.c +12 -16
  26. data/ext/nokogiri/xml_dtd.c +56 -50
  27. data/ext/nokogiri/xml_element_content.c +31 -26
  28. data/ext/nokogiri/xml_element_decl.c +22 -22
  29. data/ext/nokogiri/xml_encoding_handler.c +45 -20
  30. data/ext/nokogiri/xml_entity_decl.c +32 -30
  31. data/ext/nokogiri/xml_entity_reference.c +16 -18
  32. data/ext/nokogiri/xml_namespace.c +74 -32
  33. data/ext/nokogiri/xml_node.c +1290 -680
  34. data/ext/nokogiri/xml_node_set.c +239 -208
  35. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  36. data/ext/nokogiri/xml_reader.c +227 -189
  37. data/ext/nokogiri/xml_relax_ng.c +52 -28
  38. data/ext/nokogiri/xml_sax_parser.c +123 -125
  39. data/ext/nokogiri/xml_sax_parser_context.c +138 -79
  40. data/ext/nokogiri/xml_sax_push_parser.c +88 -35
  41. data/ext/nokogiri/xml_schema.c +112 -33
  42. data/ext/nokogiri/xml_syntax_error.c +50 -23
  43. data/ext/nokogiri/xml_text.c +14 -18
  44. data/ext/nokogiri/xml_xpath_context.c +227 -140
  45. data/ext/nokogiri/xslt_stylesheet.c +269 -177
  46. data/gumbo-parser/CHANGES.md +63 -0
  47. data/gumbo-parser/Makefile +101 -0
  48. data/gumbo-parser/THANKS +27 -0
  49. data/gumbo-parser/src/Makefile +34 -0
  50. data/gumbo-parser/src/README.md +41 -0
  51. data/gumbo-parser/src/ascii.c +75 -0
  52. data/gumbo-parser/src/ascii.h +115 -0
  53. data/gumbo-parser/src/attribute.c +42 -0
  54. data/gumbo-parser/src/attribute.h +17 -0
  55. data/gumbo-parser/src/char_ref.c +22225 -0
  56. data/gumbo-parser/src/char_ref.h +29 -0
  57. data/gumbo-parser/src/char_ref.rl +2154 -0
  58. data/gumbo-parser/src/error.c +626 -0
  59. data/gumbo-parser/src/error.h +148 -0
  60. data/gumbo-parser/src/foreign_attrs.c +104 -0
  61. data/gumbo-parser/src/foreign_attrs.gperf +27 -0
  62. data/gumbo-parser/src/gumbo.h +943 -0
  63. data/gumbo-parser/src/insertion_mode.h +33 -0
  64. data/gumbo-parser/src/macros.h +91 -0
  65. data/gumbo-parser/src/parser.c +4875 -0
  66. data/gumbo-parser/src/parser.h +41 -0
  67. data/gumbo-parser/src/replacement.h +33 -0
  68. data/gumbo-parser/src/string_buffer.c +103 -0
  69. data/gumbo-parser/src/string_buffer.h +68 -0
  70. data/gumbo-parser/src/string_piece.c +48 -0
  71. data/gumbo-parser/src/svg_attrs.c +174 -0
  72. data/gumbo-parser/src/svg_attrs.gperf +77 -0
  73. data/gumbo-parser/src/svg_tags.c +137 -0
  74. data/gumbo-parser/src/svg_tags.gperf +55 -0
  75. data/gumbo-parser/src/tag.c +222 -0
  76. data/gumbo-parser/src/tag_lookup.c +382 -0
  77. data/gumbo-parser/src/tag_lookup.gperf +169 -0
  78. data/gumbo-parser/src/tag_lookup.h +13 -0
  79. data/gumbo-parser/src/token_buffer.c +79 -0
  80. data/gumbo-parser/src/token_buffer.h +71 -0
  81. data/gumbo-parser/src/token_type.h +17 -0
  82. data/gumbo-parser/src/tokenizer.c +3463 -0
  83. data/gumbo-parser/src/tokenizer.h +112 -0
  84. data/gumbo-parser/src/tokenizer_states.h +339 -0
  85. data/gumbo-parser/src/utf8.c +245 -0
  86. data/gumbo-parser/src/utf8.h +164 -0
  87. data/gumbo-parser/src/util.c +68 -0
  88. data/gumbo-parser/src/util.h +30 -0
  89. data/gumbo-parser/src/vector.c +111 -0
  90. data/gumbo-parser/src/vector.h +45 -0
  91. data/lib/nokogiri/class_resolver.rb +67 -0
  92. data/lib/nokogiri/css/node.rb +10 -58
  93. data/lib/nokogiri/css/parser.rb +407 -357
  94. data/lib/nokogiri/css/parser.y +265 -246
  95. data/lib/nokogiri/css/parser_extras.rb +52 -49
  96. data/lib/nokogiri/css/syntax_error.rb +3 -1
  97. data/lib/nokogiri/css/tokenizer.rb +107 -104
  98. data/lib/nokogiri/css/tokenizer.rex +8 -7
  99. data/lib/nokogiri/css/xpath_visitor.rb +266 -80
  100. data/lib/nokogiri/css.rb +50 -17
  101. data/lib/nokogiri/decorators/slop.rb +17 -8
  102. data/lib/nokogiri/extension.rb +31 -0
  103. data/lib/nokogiri/gumbo.rb +15 -0
  104. data/lib/nokogiri/html.rb +38 -27
  105. data/lib/nokogiri/{html → html4}/builder.rb +4 -2
  106. data/lib/nokogiri/html4/document.rb +331 -0
  107. data/lib/nokogiri/html4/document_fragment.rb +54 -0
  108. data/lib/nokogiri/{html → html4}/element_description.rb +3 -1
  109. data/lib/nokogiri/html4/element_description_defaults.rb +578 -0
  110. data/lib/nokogiri/{html → html4}/entity_lookup.rb +4 -2
  111. data/lib/nokogiri/{html → html4}/sax/parser.rb +24 -15
  112. data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
  113. data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
  114. data/lib/nokogiri/html4.rb +46 -0
  115. data/lib/nokogiri/html5/document.rb +88 -0
  116. data/lib/nokogiri/html5/document_fragment.rb +83 -0
  117. data/lib/nokogiri/html5/node.rb +96 -0
  118. data/lib/nokogiri/html5.rb +477 -0
  119. data/lib/nokogiri/jruby/dependencies.rb +21 -0
  120. data/lib/nokogiri/syntax_error.rb +2 -0
  121. data/lib/nokogiri/version/constant.rb +6 -0
  122. data/lib/nokogiri/version/info.rb +221 -0
  123. data/lib/nokogiri/version.rb +3 -105
  124. data/lib/nokogiri/xml/attr.rb +6 -3
  125. data/lib/nokogiri/xml/attribute_decl.rb +3 -1
  126. data/lib/nokogiri/xml/builder.rb +96 -54
  127. data/lib/nokogiri/xml/cdata.rb +3 -1
  128. data/lib/nokogiri/xml/character_data.rb +2 -0
  129. data/lib/nokogiri/xml/document.rb +234 -95
  130. data/lib/nokogiri/xml/document_fragment.rb +86 -36
  131. data/lib/nokogiri/xml/dtd.rb +16 -4
  132. data/lib/nokogiri/xml/element_content.rb +2 -0
  133. data/lib/nokogiri/xml/element_decl.rb +3 -1
  134. data/lib/nokogiri/xml/entity_decl.rb +4 -2
  135. data/lib/nokogiri/xml/entity_reference.rb +20 -0
  136. data/lib/nokogiri/xml/namespace.rb +3 -0
  137. data/lib/nokogiri/xml/node/save_options.rb +8 -4
  138. data/lib/nokogiri/xml/node.rb +947 -502
  139. data/lib/nokogiri/xml/node_set.rb +168 -159
  140. data/lib/nokogiri/xml/notation.rb +13 -0
  141. data/lib/nokogiri/xml/parse_options.rb +40 -5
  142. data/lib/nokogiri/xml/pp/character_data.rb +9 -6
  143. data/lib/nokogiri/xml/pp/node.rb +25 -26
  144. data/lib/nokogiri/xml/pp.rb +4 -2
  145. data/lib/nokogiri/xml/processing_instruction.rb +3 -1
  146. data/lib/nokogiri/xml/reader.rb +23 -28
  147. data/lib/nokogiri/xml/relax_ng.rb +8 -2
  148. data/lib/nokogiri/xml/sax/document.rb +45 -49
  149. data/lib/nokogiri/xml/sax/parser.rb +43 -41
  150. data/lib/nokogiri/xml/sax/parser_context.rb +8 -3
  151. data/lib/nokogiri/xml/sax/push_parser.rb +6 -5
  152. data/lib/nokogiri/xml/sax.rb +6 -4
  153. data/lib/nokogiri/xml/schema.rb +19 -9
  154. data/lib/nokogiri/xml/searchable.rb +270 -0
  155. data/lib/nokogiri/xml/syntax_error.rb +25 -1
  156. data/lib/nokogiri/xml/text.rb +2 -0
  157. data/lib/nokogiri/xml/xpath/syntax_error.rb +4 -2
  158. data/lib/nokogiri/xml/xpath.rb +15 -4
  159. data/lib/nokogiri/xml/xpath_context.rb +3 -3
  160. data/lib/nokogiri/xml.rb +38 -36
  161. data/lib/nokogiri/xslt/stylesheet.rb +3 -1
  162. data/lib/nokogiri/xslt.rb +29 -20
  163. data/lib/nokogiri.rb +69 -69
  164. data/lib/xsd/xmlparser/nokogiri.rb +26 -24
  165. data/patches/libxml2/0001-Remove-script-macro-support.patch +40 -0
  166. data/patches/libxml2/0002-Update-entities-to-remove-handling-of-ssi.patch +44 -0
  167. data/patches/libxml2/0003-libxml2.la-is-in-top_builddir.patch +25 -0
  168. data/patches/libxml2/0004-use-glibc-strlen.patch +53 -0
  169. data/patches/libxml2/0005-avoid-isnan-isinf.patch +81 -0
  170. data/patches/libxml2/0006-update-automake-files-for-arm64.patch +3040 -0
  171. data/patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch +61 -0
  172. data/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
  173. data/patches/libxslt/0001-update-automake-files-for-arm64.patch +3037 -0
  174. data/ports/archives/libxml2-2.9.13.tar.xz +0 -0
  175. data/ports/archives/libxslt-1.1.35.tar.xz +0 -0
  176. metadata +278 -362
  177. data/.autotest +0 -26
  178. data/.gemtest +0 -0
  179. data/.travis.yml +0 -27
  180. data/CHANGELOG.ja.rdoc +0 -819
  181. data/CHANGELOG.rdoc +0 -819
  182. data/C_CODING_STYLE.rdoc +0 -33
  183. data/Manifest.txt +0 -315
  184. data/README.ja.rdoc +0 -106
  185. data/README.rdoc +0 -175
  186. data/ROADMAP.md +0 -90
  187. data/Rakefile +0 -246
  188. data/STANDARD_RESPONSES.md +0 -47
  189. data/Y_U_NO_GEMSPEC.md +0 -155
  190. data/build_all +0 -105
  191. data/ext/nokogiri/html_document.c +0 -170
  192. data/ext/nokogiri/html_document.h +0 -10
  193. data/ext/nokogiri/html_element_description.c +0 -279
  194. data/ext/nokogiri/html_element_description.h +0 -10
  195. data/ext/nokogiri/html_entity_lookup.c +0 -32
  196. data/ext/nokogiri/html_entity_lookup.h +0 -8
  197. data/ext/nokogiri/html_sax_parser_context.c +0 -116
  198. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  199. data/ext/nokogiri/html_sax_push_parser.c +0 -87
  200. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  201. data/ext/nokogiri/xml_attr.h +0 -9
  202. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  203. data/ext/nokogiri/xml_cdata.h +0 -9
  204. data/ext/nokogiri/xml_comment.h +0 -9
  205. data/ext/nokogiri/xml_document.h +0 -23
  206. data/ext/nokogiri/xml_document_fragment.h +0 -10
  207. data/ext/nokogiri/xml_dtd.h +0 -10
  208. data/ext/nokogiri/xml_element_content.h +0 -10
  209. data/ext/nokogiri/xml_element_decl.h +0 -9
  210. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  211. data/ext/nokogiri/xml_entity_decl.h +0 -10
  212. data/ext/nokogiri/xml_entity_reference.h +0 -9
  213. data/ext/nokogiri/xml_io.c +0 -56
  214. data/ext/nokogiri/xml_io.h +0 -11
  215. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  216. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  217. data/ext/nokogiri/xml_namespace.h +0 -13
  218. data/ext/nokogiri/xml_node.h +0 -13
  219. data/ext/nokogiri/xml_node_set.h +0 -14
  220. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  221. data/ext/nokogiri/xml_reader.h +0 -10
  222. data/ext/nokogiri/xml_relax_ng.h +0 -9
  223. data/ext/nokogiri/xml_sax_parser.h +0 -39
  224. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  225. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  226. data/ext/nokogiri/xml_schema.h +0 -9
  227. data/ext/nokogiri/xml_syntax_error.h +0 -13
  228. data/ext/nokogiri/xml_text.h +0 -9
  229. data/ext/nokogiri/xml_xpath_context.h +0 -10
  230. data/ext/nokogiri/xslt_stylesheet.h +0 -14
  231. data/lib/nokogiri/html/document.rb +0 -254
  232. data/lib/nokogiri/html/document_fragment.rb +0 -41
  233. data/lib/nokogiri/html/element_description_defaults.rb +0 -671
  234. data/lib/nokogiri/html/sax/parser_context.rb +0 -16
  235. data/lib/nokogiri/html/sax/push_parser.rb +0 -16
  236. data/ports/archives/libxml2-2.8.0.tar.gz +0 -0
  237. data/ports/archives/libxslt-1.1.26.tar.gz +0 -0
  238. data/tasks/cross_compile.rb +0 -132
  239. data/tasks/nokogiri.org.rb +0 -24
  240. data/tasks/test.rb +0 -95
  241. data/test/css/test_nthiness.rb +0 -159
  242. data/test/css/test_parser.rb +0 -341
  243. data/test/css/test_tokenizer.rb +0 -198
  244. data/test/css/test_xpath_visitor.rb +0 -91
  245. data/test/decorators/test_slop.rb +0 -16
  246. data/test/files/2ch.html +0 -108
  247. data/test/files/address_book.rlx +0 -12
  248. data/test/files/address_book.xml +0 -10
  249. data/test/files/bar/bar.xsd +0 -4
  250. data/test/files/bogus.xml +0 -0
  251. data/test/files/dont_hurt_em_why.xml +0 -422
  252. data/test/files/encoding.html +0 -82
  253. data/test/files/encoding.xhtml +0 -84
  254. data/test/files/exslt.xml +0 -8
  255. data/test/files/exslt.xslt +0 -35
  256. data/test/files/foo/foo.xsd +0 -4
  257. data/test/files/metacharset.html +0 -10
  258. data/test/files/noencoding.html +0 -47
  259. data/test/files/po.xml +0 -32
  260. data/test/files/po.xsd +0 -66
  261. data/test/files/saml/saml20assertion_schema.xsd +0 -283
  262. data/test/files/saml/saml20protocol_schema.xsd +0 -302
  263. data/test/files/saml/xenc_schema.xsd +0 -146
  264. data/test/files/saml/xmldsig_schema.xsd +0 -318
  265. data/test/files/shift_jis.html +0 -10
  266. data/test/files/shift_jis.xml +0 -5
  267. data/test/files/snuggles.xml +0 -3
  268. data/test/files/staff.dtd +0 -10
  269. data/test/files/staff.xml +0 -59
  270. data/test/files/staff.xslt +0 -32
  271. data/test/files/test_document_url/bar.xml +0 -2
  272. data/test/files/test_document_url/document.dtd +0 -4
  273. data/test/files/test_document_url/document.xml +0 -6
  274. data/test/files/tlm.html +0 -850
  275. data/test/files/to_be_xincluded.xml +0 -2
  276. data/test/files/valid_bar.xml +0 -2
  277. data/test/files/xinclude.xml +0 -4
  278. data/test/helper.rb +0 -154
  279. data/test/html/sax/test_parser.rb +0 -141
  280. data/test/html/sax/test_parser_context.rb +0 -46
  281. data/test/html/test_builder.rb +0 -164
  282. data/test/html/test_document.rb +0 -552
  283. data/test/html/test_document_encoding.rb +0 -138
  284. data/test/html/test_document_fragment.rb +0 -261
  285. data/test/html/test_element_description.rb +0 -105
  286. data/test/html/test_named_characters.rb +0 -14
  287. data/test/html/test_node.rb +0 -196
  288. data/test/html/test_node_encoding.rb +0 -27
  289. data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +0 -14
  290. data/test/namespaces/test_namespaces_in_builder_doc.rb +0 -75
  291. data/test/namespaces/test_namespaces_in_created_doc.rb +0 -75
  292. data/test/namespaces/test_namespaces_in_parsed_doc.rb +0 -66
  293. data/test/test_convert_xpath.rb +0 -135
  294. data/test/test_css_cache.rb +0 -45
  295. data/test/test_encoding_handler.rb +0 -46
  296. data/test/test_memory_leak.rb +0 -156
  297. data/test/test_nokogiri.rb +0 -132
  298. data/test/test_reader.rb +0 -555
  299. data/test/test_soap4r_sax.rb +0 -52
  300. data/test/test_xslt_transforms.rb +0 -254
  301. data/test/xml/node/test_save_options.rb +0 -28
  302. data/test/xml/node/test_subclass.rb +0 -44
  303. data/test/xml/sax/test_parser.rb +0 -366
  304. data/test/xml/sax/test_parser_context.rb +0 -106
  305. data/test/xml/sax/test_push_parser.rb +0 -157
  306. data/test/xml/test_attr.rb +0 -64
  307. data/test/xml/test_attribute_decl.rb +0 -86
  308. data/test/xml/test_builder.rb +0 -306
  309. data/test/xml/test_c14n.rb +0 -151
  310. data/test/xml/test_cdata.rb +0 -48
  311. data/test/xml/test_comment.rb +0 -29
  312. data/test/xml/test_document.rb +0 -828
  313. data/test/xml/test_document_encoding.rb +0 -28
  314. data/test/xml/test_document_fragment.rb +0 -223
  315. data/test/xml/test_dtd.rb +0 -103
  316. data/test/xml/test_dtd_encoding.rb +0 -33
  317. data/test/xml/test_element_content.rb +0 -56
  318. data/test/xml/test_element_decl.rb +0 -73
  319. data/test/xml/test_entity_decl.rb +0 -122
  320. data/test/xml/test_entity_reference.rb +0 -245
  321. data/test/xml/test_namespace.rb +0 -95
  322. data/test/xml/test_node.rb +0 -1137
  323. data/test/xml/test_node_attributes.rb +0 -96
  324. data/test/xml/test_node_encoding.rb +0 -107
  325. data/test/xml/test_node_inheritance.rb +0 -32
  326. data/test/xml/test_node_reparenting.rb +0 -374
  327. data/test/xml/test_node_set.rb +0 -755
  328. data/test/xml/test_parse_options.rb +0 -64
  329. data/test/xml/test_processing_instruction.rb +0 -30
  330. data/test/xml/test_reader_encoding.rb +0 -142
  331. data/test/xml/test_relax_ng.rb +0 -60
  332. data/test/xml/test_schema.rb +0 -103
  333. data/test/xml/test_syntax_error.rb +0 -12
  334. data/test/xml/test_text.rb +0 -45
  335. data/test/xml/test_unparented_node.rb +0 -422
  336. data/test/xml/test_xinclude.rb +0 -83
  337. data/test/xml/test_xpath.rb +0 -295
  338. data/test/xslt/test_custom_functions.rb +0 -133
  339. data/test/xslt/test_exception_handling.rb +0 -37
  340. data/test_all +0 -81
@@ -1,828 +0,0 @@
1
- require "helper"
2
-
3
- require 'uri'
4
-
5
- module Nokogiri
6
- module XML
7
- class TestDocument < Nokogiri::TestCase
8
- URI = if URI.const_defined?(:DEFAULT_PARSER)
9
- ::URI::DEFAULT_PARSER
10
- else
11
- ::URI
12
- end
13
-
14
- def setup
15
- super
16
- @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
17
- end
18
-
19
- def test_dtd_with_empty_internal_subset
20
- doc = Nokogiri::XML <<-eoxml
21
- <?xml version="1.0"?>
22
- <!DOCTYPE people >
23
- <people>
24
- </people>
25
- eoxml
26
- assert doc.root
27
- end
28
-
29
- # issue #838
30
- def test_document_with_invalid_prolog
31
- doc = Nokogiri::XML '<? ?>'
32
- assert_empty doc.content
33
- end
34
-
35
- # issue #837
36
- def test_document_with_refentity
37
- doc = Nokogiri::XML '&amp;'
38
- assert_equal '', doc.content
39
- end
40
-
41
- # issue #835
42
- def test_manually_adding_reference_entities
43
- d = Nokogiri::XML::Document.new
44
- root = Nokogiri::XML::Element.new('bar', d)
45
- txt = Nokogiri::XML::Text.new('foo', d)
46
- ent = Nokogiri::XML::EntityReference.new(d, '#8217')
47
- root << txt
48
- root << ent
49
- d << root
50
- assert_match /&#8217;/, d.to_html
51
- end
52
-
53
- def test_document_with_initial_space
54
- doc = Nokogiri::XML(" <?xml version='1.0' encoding='utf-8' ?><first \>")
55
- assert_equal 2, doc.children.size
56
- end
57
-
58
- def test_root_set_to_nil
59
- @xml.root = nil
60
- assert_equal nil, @xml.root
61
- end
62
-
63
- def test_ignore_unknown_namespace
64
- doc = Nokogiri::XML(<<-eoxml)
65
- <xml>
66
- <unknown:foo xmlns='http://hello.com/' />
67
- <bar />
68
- </xml>
69
- eoxml
70
- if Nokogiri.jruby?
71
- refute doc.xpath('//foo').first.namespace # assert that the namespace is nil
72
- end
73
- refute_empty doc.xpath('//bar'), "bar wasn't found in the document" # bar should be part of the doc
74
- end
75
-
76
- def test_collect_namespaces
77
- doc = Nokogiri::XML(<<-eoxml)
78
- <xml>
79
- <foo xmlns='hello'>
80
- <bar xmlns:foo='world' />
81
- </foo>
82
- </xml>
83
- eoxml
84
- assert_equal({"xmlns"=>"hello", "xmlns:foo"=>"world"},
85
- doc.collect_namespaces)
86
- end
87
-
88
- def test_subclass_initialize_modify # testing a segv
89
- Class.new(Nokogiri::XML::Document) {
90
- def initialize
91
- super
92
- body_node = Nokogiri::XML::Node.new "body", self
93
- body_node.content = "stuff"
94
- self.root = body_node
95
- end
96
- }.new
97
- end
98
-
99
- def test_create_text_node
100
- txt = @xml.create_text_node 'foo'
101
- assert_instance_of Nokogiri::XML::Text, txt
102
- assert_equal 'foo', txt.text
103
- assert_equal @xml, txt.document
104
- end
105
-
106
- def test_create_text_node_with_block
107
- @xml.create_text_node 'foo' do |txt|
108
- assert_instance_of Nokogiri::XML::Text, txt
109
- assert_equal 'foo', txt.text
110
- assert_equal @xml, txt.document
111
- end
112
- end
113
-
114
- def test_create_element
115
- elm = @xml.create_element('foo')
116
- assert_instance_of Nokogiri::XML::Element, elm
117
- assert_equal 'foo', elm.name
118
- assert_equal @xml, elm.document
119
- end
120
-
121
- def test_create_element_with_block
122
- @xml.create_element('foo') do |elm|
123
- assert_instance_of Nokogiri::XML::Element, elm
124
- assert_equal 'foo', elm.name
125
- assert_equal @xml, elm.document
126
- end
127
- end
128
-
129
- def test_create_element_with_attributes
130
- elm = @xml.create_element('foo',:a => "1")
131
- assert_instance_of Nokogiri::XML::Element, elm
132
- assert_instance_of Nokogiri::XML::Attr, elm.attributes["a"]
133
- assert_equal "1", elm["a"]
134
- end
135
-
136
- def test_create_element_with_namespace
137
- elm = @xml.create_element('foo',:'xmlns:foo' => 'http://tenderlovemaking.com')
138
- assert_equal 'http://tenderlovemaking.com', elm.namespaces['xmlns:foo']
139
- end
140
-
141
- def test_create_element_with_hyphenated_namespace
142
- elm = @xml.create_element('foo',:'xmlns:SOAP-ENC' => 'http://tenderlovemaking.com')
143
- assert_equal 'http://tenderlovemaking.com', elm.namespaces['xmlns:SOAP-ENC']
144
- end
145
-
146
- def test_create_element_with_content
147
- elm = @xml.create_element('foo',"needs more xml/violence")
148
- assert_equal "needs more xml/violence", elm.content
149
- end
150
-
151
- def test_create_cdata
152
- cdata = @xml.create_cdata("abc")
153
- assert_instance_of Nokogiri::XML::CDATA, cdata
154
- assert_equal "abc", cdata.content
155
- end
156
-
157
- def test_create_cdata_with_block
158
- @xml.create_cdata("abc") do |cdata|
159
- assert_instance_of Nokogiri::XML::CDATA, cdata
160
- assert_equal "abc", cdata.content
161
- end
162
- end
163
-
164
- def test_create_comment
165
- comment = @xml.create_comment("abc")
166
- assert_instance_of Nokogiri::XML::Comment, comment
167
- assert_equal "abc", comment.content
168
- end
169
-
170
- def test_create_comment_with_block
171
- @xml.create_comment("abc") do |comment|
172
- assert_instance_of Nokogiri::XML::Comment, comment
173
- assert_equal "abc", comment.content
174
- end
175
- end
176
-
177
- def test_pp
178
- out = StringIO.new('')
179
- ::PP.pp @xml, out
180
- assert_operator out.string.length, :>, 0
181
- end
182
-
183
- def test_create_internal_subset_on_existing_subset
184
- assert_not_nil @xml.internal_subset
185
- assert_raises(RuntimeError) do
186
- @xml.create_internal_subset('staff', nil, 'staff.dtd')
187
- end
188
- end
189
-
190
- def test_create_internal_subset
191
- xml = Nokogiri::XML('<root />')
192
- assert_nil xml.internal_subset
193
-
194
- xml.create_internal_subset('name', nil, 'staff.dtd')
195
- ss = xml.internal_subset
196
- assert_equal 'name', ss.name
197
- assert_nil ss.external_id
198
- assert_equal 'staff.dtd', ss.system_id
199
- end
200
-
201
- def test_external_subset
202
- assert_nil @xml.external_subset
203
- Dir.chdir(ASSETS_DIR) do
204
- @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) { |cfg|
205
- cfg.dtdload
206
- }
207
- end
208
- assert @xml.external_subset
209
- end
210
-
211
- def test_create_external_subset_fails_with_existing_subset
212
- assert_nil @xml.external_subset
213
- Dir.chdir(ASSETS_DIR) do
214
- @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) { |cfg|
215
- cfg.dtdload
216
- }
217
- end
218
- assert @xml.external_subset
219
-
220
- assert_raises(RuntimeError) do
221
- @xml.create_external_subset('staff', nil, 'staff.dtd')
222
- end
223
- end
224
-
225
- def test_create_external_subset
226
- dtd = @xml.create_external_subset('staff', nil, 'staff.dtd')
227
- assert_nil dtd.external_id
228
- assert_equal 'staff.dtd', dtd.system_id
229
- assert_equal 'staff', dtd.name
230
- assert_equal dtd, @xml.external_subset
231
- end
232
-
233
- def test_version
234
- assert_equal '1.0', @xml.version
235
- end
236
-
237
- def test_add_namespace
238
- assert_raise NoMethodError do
239
- @xml.add_namespace('foo', 'bar')
240
- end
241
- end
242
-
243
- def test_attributes
244
- assert_raise NoMethodError do
245
- @xml.attributes
246
- end
247
- end
248
-
249
- def test_namespace
250
- assert_raise NoMethodError do
251
- @xml.namespace
252
- end
253
- end
254
-
255
- def test_namespace_definitions
256
- assert_raise NoMethodError do
257
- @xml.namespace_definitions
258
- end
259
- end
260
-
261
- def test_line
262
- assert_raise NoMethodError do
263
- @xml.line
264
- end
265
- end
266
-
267
- def test_empty_node_converted_to_html_is_not_self_closing
268
- doc = Nokogiri::XML('<a></a>')
269
- assert_equal "<a></a>", doc.inner_html
270
- end
271
-
272
- def test_fragment
273
- fragment = @xml.fragment
274
- assert_equal 0, fragment.children.length
275
- end
276
-
277
- def test_add_child_fragment_with_single_node
278
- doc = Nokogiri::XML::Document.new
279
- fragment = doc.fragment('<hello />')
280
- doc.add_child fragment
281
- assert_equal '/hello', doc.at('//hello').path
282
- assert_equal 'hello', doc.root.name
283
- end
284
-
285
- def test_add_child_fragment_with_multiple_nodes
286
- doc = Nokogiri::XML::Document.new
287
- fragment = doc.fragment('<hello /><goodbye />')
288
- assert_raises(RuntimeError) do
289
- doc.add_child fragment
290
- end
291
- end
292
-
293
- def test_add_child_with_multiple_roots
294
- assert_raises(RuntimeError) do
295
- @xml << Node.new('foo', @xml)
296
- end
297
- end
298
-
299
- def test_add_child_with_string
300
- doc = Nokogiri::XML::Document.new
301
- doc.add_child "<div>quack!</div>"
302
- assert_equal 1, doc.root.children.length
303
- assert_equal "quack!", doc.root.children.first.content
304
- end
305
-
306
- def test_move_root_to_document_with_no_root
307
- sender = Nokogiri::XML('<root>foo</root>')
308
- newdoc = Nokogiri::XML::Document.new
309
- newdoc.root = sender.root
310
- end
311
-
312
- def test_move_root_with_existing_root_gets_gcd
313
- doc = Nokogiri::XML('<root>test</root>')
314
- doc2 = Nokogiri::XML("<root>#{'x' * 5000000}</root>")
315
- doc2.root = doc.root
316
- end
317
-
318
- def test_validate
319
- if Nokogiri.uses_libxml?
320
- assert_equal 44, @xml.validate.length
321
- else
322
- xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) {|cfg| cfg.dtdvalid}
323
- assert_equal 40, xml.validate.length
324
- end
325
- end
326
-
327
- def test_validate_no_internal_subset
328
- doc = Nokogiri::XML('<test/>')
329
- assert_nil doc.validate
330
- end
331
-
332
- def test_clone
333
- assert @xml.clone
334
- end
335
-
336
- def test_document_should_not_have_default_ns
337
- doc = Nokogiri::XML::Document.new
338
-
339
- assert_raises NoMethodError do
340
- doc.default_namespace = 'http://innernet.com/'
341
- end
342
-
343
- assert_raises NoMethodError do
344
- doc.add_namespace_definition('foo', 'bar')
345
- end
346
- end
347
-
348
- def test_parse_handles_nil_gracefully
349
- @doc = Nokogiri::XML::Document.parse(nil)
350
- assert_instance_of Nokogiri::XML::Document, @doc
351
- end
352
-
353
- def test_parse_takes_block
354
- options = nil
355
- Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) do |cfg|
356
- options = cfg
357
- end
358
- assert options
359
- end
360
-
361
- def test_parse_yields_parse_options
362
- options = nil
363
- Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) do |cfg|
364
- options = cfg
365
- options.nonet.nowarning.dtdattr
366
- end
367
- assert options.nonet?
368
- assert options.nowarning?
369
- assert options.dtdattr?
370
- end
371
-
372
- def test_XML_takes_block
373
- options = nil
374
- Nokogiri::XML(File.read(XML_FILE), XML_FILE) do |cfg|
375
- options = cfg
376
- options.nonet.nowarning.dtdattr
377
- end
378
- assert options.nonet?
379
- assert options.nowarning?
380
- assert options.dtdattr?
381
- end
382
-
383
- def test_subclass
384
- klass = Class.new(Nokogiri::XML::Document)
385
- doc = klass.new
386
- assert_instance_of klass, doc
387
- end
388
-
389
- def test_subclass_initialize
390
- klass = Class.new(Nokogiri::XML::Document) do
391
- attr_accessor :initialized_with
392
-
393
- def initialize(*args)
394
- @initialized_with = args
395
- end
396
- end
397
- doc = klass.new("1.0", 1)
398
- assert_equal ["1.0", 1], doc.initialized_with
399
- end
400
-
401
- def test_subclass_dup
402
- klass = Class.new(Nokogiri::XML::Document)
403
- doc = klass.new.dup
404
- assert_instance_of klass, doc
405
- end
406
-
407
- def test_subclass_parse
408
- klass = Class.new(Nokogiri::XML::Document)
409
- doc = klass.parse(File.read(XML_FILE))
410
- # lame hack uses root to avoid comparing DOCTYPE tags which can appear out of order.
411
- # I should really finish lorax and use that here.
412
- assert_equal @xml.root.to_s, doc.root.to_s
413
- assert_instance_of klass, doc
414
- end
415
-
416
- def test_document_parse_method
417
- xml = Nokogiri::XML::Document.parse(File.read(XML_FILE))
418
- # lame hack uses root to avoid comparing DOCTYPE tags which can appear out of order.
419
- # I should really finish lorax and use that here.
420
- assert_equal @xml.root.to_s, xml.root.to_s
421
- end
422
-
423
- def test_encoding=
424
- @xml.encoding = 'UTF-8'
425
- assert_match 'UTF-8', @xml.to_xml
426
-
427
- @xml.encoding = 'EUC-JP'
428
- assert_match 'EUC-JP', @xml.to_xml
429
- end
430
-
431
- def test_namespace_should_not_exist
432
- assert_raises(NoMethodError) {
433
- @xml.namespace
434
- }
435
- end
436
-
437
- def test_non_existant_function
438
- # WTF. I don't know why this is different between MRI and Jruby
439
- # They should be the same... Either way, raising an exception
440
- # is the correct thing to do.
441
- exception = RuntimeError
442
-
443
- if !Nokogiri.uses_libxml? || (Nokogiri.uses_libxml? && Nokogiri::VERSION_INFO['libxml']['platform'] == 'jruby')
444
- exception = Nokogiri::XML::XPath::SyntaxError
445
- end
446
-
447
- assert_raises(exception) {
448
- @xml.xpath('//name[foo()]')
449
- }
450
- end
451
-
452
- def test_ancestors
453
- assert_equal 0, @xml.ancestors.length
454
- end
455
-
456
- def test_root_node_parent_is_document
457
- parent = @xml.root.parent
458
- assert_equal @xml, parent
459
- assert_instance_of Nokogiri::XML::Document, parent
460
- end
461
-
462
- def test_xmlns_is_automatically_registered
463
- doc = Nokogiri::XML(<<-eoxml)
464
- <root xmlns="http://tenderlovemaking.com/">
465
- <foo>
466
- bar
467
- </foo>
468
- </root>
469
- eoxml
470
- assert_equal 1, doc.css('xmlns|foo').length
471
- assert_equal 1, doc.css('foo').length
472
- assert_equal 0, doc.css('|foo').length
473
- assert_equal 1, doc.xpath('//xmlns:foo').length
474
- assert_equal 1, doc.search('xmlns|foo').length
475
- assert_equal 1, doc.search('//xmlns:foo').length
476
- assert doc.at('xmlns|foo')
477
- assert doc.at('//xmlns:foo')
478
- assert doc.at('foo')
479
- end
480
-
481
- def test_xmlns_is_registered_for_nodesets
482
- doc = Nokogiri::XML(<<-eoxml)
483
- <root xmlns="http://tenderlovemaking.com/">
484
- <foo>
485
- <bar>
486
- baz
487
- </bar>
488
- </foo>
489
- </root>
490
- eoxml
491
- assert_equal 1, doc.css('xmlns|foo').css('xmlns|bar').length
492
- assert_equal 1, doc.css('foo').css('bar').length
493
- assert_equal 1, doc.xpath('//xmlns:foo').xpath('./xmlns:bar').length
494
- assert_equal 1, doc.search('xmlns|foo').search('xmlns|bar').length
495
- assert_equal 1, doc.search('//xmlns:foo').search('./xmlns:bar').length
496
- end
497
-
498
- def test_to_xml_with_indent
499
- doc = Nokogiri::XML('<root><foo><bar/></foo></root>')
500
- doc = Nokogiri::XML(doc.to_xml(:indent => 5))
501
-
502
- assert_indent 5, doc
503
- end
504
-
505
- def test_write_xml_to_with_indent
506
- io = StringIO.new
507
- doc = Nokogiri::XML('<root><foo><bar/></foo></root>')
508
- doc.write_xml_to io, :indent => 5
509
- io.rewind
510
- doc = Nokogiri::XML(io.read)
511
- assert_indent 5, doc
512
- end
513
-
514
- # wtf... osx's libxml sucks.
515
- unless !Nokogiri.uses_libxml? || Nokogiri::LIBXML_VERSION =~ /^2\.6\./
516
- def test_encoding
517
- xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE, 'UTF-8')
518
- assert_equal 'UTF-8', xml.encoding
519
- end
520
- end
521
-
522
- def test_document_has_errors
523
- doc = Nokogiri::XML(<<-eoxml)
524
- <foo><bar></foo>
525
- eoxml
526
- assert doc.errors.length > 0
527
- doc.errors.each do |error|
528
- assert_match error.message, error.inspect
529
- assert_match error.message, error.to_s
530
- end
531
- end
532
-
533
- def test_strict_document_throws_syntax_error
534
- assert_raises(Nokogiri::XML::SyntaxError) {
535
- Nokogiri::XML('<foo><bar></foo>', nil, nil, 0)
536
- }
537
-
538
- assert_raises(Nokogiri::XML::SyntaxError) {
539
- Nokogiri::XML('<foo><bar></foo>') { |cfg|
540
- cfg.strict
541
- }
542
- }
543
-
544
- assert_raises(Nokogiri::XML::SyntaxError) {
545
- Nokogiri::XML(StringIO.new('<foo><bar></foo>')) { |cfg|
546
- cfg.strict
547
- }
548
- }
549
- end
550
-
551
- def test_XML_function
552
- xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
553
- assert xml.xml?
554
- end
555
-
556
- def test_url
557
- assert @xml.url
558
- assert_equal XML_FILE, URI.unescape(@xml.url).sub('file:///', '')
559
- end
560
-
561
- def test_document_parent
562
- xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
563
- assert_raises(NoMethodError) {
564
- xml.parent
565
- }
566
- end
567
-
568
- def test_document_name
569
- xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
570
- assert_equal 'document', xml.name
571
- end
572
-
573
- def test_parse_can_take_io
574
- xml = nil
575
- File.open(XML_FILE, 'rb') { |f|
576
- xml = Nokogiri::XML(f)
577
- }
578
- assert xml.xml?
579
- set = xml.search('//employee')
580
- assert set.length > 0
581
- end
582
-
583
- def test_parsing_empty_io
584
- doc = Nokogiri::XML.parse(StringIO.new(''))
585
- refute_nil doc
586
- end
587
-
588
- def test_search_on_empty_documents
589
- doc = Nokogiri::XML::Document.new
590
- ns = doc.search('//foo')
591
- assert_equal 0, ns.length
592
-
593
- ns = doc.css('foo')
594
- assert_equal 0, ns.length
595
-
596
- ns = doc.xpath('//foo')
597
- assert_equal 0, ns.length
598
- end
599
-
600
- def test_bad_xpath_raises_syntax_error
601
- assert_raises(XML::XPath::SyntaxError) {
602
- @xml.xpath('\\')
603
- }
604
- end
605
-
606
- def test_find_with_namespace
607
- doc = Nokogiri::XML.parse(<<-eoxml)
608
- <x xmlns:tenderlove='http://tenderlovemaking.com/'>
609
- <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
610
- </x>
611
- eoxml
612
-
613
- ctx = Nokogiri::XML::XPathContext.new(doc)
614
- ctx.register_ns 'tenderlove', 'http://tenderlovemaking.com/'
615
- set = ctx.evaluate('//tenderlove:foo')
616
- assert_equal 1, set.length
617
- assert_equal 'foo', set.first.name
618
-
619
- # It looks like only the URI is important:
620
- ctx = Nokogiri::XML::XPathContext.new(doc)
621
- ctx.register_ns 'america', 'http://tenderlovemaking.com/'
622
- set = ctx.evaluate('//america:foo')
623
- assert_equal 1, set.length
624
- assert_equal 'foo', set.first.name
625
-
626
- # Its so important that a missing slash will cause it to return nothing
627
- ctx = Nokogiri::XML::XPathContext.new(doc)
628
- ctx.register_ns 'america', 'http://tenderlovemaking.com'
629
- set = ctx.evaluate('//america:foo')
630
- assert_equal 0, set.length
631
- end
632
-
633
- def test_xml?
634
- assert @xml.xml?
635
- end
636
-
637
- def test_document
638
- assert @xml.document
639
- end
640
-
641
- def test_singleton_methods
642
- assert node_set = @xml.search('//name')
643
- assert node_set.length > 0
644
- node = node_set.first
645
- def node.test
646
- 'test'
647
- end
648
- assert node_set = @xml.search('//name')
649
- assert_equal 'test', node_set.first.test
650
- end
651
-
652
- def test_multiple_search
653
- assert node_set = @xml.search('//employee', '//name')
654
- employees = @xml.search('//employee')
655
- names = @xml.search('//name')
656
- assert_equal(employees.length + names.length, node_set.length)
657
- end
658
-
659
- def test_node_set_index
660
- assert node_set = @xml.search('//employee')
661
-
662
- assert_equal(5, node_set.length)
663
- assert node_set[4]
664
- assert_nil node_set[5]
665
- end
666
-
667
- def test_search
668
- assert node_set = @xml.search('//employee')
669
-
670
- assert_equal(5, node_set.length)
671
-
672
- node_set.each do |node|
673
- assert_equal('employee', node.name)
674
- end
675
- end
676
-
677
- def test_dump
678
- assert @xml.serialize
679
- assert @xml.to_xml
680
- end
681
-
682
- def test_dup
683
- dup = @xml.dup
684
- assert_instance_of Nokogiri::XML::Document, dup
685
- assert dup.xml?, 'duplicate should be xml'
686
- end
687
-
688
- def test_new
689
- doc = nil
690
- doc = Nokogiri::XML::Document.new
691
- assert doc
692
- assert doc.xml?
693
- assert_nil doc.root
694
- end
695
-
696
- def test_set_root
697
- doc = nil
698
- doc = Nokogiri::XML::Document.new
699
- assert doc
700
- assert doc.xml?
701
- assert_nil doc.root
702
- node = Nokogiri::XML::Node.new("b", doc) { |n|
703
- n.content = 'hello world'
704
- }
705
- assert_equal('hello world', node.content)
706
- doc.root = node
707
- assert_equal(node, doc.root)
708
- end
709
-
710
- def test_remove_namespaces
711
- doc = Nokogiri::XML <<-EOX
712
- <root xmlns:a="http://a.flavorjon.es/" xmlns:b="http://b.flavorjon.es/">
713
- <a:foo>hello from a</a:foo>
714
- <b:foo>hello from b</b:foo>
715
- <container xmlns:c="http://c.flavorjon.es/">
716
- <c:foo c:attr='attr-value'>hello from c</c:foo>
717
- </container>
718
- </root>
719
- EOX
720
-
721
- namespaces = doc.root.namespaces
722
-
723
- # assert on setup
724
- assert_equal 2, doc.root.namespaces.length
725
- assert_equal 3, doc.at_xpath("//container").namespaces.length
726
- assert_equal 0, doc.xpath("//foo").length
727
- assert_equal 1, doc.xpath("//a:foo").length
728
- assert_equal 1, doc.xpath("//a:foo").length
729
- assert_equal 1, doc.xpath("//x:foo", "x" => "http://c.flavorjon.es/").length
730
- assert_match %r{foo c:attr}, doc.to_xml
731
-
732
- doc.remove_namespaces!
733
-
734
- assert_equal 0, doc.root.namespaces.length
735
- assert_equal 0, doc.at_xpath("//container").namespaces.length
736
- assert_equal 3, doc.xpath("//foo").length
737
- assert_equal 0, doc.xpath("//a:foo", namespaces).length
738
- assert_equal 0, doc.xpath("//a:foo", namespaces).length
739
- assert_equal 0, doc.xpath("//x:foo", "x" => "http://c.flavorjon.es/").length
740
- assert_match %r{foo attr}, doc.to_xml
741
- end
742
-
743
- # issue #785
744
- def test_attribute_decoration
745
- decorator = Module.new do
746
- def test_method
747
- end
748
- end
749
-
750
- util_decorate(@xml, decorator)
751
-
752
- assert @xml.search('//@street').first.respond_to?(:test_method)
753
- end
754
-
755
- def test_subset_is_decorated
756
- x = Module.new do
757
- def awesome!
758
- end
759
- end
760
- util_decorate(@xml, x)
761
-
762
- assert @xml.respond_to?(:awesome!)
763
- assert node_set = @xml.search('//staff')
764
- assert node_set.respond_to?(:awesome!)
765
- assert subset = node_set.search('.//employee')
766
- assert subset.respond_to?(:awesome!)
767
- assert sub_subset = node_set.search('.//name')
768
- assert sub_subset.respond_to?(:awesome!)
769
- end
770
-
771
- def test_decorator_is_applied
772
- x = Module.new do
773
- def awesome!
774
- end
775
- end
776
- util_decorate(@xml, x)
777
-
778
- assert @xml.respond_to?(:awesome!)
779
- assert node_set = @xml.search('//employee')
780
- assert node_set.respond_to?(:awesome!)
781
- node_set.each do |node|
782
- assert node.respond_to?(:awesome!), node.class
783
- end
784
- assert @xml.root.respond_to?(:awesome!)
785
- assert @xml.children.respond_to?(:awesome!)
786
- end
787
-
788
- if Nokogiri.jruby?
789
- def wrap_java_document
790
- require 'java'
791
- factory = javax.xml.parsers.DocumentBuilderFactory.newInstance
792
- builder = factory.newDocumentBuilder
793
- document = builder.newDocument
794
- root = document.createElement("foo")
795
- document.appendChild(root)
796
- Nokogiri::XML::Document.wrap(document)
797
- end
798
- end
799
-
800
- def test_java_integration
801
- skip("Ruby doesn't have the wrap method") unless Nokogiri.jruby?
802
- noko_doc = wrap_java_document
803
- assert_equal 'foo', noko_doc.root.name
804
-
805
- noko_doc = Nokogiri::XML(<<eoxml)
806
- <foo xmlns='hello'>
807
- <bar xmlns:foo='world' />
808
- </foo>
809
- eoxml
810
- dom = noko_doc.to_java
811
- assert dom.kind_of? org.w3c.dom.Document
812
- assert_equal 'foo', dom.getDocumentElement().getTagName()
813
- end
814
-
815
- def test_add_child
816
- skip("Ruby doesn't have the wrap method") unless Nokogiri.jruby?
817
- doc = wrap_java_document
818
- doc.root.add_child "<bar />"
819
- end
820
-
821
- def test_can_be_closed
822
- f = File.open XML_FILE
823
- Nokogiri::XML f
824
- f.close
825
- end
826
- end
827
- end
828
- end