nokogiri 1.3.0-x86-mswin32

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

Potentially problematic release.


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

Files changed (256) hide show
  1. data/.autotest +27 -0
  2. data/CHANGELOG.ja.rdoc +233 -0
  3. data/CHANGELOG.rdoc +222 -0
  4. data/Manifest.txt +247 -0
  5. data/README.ja.rdoc +103 -0
  6. data/README.rdoc +117 -0
  7. data/Rakefile +205 -0
  8. data/bin/nokogiri +47 -0
  9. data/ext/nokogiri/extconf.rb +89 -0
  10. data/ext/nokogiri/html_document.c +183 -0
  11. data/ext/nokogiri/html_document.h +10 -0
  12. data/ext/nokogiri/html_element_description.c +272 -0
  13. data/ext/nokogiri/html_element_description.h +10 -0
  14. data/ext/nokogiri/html_entity_lookup.c +30 -0
  15. data/ext/nokogiri/html_entity_lookup.h +8 -0
  16. data/ext/nokogiri/html_sax_parser.c +57 -0
  17. data/ext/nokogiri/html_sax_parser.h +11 -0
  18. data/ext/nokogiri/iconv.dll +0 -0
  19. data/ext/nokogiri/libexslt.dll +0 -0
  20. data/ext/nokogiri/libxml2.dll +0 -0
  21. data/ext/nokogiri/libxslt.dll +0 -0
  22. data/ext/nokogiri/nokogiri.c +81 -0
  23. data/ext/nokogiri/nokogiri.h +149 -0
  24. data/ext/nokogiri/xml_attr.c +92 -0
  25. data/ext/nokogiri/xml_attr.h +9 -0
  26. data/ext/nokogiri/xml_cdata.c +53 -0
  27. data/ext/nokogiri/xml_cdata.h +9 -0
  28. data/ext/nokogiri/xml_comment.c +51 -0
  29. data/ext/nokogiri/xml_comment.h +9 -0
  30. data/ext/nokogiri/xml_document.c +308 -0
  31. data/ext/nokogiri/xml_document.h +21 -0
  32. data/ext/nokogiri/xml_document_fragment.c +48 -0
  33. data/ext/nokogiri/xml_document_fragment.h +10 -0
  34. data/ext/nokogiri/xml_dtd.c +102 -0
  35. data/ext/nokogiri/xml_dtd.h +8 -0
  36. data/ext/nokogiri/xml_entity_reference.c +50 -0
  37. data/ext/nokogiri/xml_entity_reference.h +9 -0
  38. data/ext/nokogiri/xml_io.c +24 -0
  39. data/ext/nokogiri/xml_io.h +10 -0
  40. data/ext/nokogiri/xml_namespace.c +69 -0
  41. data/ext/nokogiri/xml_namespace.h +12 -0
  42. data/ext/nokogiri/xml_node.c +928 -0
  43. data/ext/nokogiri/xml_node.h +14 -0
  44. data/ext/nokogiri/xml_node_set.c +386 -0
  45. data/ext/nokogiri/xml_node_set.h +9 -0
  46. data/ext/nokogiri/xml_processing_instruction.c +54 -0
  47. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  48. data/ext/nokogiri/xml_reader.c +572 -0
  49. data/ext/nokogiri/xml_reader.h +10 -0
  50. data/ext/nokogiri/xml_relax_ng.c +106 -0
  51. data/ext/nokogiri/xml_relax_ng.h +9 -0
  52. data/ext/nokogiri/xml_sax_parser.c +336 -0
  53. data/ext/nokogiri/xml_sax_parser.h +10 -0
  54. data/ext/nokogiri/xml_sax_push_parser.c +86 -0
  55. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  56. data/ext/nokogiri/xml_schema.c +107 -0
  57. data/ext/nokogiri/xml_schema.h +9 -0
  58. data/ext/nokogiri/xml_syntax_error.c +203 -0
  59. data/ext/nokogiri/xml_syntax_error.h +12 -0
  60. data/ext/nokogiri/xml_text.c +47 -0
  61. data/ext/nokogiri/xml_text.h +9 -0
  62. data/ext/nokogiri/xml_xpath.c +53 -0
  63. data/ext/nokogiri/xml_xpath.h +11 -0
  64. data/ext/nokogiri/xml_xpath_context.c +252 -0
  65. data/ext/nokogiri/xml_xpath_context.h +9 -0
  66. data/ext/nokogiri/xslt_stylesheet.c +131 -0
  67. data/ext/nokogiri/xslt_stylesheet.h +9 -0
  68. data/ext/nokogiri/zlib1.dll +0 -0
  69. data/lib/action-nokogiri.rb +36 -0
  70. data/lib/nokogiri.rb +110 -0
  71. data/lib/nokogiri/1.8/nokogiri.so +0 -0
  72. data/lib/nokogiri/1.9/nokogiri.so +0 -0
  73. data/lib/nokogiri/css.rb +25 -0
  74. data/lib/nokogiri/css/generated_parser.rb +748 -0
  75. data/lib/nokogiri/css/generated_tokenizer.rb +144 -0
  76. data/lib/nokogiri/css/node.rb +107 -0
  77. data/lib/nokogiri/css/parser.rb +82 -0
  78. data/lib/nokogiri/css/parser.y +227 -0
  79. data/lib/nokogiri/css/syntax_error.rb +7 -0
  80. data/lib/nokogiri/css/tokenizer.rb +11 -0
  81. data/lib/nokogiri/css/tokenizer.rex +54 -0
  82. data/lib/nokogiri/css/xpath_visitor.rb +172 -0
  83. data/lib/nokogiri/decorators.rb +2 -0
  84. data/lib/nokogiri/decorators/hpricot.rb +3 -0
  85. data/lib/nokogiri/decorators/hpricot/node.rb +56 -0
  86. data/lib/nokogiri/decorators/hpricot/node_set.rb +54 -0
  87. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +30 -0
  88. data/lib/nokogiri/decorators/slop.rb +33 -0
  89. data/lib/nokogiri/ffi/html/document.rb +37 -0
  90. data/lib/nokogiri/ffi/html/element_description.rb +85 -0
  91. data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
  92. data/lib/nokogiri/ffi/html/sax/parser.rb +21 -0
  93. data/lib/nokogiri/ffi/io_callbacks.rb +32 -0
  94. data/lib/nokogiri/ffi/libxml.rb +314 -0
  95. data/lib/nokogiri/ffi/structs/common_node.rb +26 -0
  96. data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
  97. data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
  98. data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
  99. data/lib/nokogiri/ffi/structs/xml_attr.rb +19 -0
  100. data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
  101. data/lib/nokogiri/ffi/structs/xml_document.rb +108 -0
  102. data/lib/nokogiri/ffi/structs/xml_dtd.rb +26 -0
  103. data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
  104. data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
  105. data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
  106. data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
  107. data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
  108. data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
  109. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +14 -0
  110. data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
  111. data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
  112. data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
  113. data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +37 -0
  114. data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
  115. data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
  116. data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
  117. data/lib/nokogiri/ffi/xml/attr.rb +41 -0
  118. data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
  119. data/lib/nokogiri/ffi/xml/comment.rb +18 -0
  120. data/lib/nokogiri/ffi/xml/document.rb +107 -0
  121. data/lib/nokogiri/ffi/xml/document_fragment.rb +26 -0
  122. data/lib/nokogiri/ffi/xml/dtd.rb +42 -0
  123. data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
  124. data/lib/nokogiri/ffi/xml/namespace.rb +38 -0
  125. data/lib/nokogiri/ffi/xml/node.rb +380 -0
  126. data/lib/nokogiri/ffi/xml/node_set.rb +130 -0
  127. data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
  128. data/lib/nokogiri/ffi/xml/reader.rb +217 -0
  129. data/lib/nokogiri/ffi/xml/relax_ng.rb +51 -0
  130. data/lib/nokogiri/ffi/xml/sax/parser.rb +148 -0
  131. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +38 -0
  132. data/lib/nokogiri/ffi/xml/schema.rb +55 -0
  133. data/lib/nokogiri/ffi/xml/syntax_error.rb +76 -0
  134. data/lib/nokogiri/ffi/xml/text.rb +18 -0
  135. data/lib/nokogiri/ffi/xml/xpath.rb +19 -0
  136. data/lib/nokogiri/ffi/xml/xpath_context.rb +135 -0
  137. data/lib/nokogiri/ffi/xslt/stylesheet.rb +47 -0
  138. data/lib/nokogiri/hpricot.rb +62 -0
  139. data/lib/nokogiri/html.rb +34 -0
  140. data/lib/nokogiri/html/builder.rb +35 -0
  141. data/lib/nokogiri/html/document.rb +71 -0
  142. data/lib/nokogiri/html/document_fragment.rb +15 -0
  143. data/lib/nokogiri/html/element_description.rb +23 -0
  144. data/lib/nokogiri/html/entity_lookup.rb +13 -0
  145. data/lib/nokogiri/html/sax/parser.rb +47 -0
  146. data/lib/nokogiri/nokogiri.rb +1 -0
  147. data/lib/nokogiri/syntax_error.rb +4 -0
  148. data/lib/nokogiri/version.rb +29 -0
  149. data/lib/nokogiri/version_warning.rb +11 -0
  150. data/lib/nokogiri/xml.rb +62 -0
  151. data/lib/nokogiri/xml/attr.rb +9 -0
  152. data/lib/nokogiri/xml/builder.rb +254 -0
  153. data/lib/nokogiri/xml/cdata.rb +11 -0
  154. data/lib/nokogiri/xml/document.rb +100 -0
  155. data/lib/nokogiri/xml/document_fragment.rb +49 -0
  156. data/lib/nokogiri/xml/dtd.rb +11 -0
  157. data/lib/nokogiri/xml/entity_declaration.rb +11 -0
  158. data/lib/nokogiri/xml/fragment_handler.rb +55 -0
  159. data/lib/nokogiri/xml/namespace.rb +7 -0
  160. data/lib/nokogiri/xml/node.rb +745 -0
  161. data/lib/nokogiri/xml/node/save_options.rb +42 -0
  162. data/lib/nokogiri/xml/node_set.rb +238 -0
  163. data/lib/nokogiri/xml/notation.rb +6 -0
  164. data/lib/nokogiri/xml/parse_options.rb +80 -0
  165. data/lib/nokogiri/xml/processing_instruction.rb +8 -0
  166. data/lib/nokogiri/xml/reader.rb +66 -0
  167. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  168. data/lib/nokogiri/xml/sax.rb +3 -0
  169. data/lib/nokogiri/xml/sax/document.rb +143 -0
  170. data/lib/nokogiri/xml/sax/parser.rb +101 -0
  171. data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
  172. data/lib/nokogiri/xml/schema.rb +65 -0
  173. data/lib/nokogiri/xml/syntax_error.rb +34 -0
  174. data/lib/nokogiri/xml/xpath.rb +10 -0
  175. data/lib/nokogiri/xml/xpath/syntax_error.rb +8 -0
  176. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  177. data/lib/nokogiri/xslt.rb +48 -0
  178. data/lib/nokogiri/xslt/stylesheet.rb +25 -0
  179. data/lib/xsd/xmlparser/nokogiri.rb +64 -0
  180. data/tasks/test.rb +161 -0
  181. data/test/css/test_nthiness.rb +160 -0
  182. data/test/css/test_parser.rb +277 -0
  183. data/test/css/test_tokenizer.rb +176 -0
  184. data/test/css/test_xpath_visitor.rb +76 -0
  185. data/test/ffi/test_document.rb +35 -0
  186. data/test/files/address_book.rlx +12 -0
  187. data/test/files/address_book.xml +10 -0
  188. data/test/files/dont_hurt_em_why.xml +422 -0
  189. data/test/files/exslt.xml +8 -0
  190. data/test/files/exslt.xslt +35 -0
  191. data/test/files/po.xml +32 -0
  192. data/test/files/po.xsd +66 -0
  193. data/test/files/staff.xml +59 -0
  194. data/test/files/staff.xslt +32 -0
  195. data/test/files/tlm.html +850 -0
  196. data/test/helper.rb +123 -0
  197. data/test/hpricot/files/basic.xhtml +17 -0
  198. data/test/hpricot/files/boingboing.html +2266 -0
  199. data/test/hpricot/files/cy0.html +3653 -0
  200. data/test/hpricot/files/immob.html +400 -0
  201. data/test/hpricot/files/pace_application.html +1320 -0
  202. data/test/hpricot/files/tenderlove.html +16 -0
  203. data/test/hpricot/files/uswebgen.html +220 -0
  204. data/test/hpricot/files/utf8.html +1054 -0
  205. data/test/hpricot/files/week9.html +1723 -0
  206. data/test/hpricot/files/why.xml +19 -0
  207. data/test/hpricot/load_files.rb +11 -0
  208. data/test/hpricot/test_alter.rb +68 -0
  209. data/test/hpricot/test_builder.rb +20 -0
  210. data/test/hpricot/test_parser.rb +426 -0
  211. data/test/hpricot/test_paths.rb +15 -0
  212. data/test/hpricot/test_preserved.rb +77 -0
  213. data/test/hpricot/test_xml.rb +30 -0
  214. data/test/html/sax/test_parser.rb +52 -0
  215. data/test/html/test_builder.rb +156 -0
  216. data/test/html/test_document.rb +361 -0
  217. data/test/html/test_document_encoding.rb +46 -0
  218. data/test/html/test_document_fragment.rb +97 -0
  219. data/test/html/test_element_description.rb +95 -0
  220. data/test/html/test_named_characters.rb +14 -0
  221. data/test/html/test_node.rb +165 -0
  222. data/test/test_convert_xpath.rb +186 -0
  223. data/test/test_css_cache.rb +56 -0
  224. data/test/test_gc.rb +15 -0
  225. data/test/test_memory_leak.rb +77 -0
  226. data/test/test_nokogiri.rb +127 -0
  227. data/test/test_reader.rb +316 -0
  228. data/test/test_xslt_transforms.rb +131 -0
  229. data/test/xml/node/test_save_options.rb +20 -0
  230. data/test/xml/node/test_subclass.rb +44 -0
  231. data/test/xml/sax/test_parser.rb +169 -0
  232. data/test/xml/sax/test_push_parser.rb +92 -0
  233. data/test/xml/test_attr.rb +38 -0
  234. data/test/xml/test_builder.rb +73 -0
  235. data/test/xml/test_cdata.rb +38 -0
  236. data/test/xml/test_comment.rb +23 -0
  237. data/test/xml/test_document.rb +397 -0
  238. data/test/xml/test_document_encoding.rb +26 -0
  239. data/test/xml/test_document_fragment.rb +76 -0
  240. data/test/xml/test_dtd.rb +42 -0
  241. data/test/xml/test_dtd_encoding.rb +31 -0
  242. data/test/xml/test_entity_reference.rb +21 -0
  243. data/test/xml/test_namespace.rb +43 -0
  244. data/test/xml/test_node.rb +808 -0
  245. data/test/xml/test_node_attributes.rb +34 -0
  246. data/test/xml/test_node_encoding.rb +84 -0
  247. data/test/xml/test_node_set.rb +368 -0
  248. data/test/xml/test_parse_options.rb +52 -0
  249. data/test/xml/test_processing_instruction.rb +30 -0
  250. data/test/xml/test_reader_encoding.rb +126 -0
  251. data/test/xml/test_relax_ng.rb +60 -0
  252. data/test/xml/test_schema.rb +65 -0
  253. data/test/xml/test_text.rb +18 -0
  254. data/test/xml/test_unparented_node.rb +381 -0
  255. data/test/xml/test_xpath.rb +106 -0
  256. metadata +409 -0
@@ -0,0 +1,38 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestAttr < Nokogiri::TestCase
6
+ def test_new
7
+ 100.times {
8
+ doc = Nokogiri::XML::Document.new
9
+ attribute = Nokogiri::XML::Attr.new(doc, 'foo')
10
+ }
11
+ end
12
+
13
+ def test_content=
14
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
15
+ address = xml.xpath('//address')[3]
16
+ street = address.attributes['street']
17
+ street.content = "Y&ent1;"
18
+ assert_equal "Y&ent1;", street.value
19
+ end
20
+
21
+ def test_value=
22
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
23
+ address = xml.xpath('//address')[3]
24
+ street = address.attributes['street']
25
+ street.value = "Y&ent1;"
26
+ assert_equal "Y&ent1;", street.value
27
+ end
28
+
29
+ def test_unlink
30
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
31
+ address = xml.xpath('/staff/employee/address').first
32
+ assert_equal 'Yes', address['domestic']
33
+ address.attribute_nodes.first.unlink
34
+ assert_nil address['domestic']
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,73 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestBuilder < Nokogiri::TestCase
6
+ def test_set_encoding
7
+ builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
8
+ xml.root do
9
+ xml.bar 'blah'
10
+ end
11
+ end
12
+ assert_match 'UTF-8', builder.to_xml
13
+ end
14
+
15
+ def test_bang_and_underscore_is_escaped
16
+ builder = Nokogiri::XML::Builder.new do |xml|
17
+ xml.root do
18
+ xml.p_('adsfadsf')
19
+ xml.p!('adsfadsf')
20
+ end
21
+ end
22
+ assert_equal 2, builder.doc.xpath('//p').length
23
+ end
24
+
25
+ def test_square_brackets_set_attributes
26
+ builder = Nokogiri::XML::Builder.new do |xml|
27
+ xml.root do
28
+ foo = xml.foo
29
+ foo['id'] = 'hello'
30
+ assert_equal 'hello', foo['id']
31
+ end
32
+ end
33
+ assert_equal 1, builder.doc.xpath('//foo[@id = "hello"]').length
34
+ end
35
+
36
+ def test_nested_local_variable
37
+ @ivar = 'hello'
38
+ local_var = 'hello world'
39
+ builder = Nokogiri::XML::Builder.new do |xml|
40
+ xml.root do
41
+ xml.foo local_var
42
+ xml.bar @ivar
43
+ xml.baz {
44
+ xml.text @ivar
45
+ }
46
+ end
47
+ end
48
+
49
+ assert_equal 'hello world', builder.doc.at('//root/foo').content
50
+ assert_equal 'hello', builder.doc.at('//root/bar').content
51
+ assert_equal 'hello', builder.doc.at('baz').content
52
+ end
53
+
54
+ def test_cdata
55
+ builder = Nokogiri::XML::Builder.new do
56
+ root {
57
+ cdata "hello world"
58
+ }
59
+ end
60
+ assert_equal("<?xml version=\"1.0\"?><root><![CDATA[hello world]]></root>", builder.to_xml.gsub(/\n/, ''))
61
+ end
62
+
63
+ def test_builder_no_block
64
+ string = "hello world"
65
+ builder = Nokogiri::XML::Builder.new
66
+ builder.root {
67
+ cdata string
68
+ }
69
+ assert_equal("<?xml version=\"1.0\"?><root><![CDATA[hello world]]></root>", builder.to_xml.gsub(/\n/, ''))
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestCDATA < Nokogiri::TestCase
6
+ def setup
7
+ super
8
+ @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
9
+ end
10
+
11
+ def test_cdata_node
12
+ name = @xml.xpath('//employee[2]/name').first
13
+ assert cdata = name.children[1]
14
+ assert cdata.cdata?
15
+ assert_equal '#cdata-section', cdata.name
16
+ end
17
+
18
+ def test_new
19
+ node = CDATA.new(@xml, "foo")
20
+ assert_equal "foo", node.content
21
+
22
+ node = CDATA.new(@xml.root, "foo")
23
+ assert_equal "foo", node.content
24
+ end
25
+
26
+ def test_new_with_nil
27
+ node = CDATA.new(@xml, nil)
28
+ assert_equal nil, node.content
29
+ end
30
+
31
+ def test_lots_of_new_cdata
32
+ 100.times {
33
+ node = CDATA.new(@xml, "asdfasdf")
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestComment < Nokogiri::TestCase
6
+ def setup
7
+ super
8
+ @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
9
+ end
10
+
11
+ def test_new
12
+ comment = Nokogiri::XML::Comment.new(@xml, 'hello world')
13
+ assert_equal('<!--hello world-->', comment.to_s)
14
+ end
15
+
16
+ def test_many_comments
17
+ 100.times {
18
+ Nokogiri::XML::Comment.new(@xml, 'hello world')
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,397 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ require 'uri'
4
+
5
+ module Nokogiri
6
+ module XML
7
+ class TestDocument < Nokogiri::TestCase
8
+ def setup
9
+ super
10
+ @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
11
+ end
12
+
13
+ def test_parse_takes_block
14
+ options = nil
15
+ Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) do |cfg|
16
+ options = cfg
17
+ end
18
+ assert options
19
+ end
20
+
21
+ def test_parse_yields_parse_options
22
+ options = nil
23
+ Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) do |cfg|
24
+ options = cfg
25
+ options.nonet.nowarning.dtdattr
26
+ end
27
+ assert options.nonet?
28
+ assert options.nowarning?
29
+ assert options.dtdattr?
30
+ end
31
+
32
+ def test_XML_takes_block
33
+ options = nil
34
+ Nokogiri::XML(File.read(XML_FILE), XML_FILE) do |cfg|
35
+ options = cfg
36
+ options.nonet.nowarning.dtdattr
37
+ end
38
+ assert options.nonet?
39
+ assert options.nowarning?
40
+ assert options.dtdattr?
41
+ end
42
+
43
+ def test_subclass
44
+ klass = Class.new(Nokogiri::XML::Document)
45
+ doc = klass.new
46
+ assert_instance_of klass, doc
47
+ end
48
+
49
+ def test_subclass_initialize
50
+ klass = Class.new(Nokogiri::XML::Document) do
51
+ attr_accessor :initialized_with
52
+
53
+ def initialize(*args)
54
+ @initialized_with = args
55
+ end
56
+ end
57
+ doc = klass.new("1.0", 1)
58
+ assert_equal ["1.0", 1], doc.initialized_with
59
+ end
60
+
61
+ def test_subclass_dup
62
+ klass = Class.new(Nokogiri::XML::Document)
63
+ doc = klass.new.dup
64
+ assert_instance_of klass, doc
65
+ end
66
+
67
+ def test_subclass_parse
68
+ klass = Class.new(Nokogiri::XML::Document)
69
+ doc = klass.parse(File.read(XML_FILE))
70
+ assert_equal @xml.to_s, doc.to_s
71
+ assert_instance_of klass, doc
72
+ end
73
+
74
+ def test_document_parse_method
75
+ xml = Nokogiri::XML::Document.parse(File.read(XML_FILE))
76
+ assert_equal @xml.to_s, xml.to_s
77
+ end
78
+
79
+ def test_encoding=
80
+ @xml.encoding = 'UTF-8'
81
+ assert_match 'UTF-8', @xml.to_xml
82
+
83
+ @xml.encoding = 'EUC-JP'
84
+ assert_match 'EUC-JP', @xml.to_xml
85
+ end
86
+
87
+ def test_namespace_should_not_exist
88
+ assert_raises(NoMethodError) {
89
+ @xml.namespace
90
+ }
91
+ end
92
+
93
+ def test_non_existant_function
94
+ # WTF. I don't know why this is different between MRI and ffi.
95
+ # They should be the same... Either way, raising an exception
96
+ # is the correct thing to do.
97
+ exception = RuntimeError
98
+
99
+ if Nokogiri::VERSION_INFO['libxml']['platform'] == 'jruby'
100
+ exception = Nokogiri::XML::XPath::SyntaxError
101
+ end
102
+
103
+ assert_raises(exception) {
104
+ @xml.xpath('//name[foo()]')
105
+ }
106
+ end
107
+
108
+ def test_ancestors
109
+ assert_equal 0, @xml.ancestors.length
110
+ end
111
+
112
+ def test_root_node_parent_is_document
113
+ parent = @xml.root.parent
114
+ assert_equal @xml, parent
115
+ assert_instance_of Nokogiri::XML::Document, parent
116
+ end
117
+
118
+ def test_xmlns_is_automatically_registered
119
+ doc = Nokogiri::XML(<<-eoxml)
120
+ <root xmlns="http://tenderlovemaking.com/">
121
+ <foo>
122
+ bar
123
+ </foo>
124
+ </root>
125
+ eoxml
126
+ assert_equal 1, doc.css('xmlns|foo').length
127
+ assert_equal 1, doc.css('foo').length
128
+ assert_equal 0, doc.css('|foo').length
129
+ assert_equal 1, doc.xpath('//xmlns:foo').length
130
+ assert_equal 1, doc.search('xmlns|foo').length
131
+ assert_equal 1, doc.search('//xmlns:foo').length
132
+ assert doc.at('xmlns|foo')
133
+ assert doc.at('//xmlns:foo')
134
+ assert doc.at('foo')
135
+ end
136
+
137
+ def test_xmlns_is_registered_for_nodesets
138
+ doc = Nokogiri::XML(<<-eoxml)
139
+ <root xmlns="http://tenderlovemaking.com/">
140
+ <foo>
141
+ <bar>
142
+ baz
143
+ </bar>
144
+ </foo>
145
+ </root>
146
+ eoxml
147
+ assert_equal 1, doc.css('xmlns|foo').css('xmlns|bar').length
148
+ assert_equal 1, doc.css('foo').css('bar').length
149
+ assert_equal 1, doc.xpath('//xmlns:foo').xpath('./xmlns:bar').length
150
+ assert_equal 1, doc.search('xmlns|foo').search('xmlns|bar').length
151
+ assert_equal 1, doc.search('//xmlns:foo').search('./xmlns:bar').length
152
+ end
153
+
154
+ def test_to_xml_with_indent
155
+ doc = Nokogiri::XML('<root><foo><bar/></foo></root>')
156
+ doc = Nokogiri::XML(doc.to_xml(:indent => 5))
157
+
158
+ assert_indent 5, doc
159
+ end
160
+
161
+ def test_write_xml_to_with_indent
162
+ io = StringIO.new
163
+ doc = Nokogiri::XML('<root><foo><bar/></foo></root>')
164
+ doc.write_xml_to io, :indent => 5
165
+ io.rewind
166
+ doc = Nokogiri::XML(io.read)
167
+ assert_indent 5, doc
168
+ end
169
+
170
+ # wtf... osx's libxml sucks.
171
+ unless Nokogiri::LIBXML_VERSION =~ /^2\.6\./
172
+ def test_encoding
173
+ xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE, 'UTF-8')
174
+ assert_equal 'UTF-8', xml.encoding
175
+ end
176
+ end
177
+
178
+ def test_document_has_errors
179
+ doc = Nokogiri::XML(<<-eoxml)
180
+ <foo><bar></foo>
181
+ eoxml
182
+ assert doc.errors.length > 0
183
+ doc.errors.each do |error|
184
+ assert_match error.message, error.inspect
185
+ assert_match error.message, error.to_s
186
+ end
187
+ end
188
+
189
+ def test_strict_document_throws_syntax_error
190
+ assert_raises(Nokogiri::XML::SyntaxError) {
191
+ Nokogiri::XML('<foo><bar></foo>', nil, nil, 0)
192
+ }
193
+ end
194
+
195
+ def test_XML_function
196
+ xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
197
+ assert xml.xml?
198
+ end
199
+
200
+ def test_url
201
+ assert @xml.url
202
+ assert_equal XML_FILE, URI.unescape(@xml.url).sub('file:///', '')
203
+ end
204
+
205
+ def test_document_parent
206
+ xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
207
+ assert_raises(NoMethodError) {
208
+ xml.parent
209
+ }
210
+ end
211
+
212
+ def test_document_name
213
+ xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
214
+ assert_equal 'document', xml.name
215
+ end
216
+
217
+ def test_parse_can_take_io
218
+ xml = nil
219
+ File.open(XML_FILE, 'rb') { |f|
220
+ xml = Nokogiri::XML(f)
221
+ }
222
+ assert xml.xml?
223
+ set = xml.search('//employee')
224
+ assert set.length > 0
225
+ end
226
+
227
+ def test_search_on_empty_documents
228
+ doc = Nokogiri::XML::Document.new
229
+ ns = doc.search('//foo')
230
+ assert_equal 0, ns.length
231
+
232
+ ns = doc.css('foo')
233
+ assert_equal 0, ns.length
234
+
235
+ ns = doc.xpath('//foo')
236
+ assert_equal 0, ns.length
237
+ end
238
+
239
+ def test_bad_xpath_raises_syntax_error
240
+ assert_raises(XML::XPath::SyntaxError) {
241
+ @xml.xpath('\\')
242
+ }
243
+ end
244
+
245
+ def test_new_document_collect_namespaces
246
+ doc = Nokogiri::XML::Document.new
247
+ assert_equal({}, doc.collect_namespaces)
248
+ end
249
+
250
+ def test_find_with_namespace
251
+ doc = Nokogiri::XML.parse(<<-eoxml)
252
+ <x xmlns:tenderlove='http://tenderlovemaking.com/'>
253
+ <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
254
+ </x>
255
+ eoxml
256
+
257
+ ctx = Nokogiri::XML::XPathContext.new(doc)
258
+ ctx.register_ns 'tenderlove', 'http://tenderlovemaking.com/'
259
+ set = ctx.evaluate('//tenderlove:foo').node_set
260
+ assert_equal 1, set.length
261
+ assert_equal 'foo', set.first.name
262
+
263
+ # It looks like only the URI is important:
264
+ ctx = Nokogiri::XML::XPathContext.new(doc)
265
+ ctx.register_ns 'america', 'http://tenderlovemaking.com/'
266
+ set = ctx.evaluate('//america:foo').node_set
267
+ assert_equal 1, set.length
268
+ assert_equal 'foo', set.first.name
269
+
270
+ # Its so important that a missing slash will cause it to return nothing
271
+ ctx = Nokogiri::XML::XPathContext.new(doc)
272
+ ctx.register_ns 'america', 'http://tenderlovemaking.com'
273
+ set = ctx.evaluate('//america:foo').node_set
274
+ assert_equal 0, set.length
275
+ end
276
+
277
+ def test_xml?
278
+ assert @xml.xml?
279
+ end
280
+
281
+ def test_document
282
+ assert @xml.document
283
+ end
284
+
285
+ def test_singleton_methods
286
+ assert node_set = @xml.search('//name')
287
+ assert node_set.length > 0
288
+ node = node_set.first
289
+ def node.test
290
+ 'test'
291
+ end
292
+ assert node_set = @xml.search('//name')
293
+ assert_equal 'test', node_set.first.test
294
+ end
295
+
296
+ def test_multiple_search
297
+ assert node_set = @xml.search('//employee', '//name')
298
+ employees = @xml.search('//employee')
299
+ names = @xml.search('//name')
300
+ assert_equal(employees.length + names.length, node_set.length)
301
+ end
302
+
303
+ def test_node_set_index
304
+ assert node_set = @xml.search('//employee')
305
+
306
+ assert_equal(5, node_set.length)
307
+ assert node_set[4]
308
+ assert_nil node_set[5]
309
+ end
310
+
311
+ def test_search
312
+ assert node_set = @xml.search('//employee')
313
+
314
+ assert_equal(5, node_set.length)
315
+
316
+ node_set.each do |node|
317
+ assert_equal('employee', node.name)
318
+ end
319
+ end
320
+
321
+ def test_dump
322
+ assert @xml.serialize
323
+ assert @xml.to_xml
324
+ end
325
+
326
+ def test_dup
327
+ dup = @xml.dup
328
+ assert_instance_of Nokogiri::XML::Document, dup
329
+ assert dup.xml?, 'duplicate should be xml'
330
+ end
331
+
332
+ def test_subset_is_decorated
333
+ x = Module.new do
334
+ def awesome!
335
+ end
336
+ end
337
+ util_decorate(@xml, x)
338
+
339
+ assert @xml.respond_to?(:awesome!)
340
+ assert node_set = @xml.search('//staff')
341
+ assert node_set.respond_to?(:awesome!)
342
+ assert subset = node_set.search('.//employee')
343
+ assert subset.respond_to?(:awesome!)
344
+ assert sub_subset = node_set.search('.//name')
345
+ assert sub_subset.respond_to?(:awesome!)
346
+ end
347
+
348
+ def test_decorator_is_applied
349
+ x = Module.new do
350
+ def awesome!
351
+ end
352
+ end
353
+ util_decorate(@xml, x)
354
+
355
+ assert @xml.respond_to?(:awesome!)
356
+ assert node_set = @xml.search('//employee')
357
+ assert node_set.respond_to?(:awesome!)
358
+ node_set.each do |node|
359
+ assert node.respond_to?(:awesome!), node.class
360
+ end
361
+ assert @xml.root.respond_to?(:awesome!)
362
+ end
363
+
364
+ def test_new
365
+ doc = nil
366
+ assert_nothing_raised {
367
+ doc = Nokogiri::XML::Document.new
368
+ }
369
+ assert doc
370
+ assert doc.xml?
371
+ assert_nil doc.root
372
+ end
373
+
374
+ def test_set_root
375
+ doc = nil
376
+ assert_nothing_raised {
377
+ doc = Nokogiri::XML::Document.new
378
+ }
379
+ assert doc
380
+ assert doc.xml?
381
+ assert_nil doc.root
382
+ node = Nokogiri::XML::Node.new("b", doc) { |n|
383
+ n.content = 'hello world'
384
+ }
385
+ assert_equal('hello world', node.content)
386
+ doc.root = node
387
+ assert_equal(node, doc.root)
388
+ end
389
+
390
+ def util_decorate(document, x)
391
+ document.decorators(XML::Node) << x
392
+ document.decorators(XML::NodeSet) << x
393
+ document.decorate!
394
+ end
395
+ end
396
+ end
397
+ end