nokogiri 1.2.3-x86-mswin32-60 → 1.4.5-x86-mswin32-60

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 (319) hide show
  1. data/.autotest +18 -7
  2. data/.gemtest +0 -0
  3. data/CHANGELOG.ja.rdoc +297 -3
  4. data/CHANGELOG.rdoc +289 -0
  5. data/Manifest.txt +148 -37
  6. data/README.ja.rdoc +20 -20
  7. data/README.rdoc +53 -22
  8. data/Rakefile +127 -211
  9. data/bin/nokogiri +54 -0
  10. data/ext/nokogiri/depend +358 -0
  11. data/ext/nokogiri/extconf.rb +89 -54
  12. data/ext/nokogiri/html_document.c +34 -27
  13. data/ext/nokogiri/html_document.h +1 -1
  14. data/ext/nokogiri/html_element_description.c +276 -0
  15. data/ext/nokogiri/html_element_description.h +10 -0
  16. data/ext/nokogiri/html_entity_lookup.c +7 -5
  17. data/ext/nokogiri/html_entity_lookup.h +1 -1
  18. data/ext/nokogiri/html_sax_parser_context.c +94 -0
  19. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  20. data/ext/nokogiri/{native.c → nokogiri.c} +31 -7
  21. data/ext/nokogiri/{native.h → nokogiri.h} +68 -41
  22. data/ext/nokogiri/xml_attr.c +20 -9
  23. data/ext/nokogiri/xml_attr.h +1 -1
  24. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  25. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  26. data/ext/nokogiri/xml_cdata.c +21 -9
  27. data/ext/nokogiri/xml_cdata.h +1 -1
  28. data/ext/nokogiri/xml_comment.c +18 -6
  29. data/ext/nokogiri/xml_comment.h +1 -1
  30. data/ext/nokogiri/xml_document.c +247 -68
  31. data/ext/nokogiri/xml_document.h +5 -3
  32. data/ext/nokogiri/xml_document_fragment.c +15 -7
  33. data/ext/nokogiri/xml_document_fragment.h +1 -1
  34. data/ext/nokogiri/xml_dtd.c +110 -10
  35. data/ext/nokogiri/xml_dtd.h +3 -1
  36. data/ext/nokogiri/xml_element_content.c +123 -0
  37. data/ext/nokogiri/xml_element_content.h +10 -0
  38. data/ext/nokogiri/xml_element_decl.c +69 -0
  39. data/ext/nokogiri/xml_element_decl.h +9 -0
  40. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  41. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  42. data/ext/nokogiri/xml_entity_decl.c +110 -0
  43. data/ext/nokogiri/xml_entity_decl.h +10 -0
  44. data/ext/nokogiri/xml_entity_reference.c +16 -5
  45. data/ext/nokogiri/xml_entity_reference.h +1 -1
  46. data/ext/nokogiri/xml_io.c +40 -8
  47. data/ext/nokogiri/xml_io.h +2 -1
  48. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  49. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  50. data/ext/nokogiri/xml_namespace.c +84 -0
  51. data/ext/nokogiri/xml_namespace.h +13 -0
  52. data/ext/nokogiri/xml_node.c +782 -225
  53. data/ext/nokogiri/xml_node.h +2 -4
  54. data/ext/nokogiri/xml_node_set.c +253 -34
  55. data/ext/nokogiri/xml_node_set.h +2 -2
  56. data/ext/nokogiri/xml_processing_instruction.c +17 -5
  57. data/ext/nokogiri/xml_processing_instruction.h +1 -1
  58. data/ext/nokogiri/xml_reader.c +277 -85
  59. data/ext/nokogiri/xml_reader.h +1 -1
  60. data/ext/nokogiri/xml_relax_ng.c +168 -0
  61. data/ext/nokogiri/xml_relax_ng.h +9 -0
  62. data/ext/nokogiri/xml_sax_parser.c +183 -111
  63. data/ext/nokogiri/xml_sax_parser.h +30 -1
  64. data/ext/nokogiri/xml_sax_parser_context.c +199 -0
  65. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  66. data/ext/nokogiri/xml_sax_push_parser.c +42 -12
  67. data/ext/nokogiri/xml_sax_push_parser.h +1 -1
  68. data/ext/nokogiri/xml_schema.c +205 -0
  69. data/ext/nokogiri/xml_schema.h +9 -0
  70. data/ext/nokogiri/xml_syntax_error.c +28 -173
  71. data/ext/nokogiri/xml_syntax_error.h +2 -1
  72. data/ext/nokogiri/xml_text.c +16 -6
  73. data/ext/nokogiri/xml_text.h +1 -1
  74. data/ext/nokogiri/xml_xpath_context.c +104 -47
  75. data/ext/nokogiri/xml_xpath_context.h +1 -1
  76. data/ext/nokogiri/xslt_stylesheet.c +161 -19
  77. data/ext/nokogiri/xslt_stylesheet.h +1 -1
  78. data/lib/nokogiri.rb +47 -8
  79. data/lib/nokogiri/1.8/nokogiri.so +0 -0
  80. data/lib/nokogiri/1.9/nokogiri.so +0 -0
  81. data/lib/nokogiri/css.rb +6 -3
  82. data/lib/nokogiri/css/node.rb +14 -12
  83. data/lib/nokogiri/css/parser.rb +665 -62
  84. data/lib/nokogiri/css/parser.y +20 -10
  85. data/lib/nokogiri/css/parser_extras.rb +91 -0
  86. data/lib/nokogiri/css/tokenizer.rb +148 -5
  87. data/lib/nokogiri/css/tokenizer.rex +10 -9
  88. data/lib/nokogiri/css/xpath_visitor.rb +47 -44
  89. data/lib/nokogiri/decorators/slop.rb +8 -4
  90. data/lib/nokogiri/ffi/encoding_handler.rb +42 -0
  91. data/lib/nokogiri/ffi/html/document.rb +28 -0
  92. data/lib/nokogiri/ffi/html/element_description.rb +81 -0
  93. data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
  94. data/lib/nokogiri/ffi/html/sax/parser_context.rb +38 -0
  95. data/lib/nokogiri/ffi/io_callbacks.rb +42 -0
  96. data/lib/nokogiri/ffi/libxml.rb +420 -0
  97. data/lib/nokogiri/ffi/structs/common_node.rb +38 -0
  98. data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
  99. data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
  100. data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
  101. data/lib/nokogiri/ffi/structs/xml_attr.rb +20 -0
  102. data/lib/nokogiri/ffi/structs/xml_attribute.rb +27 -0
  103. data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
  104. data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +11 -0
  105. data/lib/nokogiri/ffi/structs/xml_document.rb +117 -0
  106. data/lib/nokogiri/ffi/structs/xml_dtd.rb +28 -0
  107. data/lib/nokogiri/ffi/structs/xml_element.rb +26 -0
  108. data/lib/nokogiri/ffi/structs/xml_element_content.rb +17 -0
  109. data/lib/nokogiri/ffi/structs/xml_entity.rb +32 -0
  110. data/lib/nokogiri/ffi/structs/xml_enumeration.rb +12 -0
  111. data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
  112. data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
  113. data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
  114. data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
  115. data/lib/nokogiri/ffi/structs/xml_parser_context.rb +20 -0
  116. data/lib/nokogiri/ffi/structs/xml_parser_input.rb +19 -0
  117. data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
  118. data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
  119. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +124 -0
  120. data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
  121. data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
  122. data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
  123. data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +38 -0
  124. data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
  125. data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
  126. data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
  127. data/lib/nokogiri/ffi/weak_bucket.rb +40 -0
  128. data/lib/nokogiri/ffi/xml/attr.rb +41 -0
  129. data/lib/nokogiri/ffi/xml/attribute_decl.rb +27 -0
  130. data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
  131. data/lib/nokogiri/ffi/xml/comment.rb +18 -0
  132. data/lib/nokogiri/ffi/xml/document.rb +174 -0
  133. data/lib/nokogiri/ffi/xml/document_fragment.rb +21 -0
  134. data/lib/nokogiri/ffi/xml/dtd.rb +67 -0
  135. data/lib/nokogiri/ffi/xml/element_content.rb +43 -0
  136. data/lib/nokogiri/ffi/xml/element_decl.rb +19 -0
  137. data/lib/nokogiri/ffi/xml/entity_decl.rb +36 -0
  138. data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
  139. data/lib/nokogiri/ffi/xml/namespace.rb +44 -0
  140. data/lib/nokogiri/ffi/xml/node.rb +559 -0
  141. data/lib/nokogiri/ffi/xml/node_set.rb +150 -0
  142. data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
  143. data/lib/nokogiri/ffi/xml/reader.rb +236 -0
  144. data/lib/nokogiri/ffi/xml/relax_ng.rb +85 -0
  145. data/lib/nokogiri/ffi/xml/sax/parser.rb +143 -0
  146. data/lib/nokogiri/ffi/xml/sax/parser_context.rb +79 -0
  147. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +51 -0
  148. data/lib/nokogiri/ffi/xml/schema.rb +109 -0
  149. data/lib/nokogiri/ffi/xml/syntax_error.rb +98 -0
  150. data/lib/nokogiri/ffi/xml/text.rb +18 -0
  151. data/lib/nokogiri/ffi/xml/xpath.rb +9 -0
  152. data/lib/nokogiri/ffi/xml/xpath_context.rb +153 -0
  153. data/lib/nokogiri/ffi/xslt/stylesheet.rb +77 -0
  154. data/lib/nokogiri/html.rb +13 -47
  155. data/lib/nokogiri/html/builder.rb +27 -1
  156. data/lib/nokogiri/html/document.rb +201 -7
  157. data/lib/nokogiri/html/document_fragment.rb +41 -0
  158. data/lib/nokogiri/html/element_description.rb +23 -0
  159. data/lib/nokogiri/html/entity_lookup.rb +2 -0
  160. data/lib/nokogiri/html/sax/parser.rb +34 -3
  161. data/lib/nokogiri/html/sax/parser_context.rb +16 -0
  162. data/lib/nokogiri/nokogiri.rb +1 -0
  163. data/lib/nokogiri/version.rb +40 -1
  164. data/lib/nokogiri/version_warning.rb +14 -0
  165. data/lib/nokogiri/xml.rb +32 -53
  166. data/lib/nokogiri/xml/attr.rb +5 -0
  167. data/lib/nokogiri/xml/attribute_decl.rb +18 -0
  168. data/lib/nokogiri/xml/builder.rb +349 -29
  169. data/lib/nokogiri/xml/cdata.rb +3 -1
  170. data/lib/nokogiri/xml/character_data.rb +7 -0
  171. data/lib/nokogiri/xml/document.rb +166 -14
  172. data/lib/nokogiri/xml/document_fragment.rb +76 -1
  173. data/lib/nokogiri/xml/dtd.rb +16 -3
  174. data/lib/nokogiri/xml/element_content.rb +36 -0
  175. data/lib/nokogiri/xml/element_decl.rb +13 -0
  176. data/lib/nokogiri/xml/entity_decl.rb +19 -0
  177. data/lib/nokogiri/xml/namespace.rb +13 -0
  178. data/lib/nokogiri/xml/node.rb +561 -166
  179. data/lib/nokogiri/xml/node/save_options.rb +22 -2
  180. data/lib/nokogiri/xml/node_set.rb +202 -40
  181. data/lib/nokogiri/xml/parse_options.rb +93 -0
  182. data/lib/nokogiri/xml/pp.rb +2 -0
  183. data/lib/nokogiri/xml/pp/character_data.rb +18 -0
  184. data/lib/nokogiri/xml/pp/node.rb +56 -0
  185. data/lib/nokogiri/xml/processing_instruction.rb +2 -0
  186. data/lib/nokogiri/xml/reader.rb +93 -8
  187. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  188. data/lib/nokogiri/xml/sax.rb +1 -7
  189. data/lib/nokogiri/xml/sax/document.rb +107 -2
  190. data/lib/nokogiri/xml/sax/parser.rb +57 -7
  191. data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
  192. data/lib/nokogiri/xml/sax/push_parser.rb +13 -1
  193. data/lib/nokogiri/xml/schema.rb +63 -0
  194. data/lib/nokogiri/xml/syntax_error.rb +25 -1
  195. data/lib/nokogiri/xml/text.rb +4 -1
  196. data/lib/nokogiri/xml/xpath.rb +1 -1
  197. data/lib/nokogiri/xml/xpath/syntax_error.rb +3 -0
  198. data/lib/nokogiri/xml/xpath_context.rb +2 -0
  199. data/lib/nokogiri/xslt.rb +26 -2
  200. data/lib/nokogiri/xslt/stylesheet.rb +19 -0
  201. data/lib/xsd/xmlparser/nokogiri.rb +45 -9
  202. data/tasks/cross_compile.rb +173 -0
  203. data/tasks/test.rb +25 -69
  204. data/test/css/test_nthiness.rb +3 -4
  205. data/test/css/test_parser.rb +75 -20
  206. data/test/css/test_tokenizer.rb +23 -1
  207. data/test/css/test_xpath_visitor.rb +10 -1
  208. data/test/decorators/test_slop.rb +16 -0
  209. data/test/ffi/test_document.rb +35 -0
  210. data/test/files/2ch.html +108 -0
  211. data/test/files/address_book.rlx +12 -0
  212. data/test/files/address_book.xml +10 -0
  213. data/test/files/bar/bar.xsd +4 -0
  214. data/test/files/encoding.html +82 -0
  215. data/test/files/encoding.xhtml +84 -0
  216. data/test/files/foo/foo.xsd +4 -0
  217. data/test/files/po.xml +32 -0
  218. data/test/files/po.xsd +66 -0
  219. data/test/files/shift_jis.html +10 -0
  220. data/test/files/shift_jis.xml +5 -0
  221. data/test/files/snuggles.xml +3 -0
  222. data/test/files/staff.dtd +10 -0
  223. data/test/files/valid_bar.xml +2 -0
  224. data/test/helper.rb +101 -23
  225. data/test/html/sax/test_parser.rb +81 -2
  226. data/test/html/sax/test_parser_context.rb +48 -0
  227. data/test/html/test_builder.rb +39 -8
  228. data/test/html/test_document.rb +186 -23
  229. data/test/html/test_document_encoding.rb +78 -1
  230. data/test/html/test_document_fragment.rb +253 -0
  231. data/test/html/test_element_description.rb +98 -0
  232. data/test/html/test_named_characters.rb +1 -1
  233. data/test/html/test_node.rb +124 -36
  234. data/test/html/test_node_encoding.rb +27 -0
  235. data/test/test_convert_xpath.rb +1 -52
  236. data/test/test_css_cache.rb +2 -13
  237. data/test/test_encoding_handler.rb +46 -0
  238. data/test/test_memory_leak.rb +88 -19
  239. data/test/test_nokogiri.rb +38 -5
  240. data/test/test_reader.rb +188 -6
  241. data/test/test_soap4r_sax.rb +52 -0
  242. data/test/test_xslt_transforms.rb +183 -83
  243. data/test/xml/node/test_save_options.rb +1 -1
  244. data/test/xml/node/test_subclass.rb +44 -0
  245. data/test/xml/sax/test_parser.rb +175 -4
  246. data/test/xml/sax/test_parser_context.rb +113 -0
  247. data/test/xml/sax/test_push_parser.rb +90 -2
  248. data/test/xml/test_attr.rb +35 -1
  249. data/test/xml/test_attribute_decl.rb +82 -0
  250. data/test/xml/test_builder.rb +186 -1
  251. data/test/xml/test_cdata.rb +32 -1
  252. data/test/xml/test_comment.rb +13 -1
  253. data/test/xml/test_document.rb +415 -43
  254. data/test/xml/test_document_encoding.rb +1 -1
  255. data/test/xml/test_document_fragment.rb +173 -5
  256. data/test/xml/test_dtd.rb +61 -6
  257. data/test/xml/test_dtd_encoding.rb +3 -1
  258. data/test/xml/test_element_content.rb +56 -0
  259. data/test/xml/test_element_decl.rb +73 -0
  260. data/test/xml/test_entity_decl.rb +120 -0
  261. data/test/xml/test_entity_reference.rb +5 -1
  262. data/test/xml/test_namespace.rb +68 -0
  263. data/test/xml/test_node.rb +546 -201
  264. data/test/xml/test_node_attributes.rb +34 -0
  265. data/test/xml/test_node_encoding.rb +33 -3
  266. data/test/xml/test_node_reparenting.rb +321 -0
  267. data/test/xml/test_node_set.rb +538 -2
  268. data/test/xml/test_parse_options.rb +52 -0
  269. data/test/xml/test_processing_instruction.rb +6 -1
  270. data/test/xml/test_reader_encoding.rb +1 -1
  271. data/test/xml/test_relax_ng.rb +60 -0
  272. data/test/xml/test_schema.rb +94 -0
  273. data/test/xml/test_syntax_error.rb +12 -0
  274. data/test/xml/test_text.rb +35 -1
  275. data/test/xml/test_unparented_node.rb +5 -5
  276. data/test/xml/test_xpath.rb +142 -11
  277. data/test/xslt/test_custom_functions.rb +94 -0
  278. metadata +328 -92
  279. data/ext/nokogiri/html_sax_parser.c +0 -57
  280. data/ext/nokogiri/html_sax_parser.h +0 -11
  281. data/ext/nokogiri/iconv.dll +0 -0
  282. data/ext/nokogiri/libexslt.dll +0 -0
  283. data/ext/nokogiri/libxml2.dll +0 -0
  284. data/ext/nokogiri/libxslt.dll +0 -0
  285. data/ext/nokogiri/native.so +0 -0
  286. data/ext/nokogiri/xml_xpath.c +0 -53
  287. data/ext/nokogiri/xml_xpath.h +0 -11
  288. data/ext/nokogiri/zlib1.dll +0 -0
  289. data/lib/action-nokogiri.rb +0 -30
  290. data/lib/nokogiri/css/generated_parser.rb +0 -713
  291. data/lib/nokogiri/css/generated_tokenizer.rb +0 -144
  292. data/lib/nokogiri/decorators.rb +0 -2
  293. data/lib/nokogiri/decorators/hpricot.rb +0 -3
  294. data/lib/nokogiri/decorators/hpricot/node.rb +0 -56
  295. data/lib/nokogiri/decorators/hpricot/node_set.rb +0 -54
  296. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +0 -28
  297. data/lib/nokogiri/hpricot.rb +0 -51
  298. data/lib/nokogiri/xml/comment.rb +0 -6
  299. data/lib/nokogiri/xml/element.rb +0 -6
  300. data/lib/nokogiri/xml/entity_declaration.rb +0 -9
  301. data/lib/nokogiri/xml/fragment_handler.rb +0 -34
  302. data/test/hpricot/files/basic.xhtml +0 -17
  303. data/test/hpricot/files/boingboing.html +0 -2266
  304. data/test/hpricot/files/cy0.html +0 -3653
  305. data/test/hpricot/files/immob.html +0 -400
  306. data/test/hpricot/files/pace_application.html +0 -1320
  307. data/test/hpricot/files/tenderlove.html +0 -16
  308. data/test/hpricot/files/uswebgen.html +0 -220
  309. data/test/hpricot/files/utf8.html +0 -1054
  310. data/test/hpricot/files/week9.html +0 -1723
  311. data/test/hpricot/files/why.xml +0 -19
  312. data/test/hpricot/load_files.rb +0 -11
  313. data/test/hpricot/test_alter.rb +0 -68
  314. data/test/hpricot/test_builder.rb +0 -20
  315. data/test/hpricot/test_parser.rb +0 -426
  316. data/test/hpricot/test_paths.rb +0 -15
  317. data/test/hpricot/test_preserved.rb +0 -77
  318. data/test/hpricot/test_xml.rb +0 -30
  319. data/test/test_gc.rb +0 -15
@@ -1,12 +1,44 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
1
+ require "helper"
2
2
 
3
3
  class TestNokogiri < Nokogiri::TestCase
4
- def test_version
4
+ def test_versions
5
+ version_match = /\d+\.\d+\.\d+/
6
+ assert_match version_match, Nokogiri::VERSION
7
+ assert_match version_match, Nokogiri::LIBXML_VERSION
8
+
9
+ if defined?(FFI) && defined?(Nokogiri::LibXML)
10
+ assert_equal 'ffi', Nokogiri::VERSION_INFO['libxml']['binding']
11
+ if RUBY_PLATFORM =~ /java/
12
+ assert_equal 'jruby', Nokogiri::VERSION_INFO['libxml']['platform']
13
+ else
14
+ assert_equal 'ruby', Nokogiri::VERSION_INFO['libxml']['platform']
15
+ end
16
+ assert Nokogiri.ffi?
17
+ else
18
+ assert_equal 'extension', Nokogiri::VERSION_INFO['libxml']['binding']
19
+
20
+ assert_match version_match, Nokogiri::VERSION_INFO['libxml']['compiled']
21
+ assert_equal Nokogiri::LIBXML_VERSION, Nokogiri::VERSION_INFO['libxml']['compiled']
22
+ assert ! Nokogiri.ffi?
23
+ end
24
+
25
+ assert_match version_match, Nokogiri::VERSION_INFO['libxml']['loaded']
5
26
  Nokogiri::LIBXML_PARSER_VERSION =~ /(\d)(\d{2})(\d{2})/
6
27
  major = $1.to_i
7
28
  minor = $2.to_i
8
29
  bug = $3.to_i
9
- assert_equal "#{major}.#{minor}.#{bug}", Nokogiri::LIBXML_VERSION
30
+ assert_equal "#{major}.#{minor}.#{bug}", Nokogiri::VERSION_INFO['libxml']['loaded']
31
+ end
32
+
33
+ def test_libxml_iconv
34
+ assert Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED)
35
+ end
36
+
37
+ def test_parse_with_io
38
+ doc = Nokogiri.parse(
39
+ StringIO.new("<html><head><title></title><body></body></html>")
40
+ )
41
+ assert_instance_of Nokogiri::HTML::Document, doc
10
42
  end
11
43
 
12
44
  def test_xml?
@@ -41,7 +73,7 @@ class TestNokogiri < Nokogiri::TestCase
41
73
  doc = Nokogiri.make { b "bold tag" }
42
74
  assert_equal('<b>bold tag</b>', doc.to_html.chomp)
43
75
  end
44
-
76
+
45
77
  SLOP_HTML = <<-END
46
78
  <html>
47
79
  <body>
@@ -91,7 +123,7 @@ class TestNokogiri < Nokogiri::TestCase
91
123
 
92
124
  assert_raise(NoMethodError) { doc.nonexistent }
93
125
  end
94
-
126
+
95
127
  def test_slop_decorator
96
128
  doc = Nokogiri(SLOP_HTML)
97
129
  assert !doc.decorators(Nokogiri::XML::Node).include?(Nokogiri::Decorators::Slop)
@@ -102,4 +134,5 @@ class TestNokogiri < Nokogiri::TestCase
102
134
  doc.slop!
103
135
  assert_equal 1, doc.decorators(Nokogiri::XML::Node).select { |d| d == Nokogiri::Decorators::Slop }.size
104
136
  end
137
+
105
138
  end
data/test/test_reader.rb CHANGED
@@ -1,7 +1,123 @@
1
1
  # -*- coding: utf-8 -*-
2
- require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
2
+ require "helper"
3
3
 
4
4
  class TestReader < Nokogiri::TestCase
5
+ def test_from_io_sets_io_as_source
6
+ io = File.open SNUGGLES_FILE
7
+ reader = Nokogiri::XML::Reader.from_io(io)
8
+ assert_equal io, reader.source
9
+ end
10
+
11
+ def test_empty_element?
12
+ reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
13
+ <xml><city>Paris</city><state/></xml>
14
+ eoxml
15
+
16
+ results = reader.map do |node|
17
+ if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE
18
+ node.empty_element?
19
+ end
20
+ end
21
+ assert_equal [false, false, nil, nil, true, nil], results
22
+ end
23
+
24
+ def test_self_closing?
25
+ reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
26
+ <xml><city>Paris</city><state/></xml>
27
+ eoxml
28
+
29
+ results = reader.map do |node|
30
+ if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE
31
+ node.self_closing?
32
+ end
33
+ end
34
+ assert_equal [false, false, nil, nil, true, nil], results
35
+ end
36
+
37
+ def test_reader_takes_block
38
+ options = nil
39
+ Nokogiri::XML::Reader(File.read(XML_FILE), XML_FILE) do |cfg|
40
+ options = cfg
41
+ options.nonet.nowarning.dtdattr
42
+ end
43
+ assert options.nonet?
44
+ assert options.nowarning?
45
+ assert options.dtdattr?
46
+ end
47
+
48
+ def test_nil_raises
49
+ assert_raises(ArgumentError) {
50
+ Nokogiri::XML::Reader.from_memory(nil)
51
+ }
52
+ assert_raises(ArgumentError) {
53
+ Nokogiri::XML::Reader.from_io(nil)
54
+ }
55
+ end
56
+
57
+ def test_from_io
58
+ io = File.open SNUGGLES_FILE
59
+ reader = Nokogiri::XML::Reader.from_io(io)
60
+ assert_equal false, reader.default?
61
+ assert_equal [false, false, false, false, false, false, false],
62
+ reader.map { |x| x.default? }
63
+ end
64
+
65
+ def test_io
66
+ io = File.open SNUGGLES_FILE
67
+ reader = Nokogiri::XML::Reader(io)
68
+ assert_equal false, reader.default?
69
+ assert_equal [false, false, false, false, false, false, false],
70
+ reader.map { |x| x.default? }
71
+ end
72
+
73
+ def test_string_io
74
+ io = StringIO.new(<<-eoxml)
75
+ <x xmlns:tenderlove='http://tenderlovemaking.com/'>
76
+ <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
77
+ </x>
78
+ eoxml
79
+ reader = Nokogiri::XML::Reader(io)
80
+ assert_equal false, reader.default?
81
+ assert_equal [false, false, false, false, false, false, false],
82
+ reader.map { |x| x.default? }
83
+ end
84
+
85
+ class ReallyBadIO
86
+ def read(size)
87
+ 'a' * size ** 10
88
+ end
89
+ end
90
+
91
+ unless Nokogiri.ffi?
92
+ def test_io_that_reads_too_much
93
+ io = ReallyBadIO.new
94
+ Nokogiri::XML::Reader(io)
95
+ end
96
+ end
97
+
98
+ def test_in_memory
99
+ assert Nokogiri::XML::Reader(<<-eoxml)
100
+ <x xmlns:tenderlove='http://tenderlovemaking.com/'>
101
+ <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
102
+ </x>
103
+ eoxml
104
+ end
105
+
106
+ def test_reader_holds_on_to_string
107
+ xml = <<-eoxml
108
+ <x xmlns:tenderlove='http://tenderlovemaking.com/'>
109
+ <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
110
+ </x>
111
+ eoxml
112
+ reader = Nokogiri::XML::Reader(xml)
113
+ if Nokogiri.ffi?
114
+ assert_not_nil reader.source
115
+ assert reader.source.is_a?(FFI::MemoryPointer)
116
+ else
117
+ assert_equal xml, reader.source
118
+ end
119
+ end
120
+
5
121
  def test_default?
6
122
  reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
7
123
  <x xmlns:tenderlove='http://tenderlovemaking.com/'>
@@ -31,13 +147,9 @@ class TestReader < Nokogiri::TestCase
31
147
  <foo>
32
148
  </x>
33
149
  eoxml
34
- error_happened = false
35
- begin
150
+ assert_raises(Nokogiri::XML::SyntaxError) do
36
151
  reader.each { |node| }
37
- rescue Nokogiri::XML::SyntaxError => ex
38
- error_happened = true
39
152
  end
40
- assert error_happened
41
153
  assert 1, reader.errors.length
42
154
  end
43
155
 
@@ -183,6 +295,34 @@ class TestReader < Nokogiri::TestCase
183
295
  reader.map { |n| n.prefix }
184
296
  end
185
297
 
298
+ def test_node_type
299
+ reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
300
+ <x>
301
+ <y>hello</y>
302
+ </x>
303
+ eoxml
304
+ assert_equal 0, reader.node_type
305
+ assert_equal [1, 14, 1, 3, 15, 14, 15], reader.map { |n| n.node_type }
306
+ end
307
+
308
+ def test_inner_xml
309
+ str = "<x><y>hello</y></x>"
310
+ reader = Nokogiri::XML::Reader.from_memory(str)
311
+
312
+ reader.read
313
+
314
+ assert_equal "<y>hello</y>", reader.inner_xml
315
+ end
316
+
317
+ def test_outer_xml
318
+ str = "<x><y>hello</y></x>"
319
+ reader = Nokogiri::XML::Reader.from_memory(str)
320
+
321
+ reader.read
322
+
323
+ assert_equal str, reader.outer_xml
324
+ end
325
+
186
326
  def test_state
187
327
  reader = Nokogiri::XML::Reader.from_memory('<foo>bar</bar>')
188
328
  assert reader.state
@@ -227,6 +367,34 @@ class TestReader < Nokogiri::TestCase
227
367
  reader.map { |n| n.name })
228
368
  end
229
369
 
370
+ def test_base_uri
371
+ reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
372
+ <x xml:base="http://base.example.org/base/">
373
+ <link href="link"/>
374
+ <other xml:base="http://other.example.org/"/>
375
+ <relative xml:base="relative">
376
+ <link href="stuff" />
377
+ </relative>
378
+ </x>
379
+ eoxml
380
+
381
+ assert_nil reader.base_uri
382
+ assert_equal(["http://base.example.org/base/",
383
+ "http://base.example.org/base/",
384
+ "http://base.example.org/base/",
385
+ "http://base.example.org/base/",
386
+ "http://other.example.org/",
387
+ "http://base.example.org/base/",
388
+ "http://base.example.org/base/relative",
389
+ "http://base.example.org/base/relative",
390
+ "http://base.example.org/base/relative",
391
+ "http://base.example.org/base/relative",
392
+ "http://base.example.org/base/relative",
393
+ "http://base.example.org/base/",
394
+ "http://base.example.org/base/"],
395
+ reader.map {|n| n.base_uri })
396
+ end
397
+
230
398
  def test_read_from_memory
231
399
  called = false
232
400
  reader = Nokogiri::XML::Reader.from_memory('<foo>bar</foo>')
@@ -236,4 +404,18 @@ class TestReader < Nokogiri::TestCase
236
404
  end
237
405
  assert called
238
406
  end
407
+
408
+ def test_large_document_smoke_test
409
+ # simply run on a large document to verify that there no GC issues
410
+ xml = []
411
+ xml << "<elements>"
412
+ 10000.times { |j| xml << "<element id=\"#{j}\"/>" }
413
+ xml << "</elements>"
414
+ xml = xml.join("\n")
415
+
416
+ Nokogiri::XML::Reader.from_memory(xml).each do |e|
417
+ e.attributes
418
+ end
419
+ end
420
+
239
421
  end
@@ -0,0 +1,52 @@
1
+ require "helper"
2
+
3
+ module XSD
4
+ module XMLParser
5
+ class Parser
6
+ @factory_added = nil
7
+
8
+ class << self; attr_reader :factory_added; end
9
+
10
+ def self.add_factory o
11
+ @factory_added = o
12
+ end
13
+
14
+ def initialize *args
15
+ @charset = nil
16
+ end
17
+
18
+ def characters foo
19
+ end
20
+
21
+ def start_element *args
22
+ end
23
+
24
+ def end_element *args
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ require 'xsd/xmlparser/nokogiri'
31
+
32
+ class TestSoap4rSax < Nokogiri::TestCase
33
+ def test_factory_added
34
+ assert_equal XSD::XMLParser::Nokogiri, XSD::XMLParser::Nokogiri.factory_added
35
+ end
36
+
37
+ def test_parse
38
+ o = Class.new(::XSD::XMLParser::Nokogiri) do
39
+ attr_accessor :element_started
40
+ def initialize *args
41
+ super
42
+ @element_started = false
43
+ end
44
+
45
+ def start_element *args
46
+ @element_started = true
47
+ end
48
+ end.new 'foo'
49
+ o.do_parse '<?xml version="1.0" ?><root xmlns="http://example.com/"/>'
50
+ assert o.element_started, 'element started'
51
+ end
52
+ end
@@ -1,93 +1,193 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "helper"))
1
+ require "helper"
2
2
 
3
3
  class TestXsltTransforms < Nokogiri::TestCase
4
- def test_transform
5
- assert doc = Nokogiri::XML.parse(File.read(XML_FILE))
6
- assert doc.xml?
7
-
8
- assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
9
-
10
- assert result = style.apply_to(doc, ['title', '"Booyah"'])
11
- assert_match %r{<h1>Booyah</h1>}, result
12
- assert_match %r{<th.*Employee ID</th>}, result
13
- assert_match %r{<th.*Name</th>}, result
14
- assert_match %r{<th.*Position</th>}, result
15
- assert_match %r{<th.*Salary</th>}, result
16
- assert_match %r{<td>EMP0003</td>}, result
17
- assert_match %r{<td>Margaret Martin</td>}, result
18
- assert_match %r{<td>Computer Specialist</td>}, result
19
- assert_match %r{<td>100,000</td>}, result
20
- assert_no_match %r{Dallas|Texas}, result
21
- assert_no_match %r{Female}, result
22
-
23
- assert result = style.apply_to(doc, ['title', '"Grandma"'])
24
- assert_match %r{<h1>Grandma</h1>}, result
25
-
26
- assert result = style.apply_to(doc)
27
- assert_match %r{<h1></h1>}, result
4
+ def setup
5
+ @doc = Nokogiri::XML(File.open(XML_FILE))
28
6
  end
29
- def test_transform2
30
- assert doc = Nokogiri::XML.parse(File.read(XML_FILE))
31
- assert doc.xml?
32
7
 
33
- assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
34
- assert result_doc = style.transform(doc, ['title', '"Booyah"'])
35
- assert doc.xml?
8
+ if Nokogiri.uses_libxml?
9
+ def test_class_methods
10
+ style = Nokogiri::XSLT(File.read(XSLT_FILE))
36
11
 
37
- assert result_string = style.apply_to(doc, ['title', '"Booyah"'])
38
- assert_equal result_string, style.serialize(result_doc)
39
- end
40
- def test_quote_params
41
- h = {
42
- :sym => %{xxx},
43
- 'str' => %{"xxx"},
44
- :sym2 => %{'xxx'},
45
- 'str2' => %{x'x'x},
46
- :sym3 => %{x"x"x},
47
- }
48
- hh=h.dup
49
- result_hash = Nokogiri::XSLT.quote_params(h)
50
- assert_equal hh, h # non-destructive
51
-
52
- a=h.to_a.flatten
53
- result_array = Nokogiri::XSLT.quote_params(a)
54
- assert_equal h.to_a.flatten, a #non-destructive
55
-
56
- assert_equal result_array, result_hash
57
- end
12
+ assert result = style.apply_to(@doc, ['title', '"Grandma"'])
13
+ assert_match %r{<h1>Grandma</h1>}, result
14
+ end
15
+
16
+ def test_transform
17
+ assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
18
+
19
+ assert result = style.apply_to(@doc, ['title', '"Booyah"'])
20
+ assert_match %r{<h1>Booyah</h1>}, result
21
+ assert_match %r{<th.*Employee ID</th>}, result
22
+ assert_match %r{<th.*Name</th>}, result
23
+ assert_match %r{<th.*Position</th>}, result
24
+ assert_match %r{<th.*Salary</th>}, result
25
+ assert_match %r{<td>EMP0003</td>}, result
26
+ assert_match %r{<td>Margaret Martin</td>}, result
27
+ assert_match %r{<td>Computer Specialist</td>}, result
28
+ assert_match %r{<td>100,000</td>}, result
29
+ assert_no_match %r{Dallas|Texas}, result
30
+ assert_no_match %r{Female}, result
58
31
 
59
- def test_exslt
60
- assert doc = Nokogiri::XML.parse(File.read(EXML_FILE))
61
- assert doc.xml?
62
-
63
- assert style = Nokogiri::XSLT.parse(File.read(EXSLT_FILE))
64
- params = {
65
- :p1 => 'xxx',
66
- :p2 => "x'x'x",
67
- :p3 => 'x"x"x',
68
- :p4 => '"xxx"'
69
- }
70
- result_doc = Nokogiri::XML.parse(style.apply_to(doc,
71
- Nokogiri::XSLT.quote_params(params)))
72
-
73
- assert_equal 'func-result', result_doc.at('/root/function').content
74
- assert_equal 3, result_doc.at('/root/max').content.to_i
75
- assert_match(
76
- /\d{4}-\d\d-\d\d[-|+]\d\d:\d\d/,
77
- result_doc.at('/root/date').content
78
- )
79
- result_doc.xpath('/root/params/*').each do |p|
80
- assert_equal p.content, params[p.name.intern]
32
+ assert result = style.apply_to(@doc, ['title', '"Grandma"'])
33
+ assert_match %r{<h1>Grandma</h1>}, result
34
+
35
+ assert result = style.apply_to(@doc)
36
+ assert_match %r{<h1></h1>}, result
81
37
  end
82
- check_params result_doc, params
83
- result_doc = Nokogiri::XML.parse(style.apply_to(doc,
84
- Nokogiri::XSLT.quote_params(params.to_a.flatten)))
85
- check_params result_doc, params
86
- end
87
-
88
- def check_params result_doc, params
89
- result_doc.xpath('/root/params/*').each do |p|
90
- assert_equal p.content, params[p.name.intern]
38
+
39
+ def test_transform_with_output_style
40
+ xslt = Nokogiri::XSLT(<<-eoxslt)
41
+ <?xml version="1.0" encoding="ISO-8859-1"?>
42
+
43
+ <xsl:stylesheet version="1.0"
44
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
45
+ <xsl:output method="text" version="1.0"
46
+ encoding="iso-8859-1" indent="yes"/>
47
+
48
+ <xsl:param name="title"/>
49
+
50
+ <xsl:template match="/">
51
+ <html>
52
+ <body>
53
+ <xsl:for-each select="staff/employee">
54
+ <tr>
55
+ <td><xsl:value-of select="employeeId"/></td>
56
+ <td><xsl:value-of select="name"/></td>
57
+ <td><xsl:value-of select="position"/></td>
58
+ <td><xsl:value-of select="salary"/></td>
59
+ </tr>
60
+ </xsl:for-each>
61
+ </table>
62
+ </body>
63
+ </html>
64
+ </xsl:template>
65
+
66
+ </xsl:stylesheet>
67
+ eoxslt
68
+ assert_no_match(/<td>/, xslt.apply_to(@doc, ['title', 'foo']))
69
+ end
70
+
71
+ def test_transform_arg_error
72
+ assert style = Nokogiri::XSLT(File.read(XSLT_FILE))
73
+ assert_raises(TypeError) do
74
+ style.transform(@doc, :foo)
75
+ end
76
+ end
77
+
78
+ def test_transform_with_hash
79
+ assert style = Nokogiri::XSLT(File.read(XSLT_FILE))
80
+ result = style.transform(@doc, {'title' => '"Booyah"'})
81
+ assert result.html?
82
+ assert_equal "Booyah", result.at_css("h1").content
83
+ end
84
+
85
+ def test_transform2
86
+ assert style = Nokogiri::XSLT(File.open(XSLT_FILE))
87
+ assert result_doc = style.transform(@doc)
88
+ assert result_doc.html?
89
+ assert_equal "", result_doc.at_css("h1").content
90
+
91
+ assert style = Nokogiri::XSLT(File.read(XSLT_FILE))
92
+ assert result_doc = style.transform(@doc, ['title', '"Booyah"'])
93
+ assert result_doc.html?
94
+ assert_equal "Booyah", result_doc.at_css("h1").content
95
+
96
+ assert result_string = style.apply_to(@doc, ['title', '"Booyah"'])
97
+ assert_equal result_string, style.serialize(result_doc)
98
+ end
99
+
100
+ def test_transform_with_quote_params
101
+ assert style = Nokogiri::XSLT(File.open(XSLT_FILE))
102
+ assert result_doc = style.transform(@doc, Nokogiri::XSLT.quote_params(['title', 'Booyah']))
103
+ assert result_doc.html?
104
+ assert_equal "Booyah", result_doc.at_css("h1").content
105
+
106
+ assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
107
+ assert result_doc = style.transform(@doc, Nokogiri::XSLT.quote_params({'title' => 'Booyah'}))
108
+ assert result_doc.html?
109
+ assert_equal "Booyah", result_doc.at_css("h1").content
110
+ end
111
+
112
+ def test_quote_params
113
+ h = {
114
+ :sym => %{xxx},
115
+ 'str' => %{"xxx"},
116
+ :sym2 => %{'xxx'},
117
+ 'str2' => %{x'x'x},
118
+ :sym3 => %{x"x"x},
119
+ }
120
+ hh=h.dup
121
+ result_hash = Nokogiri::XSLT.quote_params(h)
122
+ assert_equal hh, h # non-destructive
123
+
124
+ a=h.to_a.flatten
125
+ result_array = Nokogiri::XSLT.quote_params(a)
126
+ assert_equal h.to_a.flatten, a #non-destructive
127
+
128
+ assert_equal result_array, result_hash
129
+ end
130
+
131
+ if Nokogiri.uses_libxml? # By now, cannot get it working on JRuby.
132
+ def test_exslt
133
+ assert doc = Nokogiri::XML.parse(File.read(EXML_FILE))
134
+ assert doc.xml?
135
+
136
+ assert style = Nokogiri::XSLT.parse(File.read(EXSLT_FILE))
137
+ params = {
138
+ :p1 => 'xxx',
139
+ :p2 => "x'x'x",
140
+ :p3 => 'x"x"x',
141
+ :p4 => '"xxx"'
142
+ }
143
+ result_doc = Nokogiri::XML.parse(style.apply_to(doc,
144
+ Nokogiri::XSLT.quote_params(params)))
145
+
146
+ assert_equal 'func-result', result_doc.at('/root/function').content
147
+ assert_equal 3, result_doc.at('/root/max').content.to_i
148
+ assert_match(
149
+ /\d{4}-\d\d-\d\d([-|+]\d\d:\d\d)?/,
150
+ result_doc.at('/root/date').content
151
+ )
152
+ result_doc.xpath('/root/params/*').each do |p|
153
+ assert_equal p.content, params[p.name.intern]
154
+ end
155
+ check_params result_doc, params
156
+ result_doc = Nokogiri::XML.parse(style.apply_to(doc,
157
+ Nokogiri::XSLT.quote_params(params.to_a.flatten)))
158
+ check_params result_doc, params
159
+ end
160
+ end
161
+
162
+ def test_xslt_parse_error
163
+ xslt_str = <<-EOX
164
+ <xsl:stylesheet version="1.0"
165
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
166
+ <!-- Not well-formed: -->
167
+ <xsl:template match="/"/>
168
+ <values>
169
+ <xsl:for-each select="//*">
170
+ <value>
171
+ <xsl:value-of select="@id"/>
172
+ </value>
173
+ </xsl:for-each>
174
+ </values>
175
+ </xsl:template>
176
+ </xsl:stylesheet>}
177
+ EOX
178
+ assert_raises(RuntimeError) { Nokogiri::XSLT.parse(xslt_str) }
179
+ end
180
+
181
+ def test_passing_a_non_document_to_transform
182
+ xsl = Nokogiri::XSLT('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"></xsl:stylesheet>')
183
+ assert_raises(ArgumentError) { xsl.transform("<div></div>") }
184
+ assert_raises(ArgumentError) { xsl.transform(Nokogiri::HTML("").css("body")) }
185
+ end
186
+
187
+ def check_params result_doc, params
188
+ result_doc.xpath('/root/params/*').each do |p|
189
+ assert_equal p.content, params[p.name.intern]
190
+ end
91
191
  end
92
192
  end
93
193
  end