nokogiri-backupify 1.5.0.beta.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. data/.autotest +26 -0
  2. data/CHANGELOG.ja.rdoc +509 -0
  3. data/CHANGELOG.rdoc +490 -0
  4. data/Manifest.txt +274 -0
  5. data/README.ja.rdoc +106 -0
  6. data/README.rdoc +150 -0
  7. data/Rakefile +217 -0
  8. data/bin/nokogiri +54 -0
  9. data/deps.rip +5 -0
  10. data/ext/java/nokogiri/EncodingHandler.java +124 -0
  11. data/ext/java/nokogiri/HtmlDocument.java +146 -0
  12. data/ext/java/nokogiri/HtmlElementDescription.java +145 -0
  13. data/ext/java/nokogiri/HtmlEntityLookup.java +79 -0
  14. data/ext/java/nokogiri/HtmlSaxParserContext.java +256 -0
  15. data/ext/java/nokogiri/NokogiriService.java +466 -0
  16. data/ext/java/nokogiri/XmlAttr.java +183 -0
  17. data/ext/java/nokogiri/XmlAttributeDecl.java +130 -0
  18. data/ext/java/nokogiri/XmlCdata.java +89 -0
  19. data/ext/java/nokogiri/XmlComment.java +84 -0
  20. data/ext/java/nokogiri/XmlDocument.java +514 -0
  21. data/ext/java/nokogiri/XmlDocumentFragment.java +216 -0
  22. data/ext/java/nokogiri/XmlDtd.java +464 -0
  23. data/ext/java/nokogiri/XmlElement.java +221 -0
  24. data/ext/java/nokogiri/XmlElementContent.java +382 -0
  25. data/ext/java/nokogiri/XmlElementDecl.java +147 -0
  26. data/ext/java/nokogiri/XmlEntityDecl.java +161 -0
  27. data/ext/java/nokogiri/XmlEntityReference.java +75 -0
  28. data/ext/java/nokogiri/XmlNamespace.java +127 -0
  29. data/ext/java/nokogiri/XmlNode.java +1392 -0
  30. data/ext/java/nokogiri/XmlNodeSet.java +284 -0
  31. data/ext/java/nokogiri/XmlProcessingInstruction.java +103 -0
  32. data/ext/java/nokogiri/XmlReader.java +409 -0
  33. data/ext/java/nokogiri/XmlRelaxng.java +199 -0
  34. data/ext/java/nokogiri/XmlSaxParserContext.java +353 -0
  35. data/ext/java/nokogiri/XmlSaxPushParser.java +182 -0
  36. data/ext/java/nokogiri/XmlSchema.java +175 -0
  37. data/ext/java/nokogiri/XmlSyntaxError.java +114 -0
  38. data/ext/java/nokogiri/XmlText.java +135 -0
  39. data/ext/java/nokogiri/XmlXpathContext.java +175 -0
  40. data/ext/java/nokogiri/XsltStylesheet.java +181 -0
  41. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +205 -0
  42. data/ext/java/nokogiri/internals/NokogiriDocumentCache.java +73 -0
  43. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +80 -0
  44. data/ext/java/nokogiri/internals/NokogiriHandler.java +326 -0
  45. data/ext/java/nokogiri/internals/NokogiriHelpers.java +583 -0
  46. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +170 -0
  47. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +118 -0
  48. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +73 -0
  49. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +121 -0
  50. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +78 -0
  51. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +120 -0
  52. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +56 -0
  53. data/ext/java/nokogiri/internals/ParserContext.java +278 -0
  54. data/ext/java/nokogiri/internals/PushInputStream.java +411 -0
  55. data/ext/java/nokogiri/internals/ReaderNode.java +473 -0
  56. data/ext/java/nokogiri/internals/SaveContext.java +282 -0
  57. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +68 -0
  58. data/ext/java/nokogiri/internals/XmlDeclHandler.java +42 -0
  59. data/ext/java/nokogiri/internals/XmlDomParser.java +77 -0
  60. data/ext/java/nokogiri/internals/XmlDomParserContext.java +233 -0
  61. data/ext/java/nokogiri/internals/XmlSaxParser.java +65 -0
  62. data/ext/java/nokogiri/internals/XsltExtensionFunction.java +72 -0
  63. data/ext/nokogiri/depend +358 -0
  64. data/ext/nokogiri/extconf.rb +124 -0
  65. data/ext/nokogiri/html_document.c +154 -0
  66. data/ext/nokogiri/html_document.h +10 -0
  67. data/ext/nokogiri/html_element_description.c +276 -0
  68. data/ext/nokogiri/html_element_description.h +10 -0
  69. data/ext/nokogiri/html_entity_lookup.c +32 -0
  70. data/ext/nokogiri/html_entity_lookup.h +8 -0
  71. data/ext/nokogiri/html_sax_parser_context.c +94 -0
  72. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  73. data/ext/nokogiri/nokogiri.c +92 -0
  74. data/ext/nokogiri/nokogiri.h +160 -0
  75. data/ext/nokogiri/xml_attr.c +94 -0
  76. data/ext/nokogiri/xml_attr.h +9 -0
  77. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  78. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  79. data/ext/nokogiri/xml_cdata.c +56 -0
  80. data/ext/nokogiri/xml_cdata.h +9 -0
  81. data/ext/nokogiri/xml_comment.c +54 -0
  82. data/ext/nokogiri/xml_comment.h +9 -0
  83. data/ext/nokogiri/xml_document.c +478 -0
  84. data/ext/nokogiri/xml_document.h +23 -0
  85. data/ext/nokogiri/xml_document_fragment.c +48 -0
  86. data/ext/nokogiri/xml_document_fragment.h +10 -0
  87. data/ext/nokogiri/xml_dtd.c +202 -0
  88. data/ext/nokogiri/xml_dtd.h +10 -0
  89. data/ext/nokogiri/xml_element_content.c +123 -0
  90. data/ext/nokogiri/xml_element_content.h +10 -0
  91. data/ext/nokogiri/xml_element_decl.c +69 -0
  92. data/ext/nokogiri/xml_element_decl.h +9 -0
  93. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  94. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  95. data/ext/nokogiri/xml_entity_decl.c +110 -0
  96. data/ext/nokogiri/xml_entity_decl.h +10 -0
  97. data/ext/nokogiri/xml_entity_reference.c +52 -0
  98. data/ext/nokogiri/xml_entity_reference.h +9 -0
  99. data/ext/nokogiri/xml_io.c +31 -0
  100. data/ext/nokogiri/xml_io.h +11 -0
  101. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  102. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  103. data/ext/nokogiri/xml_namespace.c +84 -0
  104. data/ext/nokogiri/xml_namespace.h +13 -0
  105. data/ext/nokogiri/xml_node.c +1384 -0
  106. data/ext/nokogiri/xml_node.h +13 -0
  107. data/ext/nokogiri/xml_node_set.c +418 -0
  108. data/ext/nokogiri/xml_node_set.h +9 -0
  109. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  110. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  111. data/ext/nokogiri/xml_reader.c +684 -0
  112. data/ext/nokogiri/xml_reader.h +10 -0
  113. data/ext/nokogiri/xml_relax_ng.c +161 -0
  114. data/ext/nokogiri/xml_relax_ng.h +9 -0
  115. data/ext/nokogiri/xml_sax_parser.c +288 -0
  116. data/ext/nokogiri/xml_sax_parser.h +39 -0
  117. data/ext/nokogiri/xml_sax_parser_context.c +199 -0
  118. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  119. data/ext/nokogiri/xml_sax_push_parser.c +115 -0
  120. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  121. data/ext/nokogiri/xml_schema.c +205 -0
  122. data/ext/nokogiri/xml_schema.h +9 -0
  123. data/ext/nokogiri/xml_syntax_error.c +58 -0
  124. data/ext/nokogiri/xml_syntax_error.h +13 -0
  125. data/ext/nokogiri/xml_text.c +50 -0
  126. data/ext/nokogiri/xml_text.h +9 -0
  127. data/ext/nokogiri/xml_xpath_context.c +309 -0
  128. data/ext/nokogiri/xml_xpath_context.h +9 -0
  129. data/ext/nokogiri/xslt_stylesheet.c +258 -0
  130. data/ext/nokogiri/xslt_stylesheet.h +9 -0
  131. data/lib/isorelax.jar +0 -0
  132. data/lib/jing.jar +0 -0
  133. data/lib/nekodtd.jar +0 -0
  134. data/lib/nekohtml.jar +0 -0
  135. data/lib/nokogiri.rb +143 -0
  136. data/lib/nokogiri/css.rb +23 -0
  137. data/lib/nokogiri/css/node.rb +99 -0
  138. data/lib/nokogiri/css/parser.rb +677 -0
  139. data/lib/nokogiri/css/parser.y +237 -0
  140. data/lib/nokogiri/css/parser_extras.rb +91 -0
  141. data/lib/nokogiri/css/syntax_error.rb +7 -0
  142. data/lib/nokogiri/css/tokenizer.rb +152 -0
  143. data/lib/nokogiri/css/tokenizer.rex +55 -0
  144. data/lib/nokogiri/css/xpath_visitor.rb +171 -0
  145. data/lib/nokogiri/decorators/slop.rb +35 -0
  146. data/lib/nokogiri/html.rb +36 -0
  147. data/lib/nokogiri/html/builder.rb +35 -0
  148. data/lib/nokogiri/html/document.rb +221 -0
  149. data/lib/nokogiri/html/document_fragment.rb +41 -0
  150. data/lib/nokogiri/html/element_description.rb +23 -0
  151. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  152. data/lib/nokogiri/html/entity_lookup.rb +13 -0
  153. data/lib/nokogiri/html/sax/parser.rb +52 -0
  154. data/lib/nokogiri/html/sax/parser_context.rb +16 -0
  155. data/lib/nokogiri/syntax_error.rb +4 -0
  156. data/lib/nokogiri/version.rb +35 -0
  157. data/lib/nokogiri/xml.rb +67 -0
  158. data/lib/nokogiri/xml/attr.rb +14 -0
  159. data/lib/nokogiri/xml/attribute_decl.rb +18 -0
  160. data/lib/nokogiri/xml/builder.rb +418 -0
  161. data/lib/nokogiri/xml/cdata.rb +11 -0
  162. data/lib/nokogiri/xml/character_data.rb +7 -0
  163. data/lib/nokogiri/xml/document.rb +218 -0
  164. data/lib/nokogiri/xml/document_fragment.rb +84 -0
  165. data/lib/nokogiri/xml/dtd.rb +22 -0
  166. data/lib/nokogiri/xml/element_content.rb +36 -0
  167. data/lib/nokogiri/xml/element_decl.rb +13 -0
  168. data/lib/nokogiri/xml/entity_decl.rb +19 -0
  169. data/lib/nokogiri/xml/namespace.rb +13 -0
  170. data/lib/nokogiri/xml/node.rb +907 -0
  171. data/lib/nokogiri/xml/node/save_options.rb +45 -0
  172. data/lib/nokogiri/xml/node_set.rb +350 -0
  173. data/lib/nokogiri/xml/notation.rb +6 -0
  174. data/lib/nokogiri/xml/parse_options.rb +85 -0
  175. data/lib/nokogiri/xml/pp.rb +2 -0
  176. data/lib/nokogiri/xml/pp/character_data.rb +18 -0
  177. data/lib/nokogiri/xml/pp/node.rb +56 -0
  178. data/lib/nokogiri/xml/processing_instruction.rb +8 -0
  179. data/lib/nokogiri/xml/reader.rb +112 -0
  180. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  181. data/lib/nokogiri/xml/sax.rb +4 -0
  182. data/lib/nokogiri/xml/sax/document.rb +164 -0
  183. data/lib/nokogiri/xml/sax/parser.rb +115 -0
  184. data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
  185. data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
  186. data/lib/nokogiri/xml/schema.rb +57 -0
  187. data/lib/nokogiri/xml/syntax_error.rb +47 -0
  188. data/lib/nokogiri/xml/text.rb +9 -0
  189. data/lib/nokogiri/xml/xpath.rb +10 -0
  190. data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
  191. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  192. data/lib/nokogiri/xslt.rb +52 -0
  193. data/lib/nokogiri/xslt/stylesheet.rb +25 -0
  194. data/lib/xercesImpl.jar +0 -0
  195. data/lib/xsd/xmlparser/nokogiri.rb +90 -0
  196. data/tasks/cross_compile.rb +177 -0
  197. data/tasks/test.rb +94 -0
  198. data/test/css/test_nthiness.rb +159 -0
  199. data/test/css/test_parser.rb +303 -0
  200. data/test/css/test_tokenizer.rb +198 -0
  201. data/test/css/test_xpath_visitor.rb +85 -0
  202. data/test/decorators/test_slop.rb +16 -0
  203. data/test/files/2ch.html +108 -0
  204. data/test/files/address_book.rlx +12 -0
  205. data/test/files/address_book.xml +10 -0
  206. data/test/files/bar/bar.xsd +4 -0
  207. data/test/files/dont_hurt_em_why.xml +422 -0
  208. data/test/files/exslt.xml +8 -0
  209. data/test/files/exslt.xslt +35 -0
  210. data/test/files/foo/foo.xsd +4 -0
  211. data/test/files/po.xml +32 -0
  212. data/test/files/po.xsd +66 -0
  213. data/test/files/shift_jis.html +10 -0
  214. data/test/files/shift_jis.xml +5 -0
  215. data/test/files/snuggles.xml +3 -0
  216. data/test/files/staff.dtd +10 -0
  217. data/test/files/staff.xml +59 -0
  218. data/test/files/staff.xslt +32 -0
  219. data/test/files/tlm.html +850 -0
  220. data/test/files/valid_bar.xml +2 -0
  221. data/test/helper.rb +171 -0
  222. data/test/html/sax/test_parser.rb +136 -0
  223. data/test/html/sax/test_parser_context.rb +48 -0
  224. data/test/html/test_builder.rb +164 -0
  225. data/test/html/test_document.rb +457 -0
  226. data/test/html/test_document_encoding.rb +123 -0
  227. data/test/html/test_document_fragment.rb +255 -0
  228. data/test/html/test_element_description.rb +100 -0
  229. data/test/html/test_named_characters.rb +14 -0
  230. data/test/html/test_node.rb +190 -0
  231. data/test/html/test_node_encoding.rb +27 -0
  232. data/test/test_convert_xpath.rb +135 -0
  233. data/test/test_css_cache.rb +45 -0
  234. data/test/test_encoding_handler.rb +46 -0
  235. data/test/test_memory_leak.rb +52 -0
  236. data/test/test_nokogiri.rb +132 -0
  237. data/test/test_reader.rb +403 -0
  238. data/test/test_soap4r_sax.rb +52 -0
  239. data/test/test_xslt_transforms.rb +189 -0
  240. data/test/xml/node/test_save_options.rb +20 -0
  241. data/test/xml/node/test_subclass.rb +44 -0
  242. data/test/xml/sax/test_parser.rb +338 -0
  243. data/test/xml/sax/test_parser_context.rb +113 -0
  244. data/test/xml/sax/test_push_parser.rb +156 -0
  245. data/test/xml/test_attr.rb +65 -0
  246. data/test/xml/test_attribute_decl.rb +86 -0
  247. data/test/xml/test_builder.rb +210 -0
  248. data/test/xml/test_cdata.rb +50 -0
  249. data/test/xml/test_comment.rb +29 -0
  250. data/test/xml/test_document.rb +675 -0
  251. data/test/xml/test_document_encoding.rb +26 -0
  252. data/test/xml/test_document_fragment.rb +192 -0
  253. data/test/xml/test_dtd.rb +107 -0
  254. data/test/xml/test_dtd_encoding.rb +33 -0
  255. data/test/xml/test_element_content.rb +56 -0
  256. data/test/xml/test_element_decl.rb +73 -0
  257. data/test/xml/test_entity_decl.rb +122 -0
  258. data/test/xml/test_entity_reference.rb +21 -0
  259. data/test/xml/test_namespace.rb +70 -0
  260. data/test/xml/test_node.rb +899 -0
  261. data/test/xml/test_node_attributes.rb +34 -0
  262. data/test/xml/test_node_encoding.rb +107 -0
  263. data/test/xml/test_node_reparenting.rb +321 -0
  264. data/test/xml/test_node_set.rb +708 -0
  265. data/test/xml/test_parse_options.rb +52 -0
  266. data/test/xml/test_processing_instruction.rb +30 -0
  267. data/test/xml/test_reader_encoding.rb +126 -0
  268. data/test/xml/test_relax_ng.rb +60 -0
  269. data/test/xml/test_schema.rb +89 -0
  270. data/test/xml/test_syntax_error.rb +12 -0
  271. data/test/xml/test_text.rb +47 -0
  272. data/test/xml/test_unparented_node.rb +381 -0
  273. data/test/xml/test_xpath.rb +237 -0
  274. data/test/xslt/test_custom_functions.rb +94 -0
  275. metadata +525 -0
@@ -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
@@ -0,0 +1,189 @@
1
+ require "helper"
2
+
3
+ class TestXsltTransforms < Nokogiri::TestCase
4
+
5
+ def setup
6
+ @doc = Nokogiri::XML(File.open(XML_FILE))
7
+ end
8
+
9
+ if Nokogiri.uses_libxml?
10
+ def test_class_methods
11
+ style = Nokogiri::XSLT(File.read(XSLT_FILE))
12
+
13
+ assert result = style.apply_to(@doc, ['title', '"Grandma"'])
14
+ assert_match %r{<h1>Grandma</h1>}, result
15
+ end
16
+
17
+ def test_transform
18
+ assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
19
+
20
+ assert result = style.apply_to(@doc, ['title', '"Booyah"'])
21
+ assert_match %r{<h1>Booyah</h1>}, result
22
+ assert_match %r{<th.*Employee ID</th>}, result
23
+ assert_match %r{<th.*Name</th>}, result
24
+ assert_match %r{<th.*Position</th>}, result
25
+ assert_match %r{<th.*Salary</th>}, result
26
+ assert_match %r{<td>EMP0003</td>}, result
27
+ assert_match %r{<td>Margaret Martin</td>}, result
28
+ assert_match %r{<td>Computer Specialist</td>}, result
29
+ assert_match %r{<td>100,000</td>}, result
30
+ assert_no_match %r{Dallas|Texas}, result
31
+ assert_no_match %r{Female}, result
32
+
33
+ assert result = style.apply_to(@doc, ['title', '"Grandma"'])
34
+ assert_match %r{<h1>Grandma</h1>}, result
35
+
36
+ assert result = style.apply_to(@doc)
37
+ assert_match %r{<h1></h1>}, result
38
+ end
39
+
40
+ def test_transform_with_output_style
41
+ xslt = Nokogiri::XSLT(<<-eoxslt)
42
+ <?xml version="1.0" encoding="ISO-8859-1"?>
43
+
44
+ <xsl:stylesheet version="1.0"
45
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
46
+ <xsl:output method="text" version="1.0"
47
+ encoding="iso-8859-1" indent="yes"/>
48
+
49
+ <xsl:param name="title"/>
50
+
51
+ <xsl:template match="/">
52
+ <html>
53
+ <body>
54
+ <xsl:for-each select="staff/employee">
55
+ <tr>
56
+ <td><xsl:value-of select="employeeId"/></td>
57
+ <td><xsl:value-of select="name"/></td>
58
+ <td><xsl:value-of select="position"/></td>
59
+ <td><xsl:value-of select="salary"/></td>
60
+ </tr>
61
+ </xsl:for-each>
62
+ </table>
63
+ </body>
64
+ </html>
65
+ </xsl:template>
66
+
67
+ </xsl:stylesheet>
68
+ eoxslt
69
+ assert_no_match(/<td>/, xslt.apply_to(@doc, ['title', 'foo']))
70
+ end
71
+
72
+ def test_transform_arg_error
73
+ assert style = Nokogiri::XSLT(File.read(XSLT_FILE))
74
+ assert_raises(TypeError) do
75
+ style.transform(@doc, :foo)
76
+ end
77
+ end
78
+
79
+ def test_transform_with_hash
80
+ assert style = Nokogiri::XSLT(File.read(XSLT_FILE))
81
+ result = style.transform(@doc, {'title' => '"Booyah"'})
82
+ assert result.html?
83
+ assert_equal "Booyah", result.at_css("h1").content
84
+ end
85
+
86
+ def test_transform2
87
+ assert style = Nokogiri::XSLT(File.open(XSLT_FILE))
88
+ assert result_doc = style.transform(@doc)
89
+ assert result_doc.html?
90
+ assert_equal "", result_doc.at_css("h1").content
91
+
92
+ assert style = Nokogiri::XSLT(File.read(XSLT_FILE))
93
+ assert result_doc = style.transform(@doc, ['title', '"Booyah"'])
94
+ assert result_doc.html?
95
+ assert_equal "Booyah", result_doc.at_css("h1").content
96
+
97
+ assert result_string = style.apply_to(@doc, ['title', '"Booyah"'])
98
+ assert_equal result_string, style.serialize(result_doc)
99
+ end
100
+
101
+ def test_transform_with_quote_params
102
+ assert style = Nokogiri::XSLT(File.open(XSLT_FILE))
103
+ assert result_doc = style.transform(@doc, Nokogiri::XSLT.quote_params(['title', 'Booyah']))
104
+ assert result_doc.html?
105
+ assert_equal "Booyah", result_doc.at_css("h1").content
106
+
107
+ assert style = Nokogiri::XSLT.parse(File.read(XSLT_FILE))
108
+ assert result_doc = style.transform(@doc, Nokogiri::XSLT.quote_params({'title' => 'Booyah'}))
109
+ assert result_doc.html?
110
+ assert_equal "Booyah", result_doc.at_css("h1").content
111
+ end
112
+
113
+ def test_quote_params
114
+ h = {
115
+ :sym => %{xxx},
116
+ 'str' => %{"xxx"},
117
+ :sym2 => %{'xxx'},
118
+ 'str2' => %{x'x'x},
119
+ :sym3 => %{x"x"x},
120
+ }
121
+ hh=h.dup
122
+ result_hash = Nokogiri::XSLT.quote_params(h)
123
+ assert_equal hh, h # non-destructive
124
+
125
+ a=h.to_a.flatten
126
+ result_array = Nokogiri::XSLT.quote_params(a)
127
+ assert_equal h.to_a.flatten, a #non-destructive
128
+
129
+ assert_equal result_array, result_hash
130
+ end
131
+
132
+ if Nokogiri.uses_libxml? # By now, cannot get it working on JRuby.
133
+ def test_exslt
134
+ assert doc = Nokogiri::XML.parse(File.read(EXML_FILE))
135
+ assert doc.xml?
136
+
137
+ assert style = Nokogiri::XSLT.parse(File.read(EXSLT_FILE))
138
+ params = {
139
+ :p1 => 'xxx',
140
+ :p2 => "x'x'x",
141
+ :p3 => 'x"x"x',
142
+ :p4 => '"xxx"'
143
+ }
144
+ result_doc = Nokogiri::XML.parse(style.apply_to(doc,
145
+ Nokogiri::XSLT.quote_params(params)))
146
+
147
+ assert_equal 'func-result', result_doc.at('/root/function').content
148
+ assert_equal 3, result_doc.at('/root/max').content.to_i
149
+ assert_match(
150
+ /\d{4}-\d\d-\d\d([-|+]\d\d:\d\d)?/,
151
+ result_doc.at('/root/date').content
152
+ )
153
+ result_doc.xpath('/root/params/*').each do |p|
154
+ assert_equal p.content, params[p.name.intern]
155
+ end
156
+ check_params result_doc, params
157
+ result_doc = Nokogiri::XML.parse(style.apply_to(doc,
158
+ Nokogiri::XSLT.quote_params(params.to_a.flatten)))
159
+ check_params result_doc, params
160
+ end
161
+ end
162
+
163
+ def test_xslt_parse_error
164
+ xslt_str = <<-EOX
165
+ <xsl:stylesheet version="1.0"
166
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
167
+ <!-- Not well-formed: -->
168
+ <xsl:template match="/"/>
169
+ <values>
170
+ <xsl:for-each select="//*">
171
+ <value>
172
+ <xsl:value-of select="@id"/>
173
+ </value>
174
+ </xsl:for-each>
175
+ </values>
176
+ </xsl:template>
177
+ </xsl:stylesheet>}
178
+ EOX
179
+ assert_raises(RuntimeError) { Nokogiri::XSLT.parse(xslt_str) }
180
+ end
181
+
182
+ def check_params result_doc, params
183
+ result_doc.xpath('/root/params/*').each do |p|
184
+ assert_equal p.content, params[p.name.intern]
185
+ end
186
+ end
187
+
188
+ end
189
+ end
@@ -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,338 @@
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 [['foo', [['a', '&b']]]], doc.start_elements
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 [['foo', [['a', '&b']]]], doc.start_elements
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
+ def test_start_element_attrs_include_namespaces
304
+ @parser.parse_memory(<<-eoxml)
305
+ <p xmlns:foo='http://foo.example.com/'>Paragraph 1</p>
306
+ eoxml
307
+ assert_equal [["p", [['xmlns:foo', 'http://foo.example.com/']]]],
308
+ @parser.document.start_elements
309
+ end
310
+
311
+ if Nokogiri.uses_libxml? # JRuby SAXParser only parses well-formed XML documents
312
+ def test_parse_document
313
+ @parser.parse_memory(<<-eoxml)
314
+ <p>Paragraph 1</p>
315
+ <p>Paragraph 2</p>
316
+ eoxml
317
+ end
318
+ end
319
+
320
+ def test_parser_attributes
321
+ xml = <<-eoxml
322
+ <?xml version="1.0" ?><root><foo a="&amp;b" c="&gt;d" /></root>
323
+ eoxml
324
+
325
+ block_called = false
326
+ @parser.parse(xml) { |ctx|
327
+ block_called = true
328
+ ctx.replace_entities = true
329
+ }
330
+
331
+ assert block_called
332
+
333
+ assert_equal [['root', []], ['foo', [['a', '&b'], ['c', '>d']]]], @parser.document.start_elements
334
+ end
335
+ end
336
+ end
337
+ end
338
+ end