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,21 @@
1
+ require "helper"
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestEntityReference < Nokogiri::TestCase
6
+ def setup
7
+ super
8
+ @xml = Nokogiri::XML(File.open(XML_FILE), XML_FILE)
9
+ end
10
+
11
+ def test_new
12
+ assert ref = EntityReference.new(@xml, 'ent4')
13
+ assert_instance_of EntityReference, ref
14
+ end
15
+
16
+ def test_many_references
17
+ 100.times { EntityReference.new(@xml, 'foo') }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,70 @@
1
+ require "helper"
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestNamespace < Nokogiri::TestCase
6
+ def setup
7
+ super
8
+ @xml = Nokogiri::XML <<-eoxml
9
+ <root xmlns="http://tenderlovemaking.com/" xmlns:foo="bar">
10
+ <awesome/>
11
+ </root>
12
+ eoxml
13
+ end
14
+
15
+ if Nokogiri.uses_libxml?
16
+ def test_namespace_is_in_node_cache
17
+ node = @xml.root.namespace
18
+ assert @xml.instance_variable_get(:@node_cache).include?(node)
19
+ end
20
+ end
21
+
22
+ def test_built_nodes_keep_namespace_decls
23
+ doc = Document.new
24
+ e = Node.new 'element', doc
25
+ c = Node.new 'child', doc
26
+ c.default_namespace = 'woop:de:doo'
27
+
28
+ assert c.namespace, 'has a namespace'
29
+ e.add_child c
30
+ assert c.namespace, 'has a namespace'
31
+
32
+ doc.add_child e
33
+ assert c.namespace, 'has a namespace'
34
+ end
35
+
36
+ def test_inspect
37
+ ns = @xml.root.namespace
38
+ assert_equal "#<#{ns.class.name}:#{sprintf("0x%x", ns.object_id)} href=#{ns.href.inspect}>", ns.inspect
39
+ end
40
+
41
+ def test_namespace_node_prefix
42
+ namespaces = @xml.root.namespace_definitions
43
+ assert_equal [nil, 'foo'], namespaces.map { |x| x.prefix }
44
+ end
45
+
46
+ def test_namespace_node_href
47
+ namespaces = @xml.root.namespace_definitions
48
+ assert_equal [
49
+ 'http://tenderlovemaking.com/',
50
+ 'bar'
51
+ ], namespaces.map { |x| x.href }
52
+ end
53
+
54
+ def test_equality
55
+ namespaces = @xml.root.namespace_definitions
56
+ assert_equal namespaces, @xml.root.namespace_definitions
57
+ end
58
+
59
+ def test_add_definition
60
+ @xml.root.add_namespace_definition('baz', 'bar')
61
+ assert_equal 3, @xml.root.namespace_definitions.length
62
+ end
63
+
64
+ def test_add_definition_return
65
+ ns = @xml.root.add_namespace_definition('baz', 'bar')
66
+ assert_equal 'baz', ns.prefix
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,740 @@
1
+ require "helper"
2
+
3
+ require 'stringio'
4
+
5
+ module Nokogiri
6
+ module XML
7
+ class TestNode < Nokogiri::TestCase
8
+ def setup
9
+ super
10
+ @xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
11
+ end
12
+
13
+ def test_gt_string_arg
14
+ node = @xml.at('employee')
15
+ nodes = (node > 'name')
16
+ assert_equal 1, nodes.length
17
+ assert_equal node, nodes.first.parent
18
+ end
19
+
20
+ def test_next_element_when_next_sibling_is_element_should_return_next_sibling
21
+ doc = Nokogiri::XML "<root><foo /><quux /></root>"
22
+ node = doc.at_css("foo")
23
+ next_element = node.next_element
24
+ assert next_element.element?
25
+ assert_equal doc.at_css("quux"), next_element
26
+ end
27
+
28
+ def test_next_element_when_there_is_no_next_sibling_should_return_nil
29
+ doc = Nokogiri::XML "<root><foo /><quux /></root>"
30
+ assert_nil doc.at_css("quux").next_element
31
+ end
32
+
33
+ def test_next_element_when_next_sibling_is_not_an_element_should_return_closest_next_element_sibling
34
+ doc = Nokogiri::XML "<root><foo />bar<quux /></root>"
35
+ node = doc.at_css("foo")
36
+ next_element = node.next_element
37
+ assert next_element.element?
38
+ assert_equal doc.at_css("quux"), next_element
39
+ end
40
+
41
+ def test_next_element_when_next_sibling_is_not_an_element_and_no_following_element_should_return_nil
42
+ doc = Nokogiri::XML "<root><foo />bar</root>"
43
+ node = doc.at_css("foo")
44
+ next_element = node.next_element
45
+ assert_nil next_element
46
+ end
47
+
48
+ def test_previous_element_when_previous_sibling_is_element_should_return_previous_sibling
49
+ doc = Nokogiri::XML "<root><foo /><quux /></root>"
50
+ node = doc.at_css("quux")
51
+ previous_element = node.previous_element
52
+ assert previous_element.element?
53
+ assert_equal doc.at_css("foo"), previous_element
54
+ end
55
+
56
+ def test_previous_element_when_there_is_no_previous_sibling_should_return_nil
57
+ doc = Nokogiri::XML "<root><foo /><quux /></root>"
58
+ assert_nil doc.at_css("foo").previous_element
59
+ end
60
+
61
+ def test_previous_element_when_previous_sibling_is_not_an_element_should_return_closest_previous_element_sibling
62
+ doc = Nokogiri::XML "<root><foo />bar<quux /></root>"
63
+ node = doc.at_css("quux")
64
+ previous_element = node.previous_element
65
+ assert previous_element.element?
66
+ assert_equal doc.at_css("foo"), previous_element
67
+ end
68
+
69
+ def test_previous_element_when_previous_sibling_is_not_an_element_and_no_following_element_should_return_nil
70
+ doc = Nokogiri::XML "<root>foo<bar /></root>"
71
+ node = doc.at_css("bar")
72
+ previous_element = node.previous_element
73
+ assert_nil previous_element
74
+ end
75
+
76
+ def test_element?
77
+ assert @xml.root.element?, 'is an element'
78
+ end
79
+
80
+ def test_slash_search
81
+ assert_equal 'EMP0001', (@xml/:staff/:employee/:employeeId).first.text
82
+ end
83
+
84
+ def test_append_with_document
85
+ assert_raises(ArgumentError) do
86
+ @xml.root << Nokogiri::XML::Document.new
87
+ end
88
+ end
89
+
90
+ def test_inspect_ns
91
+ xml = Nokogiri::XML(<<-eoxml) { |c| c.noblanks }
92
+ <root xmlns="http://tenderlovemaking.com/" xmlns:foo="bar">
93
+ <awesome/>
94
+ </root>
95
+ eoxml
96
+ ins = xml.inspect
97
+
98
+ xml.traverse do |node|
99
+ assert_match node.class.name, ins
100
+ if node.respond_to? :attributes
101
+ node.attributes.each do |k,v|
102
+ assert_match k, ins
103
+ assert_match v, ins
104
+ end
105
+ end
106
+
107
+ if node.respond_to?(:namespace) && node.namespace
108
+ assert_match node.namespace.class.name, ins
109
+ assert_match node.namespace.href, ins
110
+ end
111
+ end
112
+ end
113
+
114
+ def test_namespace_nodes
115
+ xml = Nokogiri::XML <<-eoxml
116
+ <root xmlns="http://tenderlovemaking.com/" xmlns:foo="bar">
117
+ <awesome/>
118
+ </root>
119
+ eoxml
120
+ awesome = xml.root
121
+ namespaces = awesome.namespace_definitions
122
+ assert_equal 2, namespaces.length
123
+ end
124
+
125
+ def test_no_definitions
126
+ xml = Nokogiri::XML <<-eoxml
127
+ <root xmlns="http://tenderlovemaking.com/" xmlns:foo="bar">
128
+ <awesome/>
129
+ </root>
130
+ eoxml
131
+ awesome = xml.at('//xmlns:awesome')
132
+ namespaces = awesome.namespace_definitions
133
+ assert_equal 0, namespaces.length
134
+ end
135
+
136
+ def test_subclass_dup
137
+ subclass = Class.new(Nokogiri::XML::Node)
138
+ node = subclass.new('foo', @xml).dup
139
+ assert_instance_of subclass, node
140
+ end
141
+
142
+ def test_namespace_goes_to_children
143
+ fruits = Nokogiri::XML(<<-eoxml)
144
+ <Fruit xmlns='www.fruits.org'>
145
+ </Fruit>
146
+ eoxml
147
+ apple = Nokogiri::XML::Node.new('Apple', fruits)
148
+ orange = Nokogiri::XML::Node.new('Orange', fruits)
149
+ apple << orange
150
+ fruits.root << apple
151
+ assert fruits.at('//fruit:Orange',{'fruit'=>'www.fruits.org'})
152
+ assert fruits.at('//fruit:Apple',{'fruit'=>'www.fruits.org'})
153
+ end
154
+
155
+ def test_description
156
+ assert_nil @xml.at('employee').description
157
+ end
158
+
159
+ def test_spaceship
160
+ nodes = @xml.xpath('//employee')
161
+ assert_equal(-1, (nodes.first <=> nodes.last))
162
+ list = [nodes.first, nodes.last].sort
163
+ assert_equal nodes.first, list.first
164
+ assert_equal nodes.last, list.last
165
+ end
166
+
167
+ def test_incorrect_spaceship
168
+ nodes = @xml.xpath('//employee')
169
+ assert_nil(nodes.first <=> 'asdf')
170
+ end
171
+
172
+ def test_document_compare
173
+ nodes = @xml.xpath('//employee')
174
+ assert_equal(-1, (nodes.first <=> @xml))
175
+ end
176
+
177
+ def test_different_document_compare
178
+ nodes = @xml.xpath('//employee')
179
+ doc = Nokogiri::XML('<a><b/></a>')
180
+ b = doc.at('b')
181
+ assert_nil(nodes.first <=> b)
182
+ end
183
+
184
+ def test_duplicate_node_removes_namespace
185
+ fruits = Nokogiri::XML(<<-eoxml)
186
+ <Fruit xmlns='www.fruits.org'>
187
+ <Apple></Apple>
188
+ </Fruit>
189
+ eoxml
190
+ apple = fruits.root.xpath('fruit:Apple', {'fruit'=>'www.fruits.org'})[0]
191
+ new_apple = apple.dup
192
+ fruits.root << new_apple
193
+ assert_equal 2, fruits.xpath('//xmlns:Apple').length
194
+ assert_equal 1, fruits.to_xml.scan('www.fruits.org').length
195
+ end
196
+
197
+ [:clone, :dup].each do |symbol|
198
+ define_method "test_#{symbol}" do
199
+ node = @xml.at('//employee')
200
+ other = node.send(symbol)
201
+ assert_equal "employee", other.name
202
+ assert_nil other.parent
203
+ end
204
+ end
205
+
206
+ def test_fragment_creates_elements
207
+ apple = @xml.fragment('<Apple/>')
208
+ apple.children.each do |child|
209
+ assert_equal Nokogiri::XML::Node::ELEMENT_NODE, child.type
210
+ assert_instance_of Nokogiri::XML::Element, child
211
+ end
212
+ end
213
+
214
+ def test_node_added_to_root_should_get_namespace
215
+ fruits = Nokogiri::XML(<<-eoxml)
216
+ <Fruit xmlns='http://www.fruits.org'>
217
+ </Fruit>
218
+ eoxml
219
+ apple = fruits.fragment('<Apple/>')
220
+ fruits.root << apple
221
+ assert_equal 1, fruits.xpath('//xmlns:Apple').length
222
+ end
223
+
224
+ def test_new_node_can_have_ancestors
225
+ xml = Nokogiri::XML('<root>text</root>')
226
+ item = Nokogiri::XML::Element.new('item', xml)
227
+ assert_equal 0, item.ancestors.length
228
+ end
229
+
230
+ def test_children
231
+ doc = Nokogiri::XML(<<-eoxml)
232
+ <root>#{'<a/>' * 9 }</root>
233
+ eoxml
234
+ assert_equal 9, doc.root.children.length
235
+ assert_equal 9, doc.root.children.to_a.length
236
+
237
+ doc = Nokogiri::XML(<<-eoxml)
238
+ <root>#{'<a/>' * 15 }</root>
239
+ eoxml
240
+ assert_equal 15, doc.root.children.length
241
+ assert_equal 15, doc.root.children.to_a.length
242
+ end
243
+
244
+ def test_add_namespace
245
+ node = @xml.at('address')
246
+ node.add_namespace('foo', 'http://tenderlovemaking.com')
247
+ assert_equal 'http://tenderlovemaking.com', node.namespaces['xmlns:foo']
248
+ end
249
+
250
+ def test_add_namespace_twice
251
+ node = @xml.at('address')
252
+ ns = node.add_namespace('foo', 'http://tenderlovemaking.com')
253
+ ns2 = node.add_namespace('foo', 'http://tenderlovemaking.com')
254
+ assert_equal ns, ns2
255
+ end
256
+
257
+ def test_add_default_ns
258
+ node = @xml.at('address')
259
+ node.add_namespace(nil, 'http://tenderlovemaking.com')
260
+ assert_equal 'http://tenderlovemaking.com', node.namespaces['xmlns']
261
+ end
262
+
263
+ def test_add_multiple_namespaces
264
+ node = @xml.at('address')
265
+
266
+ node.add_namespace(nil, 'http://tenderlovemaking.com')
267
+ assert_equal 'http://tenderlovemaking.com', node.namespaces['xmlns']
268
+
269
+ node.add_namespace('foo', 'http://tenderlovemaking.com')
270
+ assert_equal 'http://tenderlovemaking.com', node.namespaces['xmlns:foo']
271
+ end
272
+
273
+ def test_default_namespace=
274
+ node = @xml.at('address')
275
+ node.default_namespace = 'http://tenderlovemaking.com'
276
+ assert_equal 'http://tenderlovemaking.com', node.namespaces['xmlns']
277
+ end
278
+
279
+ def test_namespace=
280
+ node = @xml.at('address')
281
+ assert_nil node.namespace
282
+ definition = node.add_namespace_definition 'bar', 'http://tlm.com/'
283
+
284
+ node.namespace = definition
285
+
286
+ assert_equal definition, node.namespace
287
+
288
+ assert_equal node, @xml.at('//foo:address', {
289
+ 'foo' => 'http://tlm.com/'
290
+ })
291
+ end
292
+
293
+ def test_add_namespace_with_nil_associates_node
294
+ node = @xml.at('address')
295
+ assert_nil node.namespace
296
+ definition = node.add_namespace_definition nil, 'http://tlm.com/'
297
+ assert_equal definition, node.namespace
298
+ end
299
+
300
+ def test_add_namespace_does_not_associate_node
301
+ node = @xml.at('address')
302
+ assert_nil node.namespace
303
+ definition = node.add_namespace_definition 'foo', 'http://tlm.com/'
304
+ assert_nil node.namespace
305
+ end
306
+
307
+ def test_set_namespace_from_different_doc
308
+ node = @xml.at('address')
309
+ doc = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
310
+ decl = doc.root.add_namespace_definition 'foo', 'bar'
311
+
312
+ assert_raises(ArgumentError) do
313
+ node.namespace = decl
314
+ end
315
+ end
316
+
317
+ def test_set_namespace_must_only_take_a_namespace
318
+ node = @xml.at('address')
319
+ assert_raises(TypeError) do
320
+ node.namespace = node
321
+ end
322
+ end
323
+
324
+ def test_at
325
+ node = @xml.at('address')
326
+ assert_equal node, @xml.xpath('//address').first
327
+ end
328
+
329
+ def test_at_xpath
330
+ node = @xml.at_xpath('//address')
331
+ nodes = @xml.xpath('//address')
332
+ assert_equal 5, nodes.size
333
+ assert_equal node, nodes.first
334
+ end
335
+
336
+ def test_at_css
337
+ node = @xml.at_css('address')
338
+ nodes = @xml.css('address')
339
+ assert_equal 5, nodes.size
340
+ assert_equal node, nodes.first
341
+ end
342
+
343
+ def test_percent
344
+ node = @xml % ('address')
345
+ assert_equal node, @xml.xpath('//address').first
346
+ end
347
+
348
+ def test_accept
349
+ visitor = Class.new {
350
+ attr_accessor :visited
351
+ def accept target
352
+ target.accept(self)
353
+ end
354
+
355
+ def visit node
356
+ node.children.each { |c| c.accept(self) }
357
+ @visited = true
358
+ end
359
+ }.new
360
+ visitor.accept(@xml.root)
361
+ assert visitor.visited
362
+ end
363
+
364
+ def test_write_to
365
+ io = StringIO.new
366
+ @xml.write_to io
367
+ io.rewind
368
+ assert_equal @xml.to_xml, io.read
369
+ end
370
+
371
+ def test_attribute_with_symbol
372
+ assert_equal 'Yes', @xml.css('address').first[:domestic]
373
+ end
374
+
375
+ def test_write_to_with_block
376
+ called = false
377
+ io = StringIO.new
378
+ conf = nil
379
+ @xml.write_to io do |config|
380
+ called = true
381
+ conf = config
382
+ config.format.as_html.no_empty_tags
383
+ end
384
+ io.rewind
385
+ assert called
386
+ assert_equal @xml.serialize(nil, conf.options), io.read
387
+ end
388
+
389
+ %w{ xml html xhtml }.each do |type|
390
+ define_method(:"test_write_#{type}_to") do
391
+ io = StringIO.new
392
+ assert @xml.send(:"write_#{type}_to", io)
393
+ io.rewind
394
+ assert_match @xml.send(:"to_#{type}"), io.read
395
+ end
396
+ end
397
+
398
+ def test_serialize_with_block
399
+ called = false
400
+ conf = nil
401
+ string = @xml.serialize do |config|
402
+ called = true
403
+ conf = config
404
+ config.format.as_html.no_empty_tags
405
+ end
406
+ assert called
407
+ assert_equal @xml.serialize(nil, conf.options), string
408
+ end
409
+
410
+ def test_hold_refence_to_subnode
411
+ doc = Nokogiri::XML(<<-eoxml)
412
+ <root>
413
+ <a>
414
+ <b />
415
+ </a>
416
+ </root>
417
+ eoxml
418
+ assert node_a = doc.css('a').first
419
+ assert node_b = node_a.css('b').first
420
+ node_a.unlink
421
+ assert_equal 'b', node_b.name
422
+ end
423
+
424
+ def test_values
425
+ assert_equal %w{ Yes Yes }, @xml.xpath('//address')[1].values
426
+ end
427
+
428
+ def test_keys
429
+ assert_equal %w{ domestic street }, @xml.xpath('//address')[1].keys
430
+ end
431
+
432
+ def test_each
433
+ attributes = []
434
+ @xml.xpath('//address')[1].each do |key, value|
435
+ attributes << [key, value]
436
+ end
437
+ assert_equal [['domestic', 'Yes'], ['street', 'Yes']], attributes
438
+ end
439
+
440
+ def test_new
441
+ assert node = Nokogiri::XML::Node.new('input', @xml)
442
+ assert_equal 1, node.node_type
443
+ assert_instance_of Nokogiri::XML::Element, node
444
+ end
445
+
446
+ def test_to_str
447
+ name = @xml.xpath('//name').first
448
+ assert_match(/Margaret/, '' + name)
449
+ assert_equal('Margaret Martin', '' + name.children.first)
450
+ end
451
+
452
+ def test_ancestors
453
+ address = @xml.xpath('//address').first
454
+ assert_equal 3, address.ancestors.length
455
+ assert_equal ['employee', 'staff', 'document'],
456
+ address.ancestors.map { |x| x.name }
457
+ end
458
+
459
+ def test_read_only?
460
+ assert entity_decl = @xml.internal_subset.children.find { |x|
461
+ x.type == Node::ENTITY_DECL
462
+ }
463
+ assert entity_decl.read_only?
464
+ end
465
+
466
+ def test_remove_attribute
467
+ address = @xml.xpath('/staff/employee/address').first
468
+ assert_equal 'Yes', address['domestic']
469
+ address.remove_attribute 'domestic'
470
+ assert_nil address['domestic']
471
+ end
472
+
473
+ def test_delete
474
+ address = @xml.xpath('/staff/employee/address').first
475
+ assert_equal 'Yes', address['domestic']
476
+ address.delete 'domestic'
477
+ assert_nil address['domestic']
478
+ end
479
+
480
+ def test_set_content_with_symbol
481
+ node = @xml.at('//name')
482
+ node.content = :foo
483
+ assert_equal 'foo', node.content
484
+ end
485
+
486
+ def test_find_by_css_with_tilde_eql
487
+ xml = Nokogiri::XML.parse(<<-eoxml)
488
+ <root>
489
+ <a>Hello world</a>
490
+ <a class='foo bar'>Bar</a>
491
+ <a class='bar foo'>Bar</a>
492
+ <a class='bar'>Bar</a>
493
+ <a class='baz bar foo'>Bar</a>
494
+ <a class='bazbarfoo'>Awesome</a>
495
+ <a class='bazbar'>Awesome</a>
496
+ </root>
497
+ eoxml
498
+ set = xml.css('a[@class~="bar"]')
499
+ assert_equal 4, set.length
500
+ assert_equal ['Bar'], set.map { |node| node.content }.uniq
501
+ end
502
+
503
+ def test_unlink
504
+ xml = Nokogiri::XML.parse(<<-eoxml)
505
+ <root>
506
+ <a class='foo bar'>Bar</a>
507
+ <a class='bar foo'>Bar</a>
508
+ <a class='bar'>Bar</a>
509
+ <a>Hello world</a>
510
+ <a class='baz bar foo'>Bar</a>
511
+ <a class='bazbarfoo'>Awesome</a>
512
+ <a class='bazbar'>Awesome</a>
513
+ </root>
514
+ eoxml
515
+ node = xml.xpath('//a')[3]
516
+ assert_equal('Hello world', node.text)
517
+ assert_match(/Hello world/, xml.to_s)
518
+ assert node.parent
519
+ assert node.document
520
+ assert node.previous_sibling
521
+ assert node.next_sibling
522
+ node.unlink
523
+ assert !node.parent
524
+ #assert !node.document
525
+ assert !node.previous_sibling
526
+ assert !node.next_sibling
527
+ assert_no_match(/Hello world/, xml.to_s)
528
+ end
529
+
530
+ def test_next_sibling
531
+ assert node = @xml.root
532
+ assert sibling = node.child.next_sibling
533
+ assert_equal('employee', sibling.name)
534
+ end
535
+
536
+ def test_previous_sibling
537
+ assert node = @xml.root
538
+ assert sibling = node.child.next_sibling
539
+ assert_equal('employee', sibling.name)
540
+ assert_equal(sibling.previous_sibling, node.child)
541
+ end
542
+
543
+ def test_name=
544
+ assert node = @xml.root
545
+ node.name = 'awesome'
546
+ assert_equal('awesome', node.name)
547
+ end
548
+
549
+ def test_child
550
+ assert node = @xml.root
551
+ assert child = node.child
552
+ assert_equal('text', child.name)
553
+ end
554
+
555
+ def test_key?
556
+ assert node = @xml.search('//address').first
557
+ assert(!node.key?('asdfasdf'))
558
+ end
559
+
560
+ def test_set_property
561
+ assert node = @xml.search('//address').first
562
+ node['foo'] = 'bar'
563
+ assert_equal('bar', node['foo'])
564
+ end
565
+
566
+ def test_attributes
567
+ assert node = @xml.search('//address').first
568
+ assert_nil(node['asdfasdfasdf'])
569
+ assert_equal('Yes', node['domestic'])
570
+
571
+ assert node = @xml.search('//address')[2]
572
+ attr = node.attributes
573
+ assert_equal 2, attr.size
574
+ assert_equal 'Yes', attr['domestic'].value
575
+ assert_equal 'Yes', attr['domestic'].to_s
576
+ assert_equal 'No', attr['street'].value
577
+ end
578
+
579
+ def test_path
580
+ assert set = @xml.search('//employee')
581
+ assert node = set.first
582
+ assert_equal('/staff/employee[1]', node.path)
583
+ end
584
+
585
+ def test_search_by_symbol
586
+ assert set = @xml.search(:employee)
587
+ assert 5, set.length
588
+
589
+ assert node = @xml.at(:employee)
590
+ assert node.text =~ /EMP0001/
591
+ end
592
+
593
+ def test_new_node
594
+ node = Nokogiri::XML::Node.new('form', @xml)
595
+ assert_equal('form', node.name)
596
+ assert(node.document)
597
+ end
598
+
599
+ def test_encode_special_chars
600
+ foo = @xml.css('employee').first.encode_special_chars('&')
601
+ assert_equal '&amp;', foo
602
+ end
603
+
604
+ def test_content
605
+ node = Nokogiri::XML::Node.new('form', @xml)
606
+ assert_equal('', node.content)
607
+
608
+ node.content = 'hello world!'
609
+ assert_equal('hello world!', node.content)
610
+ end
611
+
612
+ def test_whitespace_nodes
613
+ doc = Nokogiri::XML.parse("<root><b>Foo</b>\n<i>Bar</i> <p>Bazz</p></root>")
614
+ children = doc.at('//root').children.collect{|j| j.to_s}
615
+ assert_equal "\n", children[1]
616
+ assert_equal " ", children[3]
617
+ end
618
+
619
+ def test_node_equality
620
+ doc1 = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
621
+ doc2 = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
622
+
623
+ address1_1 = doc1.xpath('//address').first
624
+ address1_2 = doc1.xpath('//address').first
625
+
626
+ address2 = doc2.xpath('//address').first
627
+
628
+ assert_not_equal address1_1, address2 # two references to very, very similar nodes
629
+ assert_equal address1_1, address1_2 # two references to the exact same node
630
+ end
631
+
632
+ def test_namespace_as_hash
633
+ xml = Nokogiri::XML.parse(<<-eoxml)
634
+ <root>
635
+ <car xmlns:part="http://general-motors.com/">
636
+ <part:tire>Michelin Model XGV</part:tire>
637
+ </car>
638
+ <bicycle xmlns:part="http://schwinn.com/">
639
+ <part:tire>I'm a bicycle tire!</part:tire>
640
+ </bicycle>
641
+ </root>
642
+ eoxml
643
+
644
+ tires = xml.xpath('//bike:tire', {'bike' => 'http://schwinn.com/'})
645
+ assert_equal 1, tires.length
646
+ end
647
+
648
+ def test_namespace_search_with_css
649
+ xml = Nokogiri::XML.parse(<<-eoxml)
650
+ <root>
651
+ <car xmlns:part="http://general-motors.com/">
652
+ <part:tire>Michelin Model XGV</part:tire>
653
+ </car>
654
+ <bicycle xmlns:part="http://schwinn.com/">
655
+ <part:tire>I'm a bicycle tire!</part:tire>
656
+ </bicycle>
657
+ </root>
658
+ eoxml
659
+
660
+ tires = xml.css('bike|tire', 'bike' => 'http://schwinn.com/')
661
+ assert_equal 1, tires.length
662
+ end
663
+
664
+ def test_namespaces
665
+ xml = Nokogiri::XML.parse(<<-EOF)
666
+ <x xmlns:a='http://foo.com/' xmlns:b='http://bar.com/'>
667
+ <y xmlns:c='http://bazz.com/'>
668
+ <a:div>hello a</a:div>
669
+ <b:div>hello b</b:div>
670
+ <c:div>hello c</c:div>
671
+ </y>
672
+ </x>
673
+ EOF
674
+ assert namespaces = xml.root.namespaces
675
+ assert namespaces.key?('xmlns:a')
676
+ assert_equal 'http://foo.com/', namespaces['xmlns:a']
677
+ assert namespaces.key?('xmlns:b')
678
+ assert_equal 'http://bar.com/', namespaces['xmlns:b']
679
+ assert ! namespaces.key?('xmlns:c')
680
+
681
+ assert namespaces = xml.namespaces
682
+ assert namespaces.key?('xmlns:a')
683
+ assert_equal 'http://foo.com/', namespaces['xmlns:a']
684
+ assert namespaces.key?('xmlns:b')
685
+ assert_equal 'http://bar.com/', namespaces['xmlns:b']
686
+
687
+ assert_equal "hello a", xml.search("//a:div", xml.namespaces).first.inner_text
688
+ assert_equal "hello b", xml.search("//b:div", xml.namespaces).first.inner_text
689
+ end
690
+
691
+ def test_namespace
692
+ xml = Nokogiri::XML.parse(<<-EOF)
693
+ <x xmlns:a='http://foo.com/' xmlns:b='http://bar.com/'>
694
+ <y xmlns:c='http://bazz.com/'>
695
+ <a:div>hello a</a:div>
696
+ <b:div>hello b</b:div>
697
+ <c:div>hello c</c:div>
698
+ <div>hello moon</div>
699
+ </y>
700
+ </x>
701
+ EOF
702
+ set = xml.search("//y/*")
703
+ assert_equal "a", set[0].namespace.prefix
704
+ assert_equal "b", set[1].namespace.prefix
705
+ assert_equal "c", set[2].namespace.prefix
706
+ assert_equal nil, set[3].namespace
707
+ end
708
+
709
+ if Nokogiri.uses_libxml?
710
+ def test_namespace_without_an_href_on_html_node
711
+ # because microsoft word's HTML formatting does this. ick.
712
+ xml = Nokogiri::HTML.parse <<-EOF
713
+ <div><o:p>foo</o:p></div>
714
+ EOF
715
+
716
+ assert_not_nil(node = xml.at('p'))
717
+
718
+ assert_equal 1, node.namespaces.keys.size
719
+ assert node.namespaces.has_key?('xmlns:o')
720
+ assert_equal nil, node.namespaces['xmlns:o']
721
+ end
722
+ end
723
+
724
+ def test_line
725
+ xml = Nokogiri::XML(<<-eoxml)
726
+ <root>
727
+ <a>
728
+ Hello world
729
+ </a>
730
+ </root>
731
+ eoxml
732
+
733
+ set = xml.search("//a")
734
+ node = set.first
735
+ assert_equal 2, node.line
736
+ end
737
+
738
+ end
739
+ end
740
+ end