rubyjedi-nokogiri_java 1.4.0.20100513161003-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (285) hide show
  1. data/.autotest +26 -0
  2. data/CHANGELOG.ja.rdoc +330 -0
  3. data/CHANGELOG.rdoc +341 -0
  4. data/Manifest.txt +277 -0
  5. data/README.ja.rdoc +105 -0
  6. data/README.rdoc +125 -0
  7. data/Rakefile +307 -0
  8. data/bin/nokogiri +49 -0
  9. data/deps.rip +5 -0
  10. data/ext/nokogiri/extconf.rb +149 -0
  11. data/ext/nokogiri/html_document.c +145 -0
  12. data/ext/nokogiri/html_document.h +10 -0
  13. data/ext/nokogiri/html_element_description.c +272 -0
  14. data/ext/nokogiri/html_element_description.h +10 -0
  15. data/ext/nokogiri/html_entity_lookup.c +32 -0
  16. data/ext/nokogiri/html_entity_lookup.h +8 -0
  17. data/ext/nokogiri/html_sax_parser_context.c +92 -0
  18. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  19. data/ext/nokogiri/nokogiri.c +96 -0
  20. data/ext/nokogiri/nokogiri.h +148 -0
  21. data/ext/nokogiri/xml_attr.c +92 -0
  22. data/ext/nokogiri/xml_attr.h +9 -0
  23. data/ext/nokogiri/xml_attribute_decl.c +67 -0
  24. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  25. data/ext/nokogiri/xml_cdata.c +54 -0
  26. data/ext/nokogiri/xml_cdata.h +9 -0
  27. data/ext/nokogiri/xml_comment.c +52 -0
  28. data/ext/nokogiri/xml_comment.h +9 -0
  29. data/ext/nokogiri/xml_document.c +386 -0
  30. data/ext/nokogiri/xml_document.h +24 -0
  31. data/ext/nokogiri/xml_document_fragment.c +46 -0
  32. data/ext/nokogiri/xml_document_fragment.h +10 -0
  33. data/ext/nokogiri/xml_dtd.c +192 -0
  34. data/ext/nokogiri/xml_dtd.h +10 -0
  35. data/ext/nokogiri/xml_element_content.c +123 -0
  36. data/ext/nokogiri/xml_element_content.h +10 -0
  37. data/ext/nokogiri/xml_element_decl.c +69 -0
  38. data/ext/nokogiri/xml_element_decl.h +9 -0
  39. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  40. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  41. data/ext/nokogiri/xml_entity_decl.c +97 -0
  42. data/ext/nokogiri/xml_entity_decl.h +10 -0
  43. data/ext/nokogiri/xml_entity_reference.c +50 -0
  44. data/ext/nokogiri/xml_entity_reference.h +9 -0
  45. data/ext/nokogiri/xml_io.c +31 -0
  46. data/ext/nokogiri/xml_io.h +11 -0
  47. data/ext/nokogiri/xml_namespace.c +82 -0
  48. data/ext/nokogiri/xml_namespace.h +13 -0
  49. data/ext/nokogiri/xml_node.c +1080 -0
  50. data/ext/nokogiri/xml_node.h +13 -0
  51. data/ext/nokogiri/xml_node_set.c +405 -0
  52. data/ext/nokogiri/xml_node_set.h +9 -0
  53. data/ext/nokogiri/xml_processing_instruction.c +54 -0
  54. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  55. data/ext/nokogiri/xml_reader.c +593 -0
  56. data/ext/nokogiri/xml_reader.h +10 -0
  57. data/ext/nokogiri/xml_relax_ng.c +159 -0
  58. data/ext/nokogiri/xml_relax_ng.h +9 -0
  59. data/ext/nokogiri/xml_sax_parser.c +283 -0
  60. data/ext/nokogiri/xml_sax_parser.h +43 -0
  61. data/ext/nokogiri/xml_sax_parser_context.c +157 -0
  62. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  63. data/ext/nokogiri/xml_sax_push_parser.c +114 -0
  64. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  65. data/ext/nokogiri/xml_schema.c +156 -0
  66. data/ext/nokogiri/xml_schema.h +9 -0
  67. data/ext/nokogiri/xml_syntax_error.c +52 -0
  68. data/ext/nokogiri/xml_syntax_error.h +13 -0
  69. data/ext/nokogiri/xml_text.c +48 -0
  70. data/ext/nokogiri/xml_text.h +9 -0
  71. data/ext/nokogiri/xml_xpath.c +53 -0
  72. data/ext/nokogiri/xml_xpath.h +11 -0
  73. data/ext/nokogiri/xml_xpath_context.c +239 -0
  74. data/ext/nokogiri/xml_xpath_context.h +9 -0
  75. data/ext/nokogiri/xslt_stylesheet.c +131 -0
  76. data/ext/nokogiri/xslt_stylesheet.h +9 -0
  77. data/lib/isorelax.jar +0 -0
  78. data/lib/jing.jar +0 -0
  79. data/lib/nekodtd.jar +0 -0
  80. data/lib/nekohtml.jar +0 -0
  81. data/lib/nokogiri.rb +123 -0
  82. data/lib/nokogiri/css.rb +25 -0
  83. data/lib/nokogiri/css/generated_parser.rb +659 -0
  84. data/lib/nokogiri/css/generated_tokenizer.rb +145 -0
  85. data/lib/nokogiri/css/node.rb +99 -0
  86. data/lib/nokogiri/css/parser.rb +82 -0
  87. data/lib/nokogiri/css/parser.y +230 -0
  88. data/lib/nokogiri/css/syntax_error.rb +7 -0
  89. data/lib/nokogiri/css/tokenizer.rb +7 -0
  90. data/lib/nokogiri/css/tokenizer.rex +55 -0
  91. data/lib/nokogiri/css/xpath_visitor.rb +164 -0
  92. data/lib/nokogiri/decorators/slop.rb +33 -0
  93. data/lib/nokogiri/ffi/encoding_handler.rb +42 -0
  94. data/lib/nokogiri/ffi/html/document.rb +28 -0
  95. data/lib/nokogiri/ffi/html/element_description.rb +81 -0
  96. data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
  97. data/lib/nokogiri/ffi/html/sax/parser_context.rb +38 -0
  98. data/lib/nokogiri/ffi/io_callbacks.rb +42 -0
  99. data/lib/nokogiri/ffi/libxml.rb +372 -0
  100. data/lib/nokogiri/ffi/structs/common_node.rb +26 -0
  101. data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
  102. data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
  103. data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
  104. data/lib/nokogiri/ffi/structs/xml_attr.rb +19 -0
  105. data/lib/nokogiri/ffi/structs/xml_attribute.rb +27 -0
  106. data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
  107. data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +11 -0
  108. data/lib/nokogiri/ffi/structs/xml_document.rb +108 -0
  109. data/lib/nokogiri/ffi/structs/xml_dtd.rb +28 -0
  110. data/lib/nokogiri/ffi/structs/xml_element.rb +26 -0
  111. data/lib/nokogiri/ffi/structs/xml_element_content.rb +17 -0
  112. data/lib/nokogiri/ffi/structs/xml_entity.rb +32 -0
  113. data/lib/nokogiri/ffi/structs/xml_enumeration.rb +12 -0
  114. data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
  115. data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
  116. data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
  117. data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
  118. data/lib/nokogiri/ffi/structs/xml_parser_context.rb +19 -0
  119. data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
  120. data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
  121. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +124 -0
  122. data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
  123. data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
  124. data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
  125. data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +37 -0
  126. data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
  127. data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
  128. data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
  129. data/lib/nokogiri/ffi/xml/attr.rb +41 -0
  130. data/lib/nokogiri/ffi/xml/attribute_decl.rb +27 -0
  131. data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
  132. data/lib/nokogiri/ffi/xml/comment.rb +18 -0
  133. data/lib/nokogiri/ffi/xml/document.rb +135 -0
  134. data/lib/nokogiri/ffi/xml/document_fragment.rb +21 -0
  135. data/lib/nokogiri/ffi/xml/dtd.rb +67 -0
  136. data/lib/nokogiri/ffi/xml/element_content.rb +43 -0
  137. data/lib/nokogiri/ffi/xml/element_decl.rb +19 -0
  138. data/lib/nokogiri/ffi/xml/entity_decl.rb +27 -0
  139. data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
  140. data/lib/nokogiri/ffi/xml/namespace.rb +44 -0
  141. data/lib/nokogiri/ffi/xml/node.rb +465 -0
  142. data/lib/nokogiri/ffi/xml/node_set.rb +146 -0
  143. data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
  144. data/lib/nokogiri/ffi/xml/reader.rb +227 -0
  145. data/lib/nokogiri/ffi/xml/relax_ng.rb +85 -0
  146. data/lib/nokogiri/ffi/xml/sax/parser.rb +135 -0
  147. data/lib/nokogiri/ffi/xml/sax/parser_context.rb +67 -0
  148. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +55 -0
  149. data/lib/nokogiri/ffi/xml/schema.rb +92 -0
  150. data/lib/nokogiri/ffi/xml/syntax_error.rb +98 -0
  151. data/lib/nokogiri/ffi/xml/text.rb +18 -0
  152. data/lib/nokogiri/ffi/xml/xpath.rb +19 -0
  153. data/lib/nokogiri/ffi/xml/xpath_context.rb +135 -0
  154. data/lib/nokogiri/ffi/xslt/stylesheet.rb +50 -0
  155. data/lib/nokogiri/html.rb +36 -0
  156. data/lib/nokogiri/html/builder.rb +35 -0
  157. data/lib/nokogiri/html/document.rb +88 -0
  158. data/lib/nokogiri/html/document_fragment.rb +15 -0
  159. data/lib/nokogiri/html/element_description.rb +23 -0
  160. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  161. data/lib/nokogiri/html/entity_lookup.rb +13 -0
  162. data/lib/nokogiri/html/sax/parser.rb +48 -0
  163. data/lib/nokogiri/html/sax/parser_context.rb +16 -0
  164. data/lib/nokogiri/nokogiri.jar +0 -0
  165. data/lib/nokogiri/syntax_error.rb +4 -0
  166. data/lib/nokogiri/version.rb +33 -0
  167. data/lib/nokogiri/version_warning.rb +11 -0
  168. data/lib/nokogiri/xml.rb +67 -0
  169. data/lib/nokogiri/xml/attr.rb +14 -0
  170. data/lib/nokogiri/xml/attribute_decl.rb +18 -0
  171. data/lib/nokogiri/xml/builder.rb +405 -0
  172. data/lib/nokogiri/xml/cdata.rb +11 -0
  173. data/lib/nokogiri/xml/character_data.rb +7 -0
  174. data/lib/nokogiri/xml/document.rb +163 -0
  175. data/lib/nokogiri/xml/document_fragment.rb +73 -0
  176. data/lib/nokogiri/xml/dtd.rb +11 -0
  177. data/lib/nokogiri/xml/element_content.rb +36 -0
  178. data/lib/nokogiri/xml/element_decl.rb +13 -0
  179. data/lib/nokogiri/xml/entity_decl.rb +15 -0
  180. data/lib/nokogiri/xml/fragment_handler.rb +73 -0
  181. data/lib/nokogiri/xml/namespace.rb +13 -0
  182. data/lib/nokogiri/xml/node.rb +730 -0
  183. data/lib/nokogiri/xml/node/save_options.rb +42 -0
  184. data/lib/nokogiri/xml/node_set.rb +318 -0
  185. data/lib/nokogiri/xml/notation.rb +6 -0
  186. data/lib/nokogiri/xml/parse_options.rb +85 -0
  187. data/lib/nokogiri/xml/pp.rb +2 -0
  188. data/lib/nokogiri/xml/pp/character_data.rb +18 -0
  189. data/lib/nokogiri/xml/pp/node.rb +56 -0
  190. data/lib/nokogiri/xml/processing_instruction.rb +8 -0
  191. data/lib/nokogiri/xml/reader.rb +74 -0
  192. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  193. data/lib/nokogiri/xml/sax.rb +4 -0
  194. data/lib/nokogiri/xml/sax/document.rb +160 -0
  195. data/lib/nokogiri/xml/sax/parser.rb +115 -0
  196. data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
  197. data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
  198. data/lib/nokogiri/xml/schema.rb +61 -0
  199. data/lib/nokogiri/xml/syntax_error.rb +43 -0
  200. data/lib/nokogiri/xml/xpath.rb +10 -0
  201. data/lib/nokogiri/xml/xpath/syntax_error.rb +8 -0
  202. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  203. data/lib/nokogiri/xslt.rb +48 -0
  204. data/lib/nokogiri/xslt/stylesheet.rb +25 -0
  205. data/lib/xercesImpl.jar +0 -0
  206. data/lib/xsd/xmlparser/nokogiri.rb +90 -0
  207. data/tasks/test.rb +100 -0
  208. data/test/css/test_nthiness.rb +159 -0
  209. data/test/css/test_parser.rb +282 -0
  210. data/test/css/test_tokenizer.rb +190 -0
  211. data/test/css/test_xpath_visitor.rb +76 -0
  212. data/test/ffi/test_document.rb +35 -0
  213. data/test/files/2ch.html +108 -0
  214. data/test/files/address_book.rlx +12 -0
  215. data/test/files/address_book.xml +10 -0
  216. data/test/files/bar/bar.xsd +4 -0
  217. data/test/files/dont_hurt_em_why.xml +422 -0
  218. data/test/files/exslt.xml +8 -0
  219. data/test/files/exslt.xslt +35 -0
  220. data/test/files/foo/foo.xsd +4 -0
  221. data/test/files/po.xml +32 -0
  222. data/test/files/po.xsd +66 -0
  223. data/test/files/shift_jis.html +10 -0
  224. data/test/files/shift_jis.xml +5 -0
  225. data/test/files/snuggles.xml +3 -0
  226. data/test/files/staff.dtd +10 -0
  227. data/test/files/staff.xml +59 -0
  228. data/test/files/staff.xslt +32 -0
  229. data/test/files/tlm.html +850 -0
  230. data/test/files/valid_bar.xml +2 -0
  231. data/test/helper.rb +137 -0
  232. data/test/html/sax/test_parser.rb +83 -0
  233. data/test/html/sax/test_parser_context.rb +48 -0
  234. data/test/html/test_builder.rb +164 -0
  235. data/test/html/test_document.rb +385 -0
  236. data/test/html/test_document_encoding.rb +77 -0
  237. data/test/html/test_document_fragment.rb +157 -0
  238. data/test/html/test_element_description.rb +98 -0
  239. data/test/html/test_named_characters.rb +14 -0
  240. data/test/html/test_node.rb +242 -0
  241. data/test/html/test_node_encoding.rb +27 -0
  242. data/test/test_convert_xpath.rb +135 -0
  243. data/test/test_css_cache.rb +45 -0
  244. data/test/test_encoding_handler.rb +46 -0
  245. data/test/test_jruby.rb +40 -0
  246. data/test/test_memory_leak.rb +87 -0
  247. data/test/test_nokogiri.rb +140 -0
  248. data/test/test_reader.rb +358 -0
  249. data/test/test_soap4r_sax.rb +52 -0
  250. data/test/test_xslt_transforms.rb +150 -0
  251. data/test/xml/node/test_save_options.rb +20 -0
  252. data/test/xml/node/test_subclass.rb +44 -0
  253. data/test/xml/sax/test_parser.rb +314 -0
  254. data/test/xml/sax/test_parser_context.rb +63 -0
  255. data/test/xml/sax/test_push_parser.rb +135 -0
  256. data/test/xml/test_attr.rb +38 -0
  257. data/test/xml/test_attribute_decl.rb +90 -0
  258. data/test/xml/test_builder.rb +167 -0
  259. data/test/xml/test_cdata.rb +38 -0
  260. data/test/xml/test_comment.rb +29 -0
  261. data/test/xml/test_document.rb +638 -0
  262. data/test/xml/test_document_encoding.rb +26 -0
  263. data/test/xml/test_document_fragment.rb +149 -0
  264. data/test/xml/test_dtd.rb +92 -0
  265. data/test/xml/test_dtd_encoding.rb +33 -0
  266. data/test/xml/test_element_content.rb +56 -0
  267. data/test/xml/test_element_decl.rb +73 -0
  268. data/test/xml/test_entity_decl.rb +83 -0
  269. data/test/xml/test_entity_reference.rb +21 -0
  270. data/test/xml/test_namespace.rb +70 -0
  271. data/test/xml/test_node.rb +740 -0
  272. data/test/xml/test_node_attributes.rb +34 -0
  273. data/test/xml/test_node_encoding.rb +107 -0
  274. data/test/xml/test_node_reparenting.rb +279 -0
  275. data/test/xml/test_node_set.rb +577 -0
  276. data/test/xml/test_parse_options.rb +52 -0
  277. data/test/xml/test_processing_instruction.rb +30 -0
  278. data/test/xml/test_reader_encoding.rb +126 -0
  279. data/test/xml/test_relax_ng.rb +60 -0
  280. data/test/xml/test_schema.rb +89 -0
  281. data/test/xml/test_syntax_error.rb +12 -0
  282. data/test/xml/test_text.rb +30 -0
  283. data/test/xml/test_unparented_node.rb +381 -0
  284. data/test/xml/test_xpath.rb +169 -0
  285. metadata +477 -0
@@ -0,0 +1,77 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "helper"
3
+
4
+ module Nokogiri
5
+ module HTML
6
+ if RUBY_VERSION =~ /^1\.9/
7
+ class TestDocumentEncoding < Nokogiri::TestCase
8
+ def test_encoding
9
+ doc = Nokogiri::HTML File.open(SHIFT_JIS_HTML, 'rb')
10
+
11
+ hello = "こんにちは"
12
+
13
+ assert_match doc.encoding, doc.to_html
14
+ assert_match hello.encode('Shift_JIS'), doc.to_html
15
+ assert_equal 'Shift_JIS', doc.to_html.encoding.name
16
+
17
+ assert_match hello, doc.to_html(:encoding => 'UTF-8')
18
+ assert_match 'UTF-8', doc.to_html(:encoding => 'UTF-8')
19
+ assert_match 'UTF-8', doc.to_html(:encoding => 'UTF-8').encoding.name
20
+ end
21
+
22
+ def test_default_to_encoding_from_string
23
+ bad_charset = <<-eohtml
24
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
25
+ <html>
26
+ <head>
27
+ <meta http-equiv="Content-Type" content="text/html; charset=charset=UTF-8">
28
+ </head>
29
+ <body>
30
+ <a href="http://tenderlovemaking.com/">blah!</a>
31
+ </body>
32
+ </html>
33
+ eohtml
34
+ doc = Nokogiri::HTML(bad_charset)
35
+ assert_equal bad_charset.encoding.name, doc.encoding
36
+
37
+ doc = Nokogiri.parse(bad_charset)
38
+ assert_equal bad_charset.encoding.name, doc.encoding
39
+ end
40
+
41
+ def test_encoding_non_utf8
42
+ orig = '日本語が上手です'
43
+ bin = Encoding::ASCII_8BIT
44
+ [Encoding::Shift_JIS, Encoding::EUC_JP].each do |enc|
45
+ html = <<-eohtml.encode(enc)
46
+ <html>
47
+ <meta http-equiv="Content-Type" content="text/html; charset=#{enc.name}">
48
+ <title xml:lang="ja">#{orig}</title></html>
49
+ eohtml
50
+ text = Nokogiri::HTML.parse(html).at('title').inner_text
51
+ assert_equal(
52
+ orig.encode(enc).force_encoding(bin),
53
+ text.encode(enc).force_encoding(bin)
54
+ )
55
+ end
56
+ end
57
+
58
+ def test_encoding_with_a_bad_name
59
+ bad_charset = <<-eohtml
60
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
61
+ <html>
62
+ <head>
63
+ <meta http-equiv="Content-Type" content="text/html; charset=charset=UTF-8">
64
+ </head>
65
+ <body>
66
+ <a href="http://tenderlovemaking.com/">blah!</a>
67
+ </body>
68
+ </html>
69
+ eohtml
70
+ doc = Nokogiri::HTML(bad_charset, nil, 'askldjfhalsdfjhlkasdfjh')
71
+ assert_equal ['http://tenderlovemaking.com/'],
72
+ doc.css('a').map { |a| a['href'] }
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,157 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "helper"
3
+
4
+ module Nokogiri
5
+ module HTML
6
+ class TestDocumentFragment < Nokogiri::TestCase
7
+ def setup
8
+ super
9
+ @html = Nokogiri::HTML.parse(File.read(HTML_FILE), HTML_FILE)
10
+ end
11
+
12
+ def test_ancestors_search
13
+ html = %q{
14
+ <div>
15
+ <ul>
16
+ <li>foo</li>
17
+ </ul>
18
+ </div>
19
+ }
20
+ fragment = Nokogiri::HTML.fragment html
21
+ li = fragment.at('li')
22
+ assert li.matches?('li')
23
+ end
24
+
25
+ def test_fun_encoding
26
+ string = %Q(<body>こんにちは</body>)
27
+ html = Nokogiri::HTML::DocumentFragment.parse(
28
+ string
29
+ ).to_html(:encoding => 'UTF-8')
30
+ assert_equal string, html
31
+ end
32
+
33
+ def test_new
34
+ fragment = Nokogiri::HTML::DocumentFragment.new(@html)
35
+ end
36
+
37
+ def test_fragment_should_have_document
38
+ fragment = Nokogiri::HTML::DocumentFragment.new(@html)
39
+ assert_equal @html, fragment.document
40
+ end
41
+
42
+ def test_empty_fragment_should_be_searchable_by_css
43
+ fragment = Nokogiri::HTML.fragment("")
44
+ assert_equal 0, fragment.css("a").size
45
+ end
46
+
47
+ def test_empty_fragment_should_be_searchable
48
+ fragment = Nokogiri::HTML.fragment("")
49
+ assert_equal 0, fragment.search("//a").size
50
+ end
51
+
52
+ def test_name
53
+ fragment = Nokogiri::HTML::DocumentFragment.new(@html)
54
+ assert_equal '#document-fragment', fragment.name
55
+ end
56
+
57
+ def test_static_method
58
+ fragment = Nokogiri::HTML::DocumentFragment.parse("<div>a</div>")
59
+ assert_instance_of Nokogiri::HTML::DocumentFragment, fragment
60
+ end
61
+
62
+ def test_many_fragments
63
+ 100.times { Nokogiri::HTML::DocumentFragment.new(@html) }
64
+ end
65
+
66
+ def test_subclass
67
+ klass = Class.new(Nokogiri::HTML::DocumentFragment)
68
+ fragment = klass.new(@html, "<div>a</div>")
69
+ assert_instance_of klass, fragment
70
+ end
71
+
72
+ def test_subclass_parse
73
+ klass = Class.new(Nokogiri::HTML::DocumentFragment)
74
+ doc = klass.parse("<div>a</div>")
75
+ assert_instance_of klass, doc
76
+ end
77
+
78
+ def test_html_fragment
79
+ fragment = Nokogiri::HTML.fragment("<div>a</div>")
80
+ assert_equal "<div>a</div>", fragment.to_s
81
+ end
82
+
83
+ def test_html_fragment_has_outer_text
84
+ doc = "a<div>b</div>c"
85
+ fragment = Nokogiri::HTML::Document.new.fragment(doc)
86
+ if Nokogiri.uses_libxml? &&
87
+ Nokogiri::VERSION_INFO['libxml']['loaded'] <= "2.6.16"
88
+ assert_equal "a<div>b</div><p>c</p>", fragment.to_s
89
+ else
90
+ assert_equal "a<div>b</div>c", fragment.to_s
91
+ end
92
+ end
93
+
94
+ def test_html_fragment_case_insensitivity
95
+ doc = "<crazyDiv>b</crazyDiv>"
96
+ fragment = Nokogiri::HTML::Document.new.fragment(doc)
97
+ assert_equal "<crazydiv>b</crazydiv>", fragment.to_s
98
+ end
99
+
100
+ def test_html_fragment_with_leading_whitespace
101
+ doc = " <div>b</div> "
102
+ fragment = Nokogiri::HTML::Document.new.fragment(doc)
103
+ assert_equal "<div>b</div>", fragment.to_s
104
+ end
105
+
106
+ def test_html_fragment_with_leading_whitespace_and_newline
107
+ doc = " \n<div>b</div> "
108
+ fragment = Nokogiri::HTML::Document.new.fragment(doc)
109
+ assert_equal "<div>b</div>", fragment.to_s
110
+ end
111
+
112
+ def test_to_s
113
+ doc = "<span>foo<br></span><span>bar</span>"
114
+ fragment = Nokogiri::HTML::Document.new.fragment(doc)
115
+ assert_equal "<span>foo<br></span><span>bar</span>", fragment.to_s
116
+ end
117
+
118
+ def test_to_html
119
+ doc = "<span>foo<br></span><span>bar</span>"
120
+ fragment = Nokogiri::HTML::Document.new.fragment(doc)
121
+ assert_equal "<span>foo<br></span><span>bar</span>", fragment.to_html
122
+ end
123
+
124
+ def test_to_xhtml
125
+ doc = "<span>foo<br></span><span>bar</span>"
126
+ fragment = Nokogiri::HTML::Document.new.fragment(doc)
127
+ if !Nokogiri.uses_libxml? ||
128
+ Nokogiri::VERSION_INFO['libxml']['loaded'] >= "2.7.0"
129
+ assert_equal "<span>foo<br /></span><span>bar</span>", fragment.to_xhtml
130
+ else
131
+ assert_equal "<span>foo<br></span><span>bar</span>", fragment.to_xhtml
132
+ end
133
+ end
134
+
135
+ def test_to_xml
136
+ doc = "<span>foo<br></span><span>bar</span>"
137
+ fragment = Nokogiri::HTML::Document.new.fragment(doc)
138
+ assert_equal "<span>foo<br/></span><span>bar</span>", fragment.to_xml
139
+ end
140
+
141
+ def test_fragment_script_tag_with_cdata
142
+ doc = HTML::Document.new
143
+ fragment = doc.fragment("<script>var foo = 'bar';</script>")
144
+ assert_equal("<script>var foo = 'bar';</script>",
145
+ fragment.to_s)
146
+ end
147
+
148
+ def test_fragment_with_comment
149
+ doc = HTML::Document.new
150
+ fragment = doc.fragment("<p>hello<!-- your ad here --></p>")
151
+ assert_equal("<p>hello<!-- your ad here --></p>",
152
+ fragment.to_s)
153
+ end
154
+
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,98 @@
1
+ require "helper"
2
+
3
+ module Nokogiri
4
+ module HTML
5
+ class TestElementDescription < Nokogiri::TestCase
6
+ def test_fetch_nonexistent
7
+ assert_nil ElementDescription['foo']
8
+ end
9
+
10
+ def test_fetch_element_description
11
+ assert desc = ElementDescription['a']
12
+ assert_instance_of ElementDescription, desc
13
+ end
14
+
15
+ def test_name
16
+ assert_equal 'a', ElementDescription['a'].name
17
+ end
18
+
19
+ def test_implied_start_tag?
20
+ assert !ElementDescription['a'].implied_start_tag?
21
+ end
22
+
23
+ def test_implied_end_tag?
24
+ assert !ElementDescription['a'].implied_end_tag?
25
+ assert ElementDescription['p'].implied_end_tag?
26
+ end
27
+
28
+ def test_save_end_tag?
29
+ assert !ElementDescription['a'].save_end_tag?
30
+ assert ElementDescription['br'].save_end_tag?
31
+ end
32
+
33
+ def test_empty?
34
+ assert ElementDescription['br'].empty?
35
+ assert !ElementDescription['a'].empty?
36
+ end
37
+
38
+ def test_deprecated?
39
+ assert ElementDescription['applet'].deprecated?
40
+ assert !ElementDescription['br'].deprecated?
41
+ end
42
+
43
+ def test_inline?
44
+ assert ElementDescription['a'].inline?
45
+ assert !ElementDescription['div'].inline?
46
+ end
47
+
48
+ def test_block?
49
+ element = ElementDescription['a']
50
+ assert_equal(!element.inline?, element.block?)
51
+ end
52
+
53
+ def test_description
54
+ assert ElementDescription['a'].description
55
+ end
56
+
57
+ def test_subelements
58
+ sub_elements = ElementDescription['body'].sub_elements
59
+ if Nokogiri.uses_libxml?
60
+ assert_equal 61, sub_elements.length
61
+ else
62
+ assert sub_elements.length > 0
63
+ end
64
+ end
65
+
66
+ def test_default_sub_element
67
+ assert_equal 'div', ElementDescription['body'].default_sub_element
68
+ end
69
+
70
+ def test_optional_attributes
71
+ attrs = ElementDescription['table'].optional_attributes
72
+ assert attrs
73
+ end
74
+
75
+ def test_deprecated_attributes
76
+ attrs = ElementDescription['table'].deprecated_attributes
77
+ assert attrs
78
+ assert_equal 2, attrs.length
79
+ end
80
+
81
+ def test_required_attributes
82
+ attrs = ElementDescription['table'].required_attributes
83
+ assert attrs
84
+ assert_equal 0, attrs.length
85
+ end
86
+
87
+ def test_inspect
88
+ desc = ElementDescription['input']
89
+ assert_match desc.name, desc.inspect
90
+ end
91
+
92
+ def test_to_s
93
+ desc = ElementDescription['input']
94
+ assert_match desc.name, desc.to_s
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,14 @@
1
+ require "helper"
2
+
3
+ module Nokogiri
4
+ module HTML
5
+ class TestNamedCharacters < Nokogiri::TestCase
6
+ def test_named_character
7
+ copy = NamedCharacters.get('copy')
8
+ assert_equal 169, NamedCharacters['copy']
9
+ assert_equal copy.value, NamedCharacters['copy']
10
+ assert copy.description
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,242 @@
1
+ require "helper"
2
+
3
+ require 'nkf'
4
+
5
+ module Nokogiri
6
+ module HTML
7
+ class TestNode < Nokogiri::TestCase
8
+ def setup
9
+ super
10
+ @html = Nokogiri::HTML(<<-eohtml)
11
+ <html>
12
+ <head></head>
13
+ <body>
14
+ <div class='baz'><a href="foo" class="bar">first</a></div>
15
+ </body>
16
+ </html>
17
+ eohtml
18
+ end
19
+
20
+ def test_attr
21
+ node = @html.at('div.baz')
22
+ assert_equal node['class'], node.attr('class')
23
+ end
24
+
25
+ def test_get_attribute
26
+ element = @html.at('div')
27
+ assert_equal 'baz', element.get_attribute('class')
28
+ assert_equal 'baz', element['class']
29
+ element['href'] = "javascript:alert(\"AGGA-KA-BOO!\")"
30
+ assert_match(/%22AGGA-KA-BOO!%22/, element.to_html)
31
+ end
32
+
33
+ def test_css_path_round_trip
34
+ doc = Nokogiri::HTML(File.read(HTML_FILE))
35
+ %w{ #header small div[2] div.post body }.each do |css_sel|
36
+ ele = doc.at css_sel
37
+ assert_equal ele, doc.at(ele.css_path), ele.css_path
38
+ end
39
+ end
40
+
41
+ def test_path_round_trip
42
+ doc = Nokogiri::HTML(File.read(HTML_FILE))
43
+ %w{ #header small div[2] div.post body }.each do |css_sel|
44
+ ele = doc.at css_sel
45
+ assert_equal ele, doc.at(ele.path), ele.path
46
+ end
47
+ end
48
+
49
+ def test_append_with_document
50
+ assert_raises(ArgumentError) do
51
+ @html.root << Nokogiri::HTML::Document.new
52
+ end
53
+ end
54
+
55
+ ###
56
+ # Make sure a document that doesn't declare a meta encoding returns
57
+ # nil.
58
+ def test_meta_encoding
59
+ assert_nil @html.meta_encoding
60
+ end
61
+
62
+ def test_description
63
+ assert desc = @html.at('a.bar').description
64
+ assert_equal 'a', desc.name
65
+ end
66
+
67
+ def test_add_next_sibling_with_empty_nodeset
68
+ assert_raises(ArgumentError) {
69
+ @html.at('a').add_next_sibling(@html.at('head').children)
70
+ }
71
+ end
72
+
73
+ def test_add_next_sibling_with_non_empty_nodeset
74
+ assert_raises(ArgumentError) {
75
+ @html.at('head').add_next_sibling(@html.at('div').children)
76
+ }
77
+ end
78
+
79
+ def test_ancestors_with_selector
80
+ assert node = @html.at('a.bar').child
81
+ assert list = node.ancestors('.baz')
82
+ assert_equal 1, list.length
83
+ assert_equal 'div', list.first.name
84
+ end
85
+
86
+ def test_matches_inside_fragment
87
+ fragment = DocumentFragment.new @html
88
+ fragment << XML::Node.new('a', @html)
89
+
90
+ a = fragment.children.last
91
+ assert a.matches?('a'), 'a should match'
92
+ end
93
+
94
+ def test_css_matches?
95
+ assert node = @html.at('a.bar')
96
+ assert node.matches?('a.bar')
97
+ end
98
+
99
+ def test_xpath_matches?
100
+ assert node = @html.at('//a')
101
+ assert node.matches?('//a')
102
+ end
103
+
104
+ def test_unlink_then_swap
105
+ node = @html.at('a')
106
+ node.unlink
107
+
108
+ another_node = @html.at('div')
109
+ assert another_node, 'should have a node'
110
+
111
+ # This used to segv
112
+ assert_nothing_raised do
113
+ node.add_previous_sibling another_node
114
+ end
115
+ end
116
+
117
+ def test_swap
118
+ @html.at('div').swap('<a href="foo">bar</a>')
119
+ a_tag = @html.css('a').first
120
+ assert_equal 'body', a_tag.parent.name
121
+ assert_equal 0, @html.css('div').length
122
+ end
123
+
124
+ def test_swap_with_regex_characters
125
+ @html.at('div').swap('<a href="foo">ba)r</a>')
126
+ a_tag = @html.css('a').first
127
+ assert_equal 'ba)r', a_tag.text
128
+ end
129
+
130
+ def test_attribute_decodes_entities
131
+ node = @html.at('div')
132
+ node['href'] = 'foo&bar'
133
+ assert_equal 'foo&bar', node['href']
134
+ node['href'] += '&baz'
135
+ assert_equal 'foo&bar&baz', node['href']
136
+ end
137
+
138
+
139
+ def test_before_will_prepend_text_nodes
140
+ assert node = @html.at('//body').children.first
141
+ node.before "some text"
142
+ assert_equal 'some text', @html.at('//body').children[0].content.strip
143
+ end
144
+
145
+ def test_before
146
+ @html.at('//div').before('<a href="awesome">town</a>')
147
+ assert_equal 'awesome', @html.at('//div').previous['href']
148
+ end
149
+
150
+ def test_fragment_handler_does_not_regurge_on_invalid_attributes
151
+ iframe = %Q{<iframe style="width: 0%; height: 0px" src="http://someurl" allowtransparency></iframe>}
152
+ assert_nothing_raised { @html.at('div').before(iframe) }
153
+ assert_nothing_raised { @html.at('div').after(iframe) }
154
+ assert_nothing_raised { @html.at('div').inner_html=(iframe) }
155
+ end
156
+
157
+ def test_inner_html=
158
+ assert div = @html.at('//div')
159
+ div.inner_html = '1<span>2</span>3'
160
+ assert_equal '1', div.children[0].to_s
161
+ assert_equal 'span', div.children[1].name
162
+ assert_equal '2', div.children[1].inner_text
163
+ assert_equal '3', div.children[2].to_s
164
+
165
+ div.inner_html = 'testing'
166
+ assert_equal 'testing', div.content
167
+ end
168
+
169
+ def test_fragment
170
+ fragment = @html.fragment(<<-eohtml)
171
+ hello
172
+ <div class="foo">
173
+ <p>bar</p>
174
+ </div>
175
+ world
176
+ eohtml
177
+ assert_match(/^hello/, fragment.inner_html.strip)
178
+ assert_equal 3, fragment.children.length
179
+ assert p_tag = fragment.css('p').first
180
+ assert_equal 'div', p_tag.parent.name
181
+ assert_equal 'foo', p_tag.parent['class']
182
+ end
183
+
184
+ def test_fragment_serialization
185
+ fragment = Nokogiri::HTML.fragment("<div>foo</div>")
186
+ assert_equal "<div>foo</div>", fragment.serialize.chomp
187
+ assert_equal "<div>foo</div>", fragment.to_xml.chomp
188
+ assert_equal "<div>foo</div>", fragment.inner_html
189
+ assert_equal "<div>foo</div>", fragment.to_html
190
+ assert_equal "<div>foo</div>", fragment.to_s
191
+ end
192
+
193
+ def test_after_will_append_text_nodes
194
+ assert node = @html.at('//body/div')
195
+ node.after "some text"
196
+ assert_equal 'some text', node.next.text.strip
197
+ end
198
+
199
+ def test_after
200
+ @html.at('//div').after('<a href="awesome">town</a>')
201
+ assert_equal 'awesome', @html.at('//div').next['href']
202
+ end
203
+
204
+ def test_replace
205
+ doc = Nokogiri::HTML(<<-eohtml)
206
+ <html>
207
+ <head></head>
208
+ <body>
209
+ <center><img src='logo.gif' /></center>
210
+ </body>
211
+ </html>
212
+ eohtml
213
+ center = doc.at("//center")
214
+ img = center.search("//img")
215
+ assert_raises ArgumentError do
216
+ center.replace img
217
+ end
218
+ end
219
+
220
+ def test_to_html_does_not_contain_entities
221
+ return unless defined?(NKF) # NKF is not implemented on Rubinius as of 2009-11-23
222
+ html = NKF.nkf("-e --msdos", <<-EOH)
223
+ <html><body>
224
+ <p> test paragraph
225
+ foo bar </p>
226
+ </body></html>
227
+ EOH
228
+ nokogiri = Nokogiri::HTML.parse(html)
229
+
230
+ if RUBY_PLATFORM =~ /java/
231
+ # NKF linebreak modes are not supported as of jruby 1.2
232
+ # see http://jira.codehaus.org/browse/JRUBY-3602 for status
233
+ assert_equal "<p>testparagraph\nfoobar</p>",
234
+ nokogiri.at("p").to_html.gsub(/ /, '')
235
+ else
236
+ assert_equal "<p>testparagraph\r\nfoobar</p>",
237
+ nokogiri.at("p").to_html.gsub(/ /, '')
238
+ end
239
+ end
240
+ end
241
+ end
242
+ end