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,20 @@
1
+ require "helper"
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class Node
6
+ class TestSaveOptions < Nokogiri::TestCase
7
+ SaveOptions.constants.each do |constant|
8
+ class_eval %{
9
+ def test_predicate_#{constant.downcase}
10
+ options = SaveOptions.new(SaveOptions::#{constant})
11
+ assert options.#{constant.downcase}?
12
+
13
+ assert SaveOptions.new.#{constant.downcase}.#{constant.downcase}?
14
+ end
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,44 @@
1
+ require "helper"
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class Node
6
+ class TestSubclass < Nokogiri::TestCase
7
+ {
8
+ Nokogiri::XML::CDATA => 'doc, "foo"',
9
+ Nokogiri::XML::Attr => 'doc, "foo"',
10
+ Nokogiri::XML::Comment => 'doc, "foo"',
11
+ Nokogiri::XML::EntityReference => 'doc, "foo"',
12
+ Nokogiri::XML::ProcessingInstruction => 'doc, "foo", "bar"',
13
+ Nokogiri::XML::DocumentFragment => 'doc',
14
+ Nokogiri::XML::Node => '"foo", doc',
15
+ Nokogiri::XML::Text => '"foo", doc',
16
+ }.each do |klass, constructor|
17
+ class_eval %{
18
+ def test_subclass_#{klass.name.gsub('::', '_')}
19
+ doc = Nokogiri::XML::Document.new
20
+ klass = Class.new(#{klass.name})
21
+ node = klass.new(#{constructor})
22
+ assert_instance_of klass, node
23
+ end
24
+ }
25
+
26
+ class_eval <<-eocode, __FILE__, __LINE__ + 1
27
+ def test_subclass_initialize_#{klass.name.gsub('::', '_')}
28
+ doc = Nokogiri::XML::Document.new
29
+ klass = Class.new(#{klass.name}) do
30
+ attr_accessor :initialized_with
31
+
32
+ def initialize *args
33
+ @initialized_with = args
34
+ end
35
+ end
36
+ node = klass.new(#{constructor}, 1)
37
+ assert_equal [#{constructor}, 1], node.initialized_with
38
+ end
39
+ eocode
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,314 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "helper"
4
+
5
+ module Nokogiri
6
+ module XML
7
+ module SAX
8
+ class TestParser < Nokogiri::SAX::TestCase
9
+ def setup
10
+ super
11
+ @parser = XML::SAX::Parser.new(Doc.new)
12
+ end
13
+
14
+ def test_parser_context_yielded_io
15
+ doc = Doc.new
16
+ parser = XML::SAX::Parser.new doc
17
+ xml = "<foo a='&amp;b'/>"
18
+
19
+ block_called = false
20
+ parser.parse(StringIO.new(xml)) { |ctx|
21
+ block_called = true
22
+ ctx.replace_entities = true
23
+ }
24
+
25
+ assert block_called
26
+
27
+ assert_equal ['a', '&b'], doc.start_elements.first.last
28
+ end
29
+
30
+ def test_parser_context_yielded_in_memory
31
+ doc = Doc.new
32
+ parser = XML::SAX::Parser.new doc
33
+ xml = "<foo a='&amp;b'/>"
34
+
35
+ block_called = false
36
+ parser.parse(xml) { |ctx|
37
+ block_called = true
38
+ ctx.replace_entities = true
39
+ }
40
+
41
+ assert block_called
42
+
43
+ assert_equal ['a', '&b'], doc.start_elements.first.last
44
+ end
45
+
46
+ def test_xml_decl
47
+ {
48
+ '' => nil,
49
+ '<?xml version="1.0" ?>' => ['1.0'],
50
+ '<?xml version="1.0" encoding="UTF-8" ?>' => ['1.0', 'UTF-8'],
51
+ '<?xml version="1.0" standalone="yes"?>' => ['1.0', 'yes'],
52
+ '<?xml version="1.0" standalone="no"?>' => ['1.0', 'no'],
53
+ }.each do |decl,value|
54
+ parser = XML::SAX::Parser.new(Doc.new)
55
+
56
+ xml = "#{decl}\n<root />"
57
+ parser.parse xml
58
+ assert parser.document.start_document_called, xml
59
+ assert_equal value, parser.document.xmldecls, xml
60
+ end
61
+ end
62
+
63
+ def test_parse_empty
64
+ assert_raises RuntimeError do
65
+ @parser.parse('')
66
+ end
67
+ end
68
+
69
+ def test_namespace_declaration_order_is_saved
70
+ @parser.parse <<-eoxml
71
+ <root xmlns:foo='http://foo.example.com/' xmlns='http://example.com/'>
72
+ <a foo:bar='hello' />
73
+ </root>
74
+ eoxml
75
+ assert_equal 2, @parser.document.start_elements_namespace.length
76
+ el = @parser.document.start_elements_namespace.first
77
+ namespaces = el.last
78
+ assert_equal ['foo', 'http://foo.example.com/'], namespaces.first
79
+ assert_equal [nil, 'http://example.com/'], namespaces.last
80
+ end
81
+
82
+ def test_bad_document_calls_error_handler
83
+ @parser.parse('<foo><bar></foo>')
84
+ assert @parser.document.errors
85
+ assert @parser.document.errors.length > 0
86
+ end
87
+
88
+ def test_namespace_are_super_fun_to_parse
89
+ @parser.parse <<-eoxml
90
+ <root xmlns:foo='http://foo.example.com/'>
91
+ <a foo:bar='hello' />
92
+ <b xmlns:foo='http://bar.example.com/'>
93
+ <a foo:bar='hello' />
94
+ </b>
95
+ <foo:bar>hello world</foo:bar>
96
+ </root>
97
+ eoxml
98
+
99
+ assert @parser.document.start_elements_namespace.length > 0
100
+ el = @parser.document.start_elements_namespace[1]
101
+ assert_equal 'a', el.first
102
+ assert_equal 1, el[1].length
103
+
104
+ attribute = el[1].first
105
+ assert_equal 'bar', attribute.localname
106
+ assert_equal 'foo', attribute.prefix
107
+ assert_equal 'hello', attribute.value
108
+ assert_equal 'http://foo.example.com/', attribute.uri
109
+ end
110
+
111
+ def test_sax_v1_namespace_attribute_declarations
112
+ @parser.parse <<-eoxml
113
+ <root xmlns:foo='http://foo.example.com/' xmlns='http://example.com/'>
114
+ <a foo:bar='hello' />
115
+ <b xmlns:foo='http://bar.example.com/'>
116
+ <a foo:bar='hello' />
117
+ </b>
118
+ <foo:bar>hello world</foo:bar>
119
+ </root>
120
+ eoxml
121
+ assert @parser.document.start_elements.length > 0
122
+ elm = @parser.document.start_elements.first
123
+ assert_equal 'root', elm.first
124
+ assert elm[1].include?(['xmlns:foo', 'http://foo.example.com/'])
125
+ assert elm[1].include?(['xmlns', 'http://example.com/'])
126
+ end
127
+
128
+ def test_sax_v1_namespace_nodes
129
+ @parser.parse <<-eoxml
130
+ <root xmlns:foo='http://foo.example.com/' xmlns='http://example.com/'>
131
+ <a foo:bar='hello' />
132
+ <b xmlns:foo='http://bar.example.com/'>
133
+ <a foo:bar='hello' />
134
+ </b>
135
+ <foo:bar>hello world</foo:bar>
136
+ </root>
137
+ eoxml
138
+ assert_equal 5, @parser.document.start_elements.length
139
+ assert @parser.document.start_elements.map { |se|
140
+ se.first
141
+ }.include?('foo:bar')
142
+ assert @parser.document.end_elements.map { |se|
143
+ se.first
144
+ }.include?('foo:bar')
145
+ end
146
+
147
+ def test_start_is_called_without_namespace
148
+ @parser.parse(<<-eoxml)
149
+ <root xmlns:foo='http://foo.example.com/' xmlns='http://example.com/'>
150
+ <foo:f><bar></foo:f>
151
+ </root>
152
+ eoxml
153
+ assert_equal ['root', 'foo:f', 'bar'],
154
+ @parser.document.start_elements.map { |x| x.first }
155
+ end
156
+
157
+ def test_parser_sets_encoding
158
+ parser = XML::SAX::Parser.new(Doc.new, 'UTF-8')
159
+ assert_equal 'UTF-8', parser.encoding
160
+ end
161
+
162
+ def test_errors_set_after_parsing_bad_dom
163
+ doc = Nokogiri::XML('<foo><bar></foo>')
164
+ assert doc.errors
165
+
166
+ @parser.parse('<foo><bar></foo>')
167
+ assert @parser.document.errors
168
+ assert @parser.document.errors.length > 0
169
+
170
+ if RUBY_VERSION =~ /^1\.9/
171
+ doc.errors.each do |error|
172
+ assert_equal 'UTF-8', error.message.encoding.name
173
+ end
174
+ end
175
+
176
+ assert_equal doc.errors.length, @parser.document.errors.length
177
+ end
178
+
179
+ def test_parse_with_memory_argument
180
+ @parser.parse(File.read(XML_FILE))
181
+ assert(@parser.document.cdata_blocks.length > 0)
182
+ end
183
+
184
+ def test_parse_with_io_argument
185
+ File.open(XML_FILE, 'rb') { |f|
186
+ @parser.parse(f)
187
+ }
188
+ assert(@parser.document.cdata_blocks.length > 0)
189
+ end
190
+
191
+ def test_parse_io
192
+ File.open(XML_FILE, 'rb') { |f|
193
+ @parser.parse_io(f, 'UTF-8')
194
+ }
195
+ assert(@parser.document.cdata_blocks.length > 0)
196
+ if RUBY_VERSION =~ /^1\.9/
197
+ called = false
198
+ @parser.document.start_elements.flatten.each do |thing|
199
+ assert_equal 'UTF-8', thing.encoding.name
200
+ called = true
201
+ end
202
+ assert called
203
+
204
+ called = false
205
+ @parser.document.end_elements.flatten.each do |thing|
206
+ assert_equal 'UTF-8', thing.encoding.name
207
+ called = true
208
+ end
209
+ assert called
210
+
211
+ called = false
212
+ @parser.document.data.each do |thing|
213
+ assert_equal 'UTF-8', thing.encoding.name
214
+ called = true
215
+ end
216
+ assert called
217
+
218
+ called = false
219
+ @parser.document.comments.flatten.each do |thing|
220
+ assert_equal 'UTF-8', thing.encoding.name
221
+ called = true
222
+ end
223
+ assert called
224
+
225
+ called = false
226
+ @parser.document.cdata_blocks.flatten.each do |thing|
227
+ assert_equal 'UTF-8', thing.encoding.name
228
+ called = true
229
+ end
230
+ assert called
231
+ end
232
+ end
233
+
234
+ def test_parse_file
235
+ @parser.parse_file(XML_FILE)
236
+
237
+ assert_raises(ArgumentError) {
238
+ @parser.parse_file(nil)
239
+ }
240
+
241
+ assert_raises(Errno::ENOENT) {
242
+ @parser.parse_file('')
243
+ }
244
+ assert_raises(Errno::EISDIR) {
245
+ @parser.parse_file(File.expand_path(File.dirname(__FILE__)))
246
+ }
247
+ end
248
+
249
+ def test_render_parse_nil_param
250
+ assert_raises(ArgumentError) { @parser.parse_memory(nil) }
251
+ end
252
+
253
+ def test_ctag
254
+ @parser.parse_memory(<<-eoxml)
255
+ <p id="asdfasdf">
256
+ <![CDATA[ This is a comment ]]>
257
+ Paragraph 1
258
+ </p>
259
+ eoxml
260
+ assert_equal [' This is a comment '], @parser.document.cdata_blocks
261
+ end
262
+
263
+ def test_comment
264
+ @parser.parse_memory(<<-eoxml)
265
+ <p id="asdfasdf">
266
+ <!-- This is a comment -->
267
+ Paragraph 1
268
+ </p>
269
+ eoxml
270
+ assert_equal [' This is a comment '], @parser.document.comments
271
+ end
272
+
273
+ def test_characters
274
+ @parser.parse_memory(<<-eoxml)
275
+ <p id="asdfasdf">Paragraph 1</p>
276
+ eoxml
277
+ assert_equal ['Paragraph 1'], @parser.document.data
278
+ end
279
+
280
+ def test_end_document
281
+ @parser.parse_memory(<<-eoxml)
282
+ <p id="asdfasdf">Paragraph 1</p>
283
+ eoxml
284
+ assert @parser.document.end_document_called
285
+ end
286
+
287
+ def test_end_element
288
+ @parser.parse_memory(<<-eoxml)
289
+ <p id="asdfasdf">Paragraph 1</p>
290
+ eoxml
291
+ assert_equal [["p"]],
292
+ @parser.document.end_elements
293
+ end
294
+
295
+ def test_start_element_attrs
296
+ @parser.parse_memory(<<-eoxml)
297
+ <p id="asdfasdf">Paragraph 1</p>
298
+ eoxml
299
+ assert_equal [["p", ["id", "asdfasdf"]]],
300
+ @parser.document.start_elements
301
+ end
302
+
303
+ if Nokogiri.uses_libxml? # JRuby SAXParser only parses well-formed XML documents
304
+ def test_parse_document
305
+ @parser.parse_memory(<<-eoxml)
306
+ <p>Paragraph 1</p>
307
+ <p>Paragraph 2</p>
308
+ eoxml
309
+ end
310
+ end
311
+ end
312
+ end
313
+ end
314
+ end
@@ -0,0 +1,63 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "helper"
4
+
5
+ module Nokogiri
6
+ module XML
7
+ module SAX
8
+ class TestParserContext < Nokogiri::SAX::TestCase
9
+ def test_replace_entities
10
+ pc = ParserContext.new StringIO.new('<root />'), 'UTF-8'
11
+ pc.replace_entities = false
12
+ assert_equal false, pc.replace_entities
13
+
14
+ pc.replace_entities = true
15
+ assert_equal true, pc.replace_entities
16
+ end
17
+
18
+ def test_from_io
19
+ assert_nothing_raised do
20
+ ParserContext.new StringIO.new('fo'), 'UTF-8'
21
+ end
22
+ end
23
+
24
+ def test_from_string
25
+ assert_nothing_raised do
26
+ ParserContext.new 'blah blah'
27
+ end
28
+ end
29
+
30
+ def test_parse_with
31
+ ctx = ParserContext.new 'blah'
32
+ assert_raises ArgumentError do
33
+ ctx.parse_with nil
34
+ end
35
+ end
36
+
37
+ def test_parse_with_sax_parser
38
+ assert_nothing_raised do
39
+ xml = "<root />"
40
+ ctx = ParserContext.new xml
41
+ parser = Parser.new Doc.new
42
+ ctx.parse_with parser
43
+ end
44
+ end
45
+
46
+ def test_from_file
47
+ assert_nothing_raised do
48
+ ctx = ParserContext.file XML_FILE
49
+ parser = Parser.new Doc.new
50
+ ctx.parse_with parser
51
+ end
52
+ end
53
+
54
+ def test_parse_with_returns_nil
55
+ xml = "<root />"
56
+ ctx = ParserContext.new xml
57
+ parser = Parser.new Doc.new
58
+ assert_nil ctx.parse_with parser
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,135 @@
1
+ require "helper"
2
+
3
+ module Nokogiri
4
+ module XML
5
+ module SAX
6
+ class TestPushParser < Nokogiri::SAX::TestCase
7
+ def setup
8
+ super
9
+ @parser = XML::SAX::PushParser.new(Doc.new)
10
+ end
11
+
12
+ def test_exception
13
+ assert_raises(SyntaxError) do
14
+ @parser << "<foo /><foo />"
15
+ end
16
+
17
+ assert_raises(SyntaxError) do
18
+ @parser << nil
19
+ end
20
+ end
21
+
22
+ def test_end_document_called
23
+ @parser.<<(<<-eoxml)
24
+ <p id="asdfasdf">
25
+ <!-- This is a comment -->
26
+ Paragraph 1
27
+ </p>
28
+ eoxml
29
+ assert ! @parser.document.end_document_called
30
+ @parser.finish
31
+ assert @parser.document.end_document_called
32
+ end
33
+
34
+ def test_start_element
35
+ @parser.<<(<<-eoxml)
36
+ <p id="asdfasdf">
37
+ eoxml
38
+
39
+ assert_equal [["p", ["id", "asdfasdf"]]],
40
+ @parser.document.start_elements
41
+
42
+ @parser.<<(<<-eoxml)
43
+ <!-- This is a comment -->
44
+ Paragraph 1
45
+ </p>
46
+ eoxml
47
+ assert_equal [' This is a comment '], @parser.document.comments
48
+ @parser.finish
49
+ end
50
+
51
+ def test_start_element_ns
52
+ @parser.<<(<<-eoxml)
53
+ <stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' size='large'></stream:stream>
54
+ eoxml
55
+
56
+ assert_equal 1, @parser.document.start_elements_namespace.length
57
+ el = @parser.document.start_elements_namespace.first
58
+
59
+ assert_equal 'stream', el.first
60
+ assert_equal 2, el[1].length
61
+ assert_equal [['version', '1.0'], ['size', 'large']],
62
+ el[1].map { |x| [x.localname, x.value] }
63
+
64
+ assert_equal 'stream', el[2]
65
+ assert_equal 'http://etherx.jabber.org/streams', el[3]
66
+ @parser.finish
67
+ end
68
+
69
+ def test_end_element_ns
70
+ @parser.<<(<<-eoxml)
71
+ <stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'></stream:stream>
72
+ eoxml
73
+
74
+ assert_equal [['stream', 'stream', 'http://etherx.jabber.org/streams']],
75
+ @parser.document.end_elements_namespace
76
+ @parser.finish
77
+ end
78
+
79
+ def test_chevron_partial_xml
80
+ @parser.<<(<<-eoxml)
81
+ <p id="asdfasdf">
82
+ eoxml
83
+
84
+ @parser.<<(<<-eoxml)
85
+ <!-- This is a comment -->
86
+ Paragraph 1
87
+ </p>
88
+ eoxml
89
+ assert_equal [' This is a comment '], @parser.document.comments
90
+ @parser.finish
91
+ end
92
+
93
+ def test_chevron
94
+ @parser.<<(<<-eoxml)
95
+ <p id="asdfasdf">
96
+ <!-- This is a comment -->
97
+ Paragraph 1
98
+ </p>
99
+ eoxml
100
+ @parser.finish
101
+ assert_equal [' This is a comment '], @parser.document.comments
102
+ end
103
+
104
+ def test_default_options
105
+ assert_equal 0, @parser.options
106
+ end
107
+
108
+ def test_recover
109
+ @parser.options |= XML::ParseOptions::RECOVER
110
+ @parser.<<(<<-eoxml)
111
+ <p>
112
+ Foo
113
+ <bar>
114
+ Bar
115
+ </p>
116
+ eoxml
117
+ @parser.finish
118
+ assert(@parser.document.errors.size >= 1)
119
+ assert_equal [["p", []], ["bar", []]], @parser.document.start_elements
120
+ assert_equal "FooBar", @parser.document.data.to_s.gsub(/\s/, '')
121
+ end
122
+
123
+ def test_broken_encoding
124
+ @parser.options |= XML::ParseOptions::RECOVER
125
+ # This is ISO_8859-1:
126
+ @parser.<< "<?xml version='1.0' encoding='UTF-8'?><r>Gau\337</r>"
127
+ @parser.finish
128
+ assert(@parser.document.errors.size >= 1)
129
+ assert_equal "Gau\337", @parser.document.data.to_s
130
+ assert_equal [["r"]], @parser.document.end_elements
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end