nokogiri-fitzsimmons 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. data/.autotest +26 -0
  2. data/.gemtest +0 -0
  3. data/CHANGELOG.ja.rdoc +666 -0
  4. data/CHANGELOG.rdoc +659 -0
  5. data/C_CODING_STYLE.rdoc +33 -0
  6. data/Manifest.txt +295 -0
  7. data/README.ja.rdoc +106 -0
  8. data/README.rdoc +178 -0
  9. data/ROADMAP.md +86 -0
  10. data/Rakefile +194 -0
  11. data/STANDARD_RESPONSES.md +47 -0
  12. data/Y_U_NO_GEMSPEC.md +155 -0
  13. data/bin/nokogiri +63 -0
  14. data/build_all +58 -0
  15. data/ext/nokogiri/depend +358 -0
  16. data/ext/nokogiri/extconf.rb +142 -0
  17. data/ext/nokogiri/html_document.c +170 -0
  18. data/ext/nokogiri/html_document.h +10 -0
  19. data/ext/nokogiri/html_element_description.c +276 -0
  20. data/ext/nokogiri/html_element_description.h +10 -0
  21. data/ext/nokogiri/html_entity_lookup.c +32 -0
  22. data/ext/nokogiri/html_entity_lookup.h +8 -0
  23. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  24. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  25. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  26. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  27. data/ext/nokogiri/nokogiri.c +133 -0
  28. data/ext/nokogiri/nokogiri.h +160 -0
  29. data/ext/nokogiri/xml_attr.c +94 -0
  30. data/ext/nokogiri/xml_attr.h +9 -0
  31. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  32. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  33. data/ext/nokogiri/xml_cdata.c +56 -0
  34. data/ext/nokogiri/xml_cdata.h +9 -0
  35. data/ext/nokogiri/xml_comment.c +54 -0
  36. data/ext/nokogiri/xml_comment.h +9 -0
  37. data/ext/nokogiri/xml_document.c +576 -0
  38. data/ext/nokogiri/xml_document.h +23 -0
  39. data/ext/nokogiri/xml_document_fragment.c +48 -0
  40. data/ext/nokogiri/xml_document_fragment.h +10 -0
  41. data/ext/nokogiri/xml_dtd.c +202 -0
  42. data/ext/nokogiri/xml_dtd.h +10 -0
  43. data/ext/nokogiri/xml_element_content.c +123 -0
  44. data/ext/nokogiri/xml_element_content.h +10 -0
  45. data/ext/nokogiri/xml_element_decl.c +69 -0
  46. data/ext/nokogiri/xml_element_decl.h +9 -0
  47. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  48. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  49. data/ext/nokogiri/xml_entity_decl.c +110 -0
  50. data/ext/nokogiri/xml_entity_decl.h +10 -0
  51. data/ext/nokogiri/xml_entity_reference.c +52 -0
  52. data/ext/nokogiri/xml_entity_reference.h +9 -0
  53. data/ext/nokogiri/xml_io.c +56 -0
  54. data/ext/nokogiri/xml_io.h +11 -0
  55. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  56. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  57. data/ext/nokogiri/xml_namespace.c +78 -0
  58. data/ext/nokogiri/xml_namespace.h +13 -0
  59. data/ext/nokogiri/xml_node.c +1480 -0
  60. data/ext/nokogiri/xml_node.h +13 -0
  61. data/ext/nokogiri/xml_node_set.c +467 -0
  62. data/ext/nokogiri/xml_node_set.h +14 -0
  63. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  64. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  65. data/ext/nokogiri/xml_reader.c +684 -0
  66. data/ext/nokogiri/xml_reader.h +10 -0
  67. data/ext/nokogiri/xml_relax_ng.c +161 -0
  68. data/ext/nokogiri/xml_relax_ng.h +9 -0
  69. data/ext/nokogiri/xml_sax_parser.c +293 -0
  70. data/ext/nokogiri/xml_sax_parser.h +39 -0
  71. data/ext/nokogiri/xml_sax_parser_context.c +222 -0
  72. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  73. data/ext/nokogiri/xml_sax_push_parser.c +115 -0
  74. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  75. data/ext/nokogiri/xml_schema.c +205 -0
  76. data/ext/nokogiri/xml_schema.h +9 -0
  77. data/ext/nokogiri/xml_syntax_error.c +58 -0
  78. data/ext/nokogiri/xml_syntax_error.h +13 -0
  79. data/ext/nokogiri/xml_text.c +52 -0
  80. data/ext/nokogiri/xml_text.h +9 -0
  81. data/ext/nokogiri/xml_xpath_context.c +319 -0
  82. data/ext/nokogiri/xml_xpath_context.h +10 -0
  83. data/ext/nokogiri/xslt_stylesheet.c +270 -0
  84. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  85. data/lib/nokogiri.rb +127 -0
  86. data/lib/nokogiri/css.rb +27 -0
  87. data/lib/nokogiri/css/node.rb +102 -0
  88. data/lib/nokogiri/css/parser.rb +720 -0
  89. data/lib/nokogiri/css/parser.y +258 -0
  90. data/lib/nokogiri/css/parser_extras.rb +91 -0
  91. data/lib/nokogiri/css/syntax_error.rb +7 -0
  92. data/lib/nokogiri/css/tokenizer.rb +152 -0
  93. data/lib/nokogiri/css/tokenizer.rex +55 -0
  94. data/lib/nokogiri/css/xpath_visitor.rb +171 -0
  95. data/lib/nokogiri/decorators/slop.rb +35 -0
  96. data/lib/nokogiri/html.rb +37 -0
  97. data/lib/nokogiri/html/builder.rb +35 -0
  98. data/lib/nokogiri/html/document.rb +254 -0
  99. data/lib/nokogiri/html/document_fragment.rb +41 -0
  100. data/lib/nokogiri/html/element_description.rb +23 -0
  101. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  102. data/lib/nokogiri/html/entity_lookup.rb +13 -0
  103. data/lib/nokogiri/html/sax/parser.rb +52 -0
  104. data/lib/nokogiri/html/sax/parser_context.rb +16 -0
  105. data/lib/nokogiri/html/sax/push_parser.rb +16 -0
  106. data/lib/nokogiri/syntax_error.rb +4 -0
  107. data/lib/nokogiri/version.rb +88 -0
  108. data/lib/nokogiri/xml.rb +73 -0
  109. data/lib/nokogiri/xml/attr.rb +14 -0
  110. data/lib/nokogiri/xml/attribute_decl.rb +18 -0
  111. data/lib/nokogiri/xml/builder.rb +431 -0
  112. data/lib/nokogiri/xml/cdata.rb +11 -0
  113. data/lib/nokogiri/xml/character_data.rb +7 -0
  114. data/lib/nokogiri/xml/document.rb +267 -0
  115. data/lib/nokogiri/xml/document_fragment.rb +103 -0
  116. data/lib/nokogiri/xml/dtd.rb +22 -0
  117. data/lib/nokogiri/xml/element_content.rb +36 -0
  118. data/lib/nokogiri/xml/element_decl.rb +13 -0
  119. data/lib/nokogiri/xml/entity_decl.rb +19 -0
  120. data/lib/nokogiri/xml/namespace.rb +13 -0
  121. data/lib/nokogiri/xml/node.rb +946 -0
  122. data/lib/nokogiri/xml/node/save_options.rb +61 -0
  123. data/lib/nokogiri/xml/node_set.rb +357 -0
  124. data/lib/nokogiri/xml/notation.rb +6 -0
  125. data/lib/nokogiri/xml/parse_options.rb +98 -0
  126. data/lib/nokogiri/xml/pp.rb +2 -0
  127. data/lib/nokogiri/xml/pp/character_data.rb +18 -0
  128. data/lib/nokogiri/xml/pp/node.rb +56 -0
  129. data/lib/nokogiri/xml/processing_instruction.rb +8 -0
  130. data/lib/nokogiri/xml/reader.rb +112 -0
  131. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  132. data/lib/nokogiri/xml/sax.rb +4 -0
  133. data/lib/nokogiri/xml/sax/document.rb +164 -0
  134. data/lib/nokogiri/xml/sax/parser.rb +115 -0
  135. data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
  136. data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
  137. data/lib/nokogiri/xml/schema.rb +63 -0
  138. data/lib/nokogiri/xml/syntax_error.rb +47 -0
  139. data/lib/nokogiri/xml/text.rb +9 -0
  140. data/lib/nokogiri/xml/xpath.rb +10 -0
  141. data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
  142. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  143. data/lib/nokogiri/xslt.rb +56 -0
  144. data/lib/nokogiri/xslt/stylesheet.rb +25 -0
  145. data/lib/xsd/xmlparser/nokogiri.rb +90 -0
  146. data/tasks/cross_compile.rb +153 -0
  147. data/tasks/nokogiri.org.rb +24 -0
  148. data/tasks/test.rb +95 -0
  149. data/test/css/test_nthiness.rb +159 -0
  150. data/test/css/test_parser.rb +341 -0
  151. data/test/css/test_tokenizer.rb +198 -0
  152. data/test/css/test_xpath_visitor.rb +91 -0
  153. data/test/decorators/test_slop.rb +16 -0
  154. data/test/files/2ch.html +108 -0
  155. data/test/files/address_book.rlx +12 -0
  156. data/test/files/address_book.xml +10 -0
  157. data/test/files/bar/bar.xsd +4 -0
  158. data/test/files/dont_hurt_em_why.xml +422 -0
  159. data/test/files/encoding.html +82 -0
  160. data/test/files/encoding.xhtml +84 -0
  161. data/test/files/exslt.xml +8 -0
  162. data/test/files/exslt.xslt +35 -0
  163. data/test/files/foo/foo.xsd +4 -0
  164. data/test/files/metacharset.html +10 -0
  165. data/test/files/noencoding.html +47 -0
  166. data/test/files/po.xml +32 -0
  167. data/test/files/po.xsd +66 -0
  168. data/test/files/shift_jis.html +10 -0
  169. data/test/files/shift_jis.xml +5 -0
  170. data/test/files/snuggles.xml +3 -0
  171. data/test/files/staff.dtd +10 -0
  172. data/test/files/staff.xml +59 -0
  173. data/test/files/staff.xslt +32 -0
  174. data/test/files/tlm.html +850 -0
  175. data/test/files/to_be_xincluded.xml +2 -0
  176. data/test/files/valid_bar.xml +2 -0
  177. data/test/files/xinclude.xml +4 -0
  178. data/test/helper.rb +147 -0
  179. data/test/html/sax/test_parser.rb +138 -0
  180. data/test/html/sax/test_parser_context.rb +46 -0
  181. data/test/html/test_builder.rb +164 -0
  182. data/test/html/test_document.rb +529 -0
  183. data/test/html/test_document_encoding.rb +138 -0
  184. data/test/html/test_document_fragment.rb +254 -0
  185. data/test/html/test_element_description.rb +100 -0
  186. data/test/html/test_named_characters.rb +14 -0
  187. data/test/html/test_node.rb +188 -0
  188. data/test/html/test_node_encoding.rb +27 -0
  189. data/test/test_convert_xpath.rb +135 -0
  190. data/test/test_css_cache.rb +45 -0
  191. data/test/test_encoding_handler.rb +46 -0
  192. data/test/test_memory_leak.rb +152 -0
  193. data/test/test_nokogiri.rb +132 -0
  194. data/test/test_reader.rb +488 -0
  195. data/test/test_soap4r_sax.rb +52 -0
  196. data/test/test_xslt_transforms.rb +254 -0
  197. data/test/xml/node/test_save_options.rb +28 -0
  198. data/test/xml/node/test_subclass.rb +44 -0
  199. data/test/xml/sax/test_parser.rb +338 -0
  200. data/test/xml/sax/test_parser_context.rb +106 -0
  201. data/test/xml/sax/test_push_parser.rb +157 -0
  202. data/test/xml/test_attr.rb +64 -0
  203. data/test/xml/test_attribute_decl.rb +86 -0
  204. data/test/xml/test_builder.rb +248 -0
  205. data/test/xml/test_c14n.rb +151 -0
  206. data/test/xml/test_cdata.rb +48 -0
  207. data/test/xml/test_comment.rb +29 -0
  208. data/test/xml/test_document.rb +742 -0
  209. data/test/xml/test_document_encoding.rb +28 -0
  210. data/test/xml/test_document_fragment.rb +216 -0
  211. data/test/xml/test_dtd.rb +103 -0
  212. data/test/xml/test_dtd_encoding.rb +33 -0
  213. data/test/xml/test_element_content.rb +56 -0
  214. data/test/xml/test_element_decl.rb +73 -0
  215. data/test/xml/test_entity_decl.rb +122 -0
  216. data/test/xml/test_entity_reference.rb +235 -0
  217. data/test/xml/test_namespace.rb +75 -0
  218. data/test/xml/test_node.rb +1029 -0
  219. data/test/xml/test_node_attributes.rb +53 -0
  220. data/test/xml/test_node_encoding.rb +107 -0
  221. data/test/xml/test_node_inheritance.rb +32 -0
  222. data/test/xml/test_node_reparenting.rb +374 -0
  223. data/test/xml/test_node_set.rb +755 -0
  224. data/test/xml/test_parse_options.rb +64 -0
  225. data/test/xml/test_processing_instruction.rb +30 -0
  226. data/test/xml/test_reader_encoding.rb +142 -0
  227. data/test/xml/test_relax_ng.rb +60 -0
  228. data/test/xml/test_schema.rb +94 -0
  229. data/test/xml/test_syntax_error.rb +12 -0
  230. data/test/xml/test_text.rb +45 -0
  231. data/test/xml/test_unparented_node.rb +413 -0
  232. data/test/xml/test_xinclude.rb +83 -0
  233. data/test/xml/test_xpath.rb +295 -0
  234. data/test/xslt/test_custom_functions.rb +129 -0
  235. data/test/xslt/test_exception_handling.rb +37 -0
  236. data/test_all +84 -0
  237. metadata +534 -0
@@ -0,0 +1,151 @@
1
+ require "helper"
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestC14N < Nokogiri::TestCase
6
+ # http://www.w3.org/TR/xml-c14n#Example-OutsideDoc
7
+ def test_3_1
8
+ doc = Nokogiri.XML <<-eoxml
9
+ <?xml version="1.0"?>
10
+
11
+ <?xml-stylesheet href="doc.xsl"
12
+ type="text/xsl" ?>
13
+
14
+ <!DOCTYPE doc SYSTEM "doc.dtd">
15
+
16
+ <doc>Hello, world!<!-- Comment 1 --></doc>
17
+
18
+ <?pi-without-data ?>
19
+
20
+ <!-- Comment 2 -->
21
+
22
+ <!-- Comment 3 -->
23
+ eoxml
24
+
25
+ c14n = doc.canonicalize
26
+ assert_no_match(/version=/, c14n)
27
+ assert_match(/Hello, world/, c14n)
28
+ assert_no_match(/Comment/, c14n)
29
+ c14n = doc.canonicalize(nil, nil, true)
30
+ assert_match(/Comment/, c14n)
31
+ end
32
+
33
+ def test_exclude_block_params
34
+ xml = '<a><b></b></a>'
35
+ doc = Nokogiri.XML xml
36
+
37
+ list = []
38
+ doc.canonicalize do |node, parent|
39
+ list << [node, parent]
40
+ true
41
+ end
42
+ if Nokogiri.jruby?
43
+ assert_equal(
44
+ ['a', 'document', 'document', nil, 'b', 'a'],
45
+ list.flatten.map { |x| x ? x.name : x }
46
+ )
47
+ else
48
+ assert_equal(
49
+ ['a', 'document', 'document', nil, 'b', 'a', 'a', 'document'],
50
+ list.flatten.map { |x| x ? x.name : x }
51
+ )
52
+ end
53
+ end
54
+
55
+ def test_exclude_block_true
56
+ xml = '<a><b></b></a>'
57
+ doc = Nokogiri.XML xml
58
+
59
+ c14n = doc.canonicalize do |node, parent|
60
+ true
61
+ end
62
+ assert_equal xml, c14n
63
+ end
64
+
65
+ def test_exclude_block_false
66
+ xml = '<a><b></b></a>'
67
+ doc = Nokogiri.XML xml
68
+
69
+ c14n = doc.canonicalize do |node, parent|
70
+ false
71
+ end
72
+ assert_equal '', c14n
73
+ end
74
+
75
+ def test_exclude_block_nil
76
+ xml = '<a><b></b></a>'
77
+ doc = Nokogiri.XML xml
78
+
79
+ c14n = doc.canonicalize do |node, parent|
80
+ nil
81
+ end
82
+ assert_equal '', c14n
83
+ end
84
+
85
+ def test_exclude_block_object
86
+ xml = '<a><b></b></a>'
87
+ doc = Nokogiri.XML xml
88
+
89
+ c14n = doc.canonicalize do |node, parent|
90
+ Object.new
91
+ end
92
+ assert_equal xml, c14n
93
+ end
94
+
95
+ def test_c14n_node
96
+ xml = '<a><b><c></c></b></a>'
97
+ doc = Nokogiri.XML xml
98
+ c14n = doc.at_xpath('//b').canonicalize
99
+ assert_equal '<b><c></c></b>', c14n
100
+ end
101
+
102
+ def test_c14n_modes
103
+ skip("C14N Exclusive implementation will complete by next version after 1.5.1") if Nokogiri.jruby?
104
+ # http://www.w3.org/TR/xml-exc-c14n/#sec-Enveloping
105
+
106
+ doc1 = Nokogiri.XML <<-eoxml
107
+ <n0:local xmlns:n0="http://foobar.org" xmlns:n3="ftp://example.org">
108
+ <n1:elem2 xmlns:n1="http://example.net" xml:lang="en">
109
+ <n3:stuff xmlns:n3="ftp://example.org"/>
110
+ </n1:elem2>
111
+ </n0:local>
112
+ eoxml
113
+ doc2 = Nokogiri.XML <<-eoxml
114
+ <n2:pdu xmlns:n1="http://example.com"
115
+ xmlns:n2="http://foo.example"
116
+ xml:lang="fr"
117
+ xml:space="retain">
118
+ <n1:elem2 xmlns:n1="http://example.net" xml:lang="en">
119
+ <n3:stuff xmlns:n3="ftp://example.org"/>
120
+ </n1:elem2>
121
+ </n2:pdu>
122
+ eoxml
123
+
124
+ c14n = doc1.at_xpath('//n1:elem2', {'n1' => 'http://example.net'}).canonicalize
125
+ assert_equal '<n1:elem2 xmlns:n0="http://foobar.org" xmlns:n1="http://example.net" xmlns:n3="ftp://example.org" xml:lang="en">
126
+ <n3:stuff></n3:stuff>
127
+ </n1:elem2>', c14n
128
+ c14n = doc2.at_xpath('//n1:elem2', {'n1' => 'http://example.net'}).canonicalize
129
+ assert_equal '<n1:elem2 xmlns:n1="http://example.net" xmlns:n2="http://foo.example" xml:lang="en" xml:space="retain">
130
+ <n3:stuff xmlns:n3="ftp://example.org"></n3:stuff>
131
+ </n1:elem2>', c14n
132
+
133
+ excl_c14n = '<n1:elem2 xmlns:n1="http://example.net" xml:lang="en">
134
+ <n3:stuff xmlns:n3="ftp://example.org"></n3:stuff>
135
+ </n1:elem2>'
136
+ c14n = doc1.at_xpath('//n1:elem2', {'n1' => 'http://example.net'}).canonicalize(XML::XML_C14N_EXCLUSIVE_1_0)
137
+ assert_equal excl_c14n, c14n
138
+ c14n = doc2.at_xpath('//n1:elem2', {'n1' => 'http://example.net'}).canonicalize(XML::XML_C14N_EXCLUSIVE_1_0)
139
+ assert_equal excl_c14n, c14n
140
+
141
+ c14n = doc2.at_xpath('//n1:elem2', {'n1' => 'http://example.net'}).canonicalize(XML::XML_C14N_EXCLUSIVE_1_0, ['n2'])
142
+ assert_equal '<n1:elem2 xmlns:n1="http://example.net" xmlns:n2="http://foo.example" xml:lang="en">
143
+ <n3:stuff xmlns:n3="ftp://example.org"></n3:stuff>
144
+ </n1:elem2>', c14n
145
+
146
+ end
147
+
148
+
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,48 @@
1
+ require "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
+ assert 100.times { CDATA.new(@xml, "asdfasdf") }
33
+ end
34
+
35
+ def test_content=
36
+ node = CDATA.new(@xml, 'foo')
37
+ assert_equal('foo', node.content)
38
+
39
+ node.content = '& <foo> &amp;'
40
+ assert_equal('& <foo> &amp;', node.content)
41
+ assert_equal('<![CDATA[& <foo> &amp;]]>', node.to_xml)
42
+
43
+ node.content = 'foo ]]> bar'
44
+ assert_equal('foo ]]> bar', node.content)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,29 @@
1
+ require "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_comment?
17
+ comment = Nokogiri::XML::Comment.new(@xml, 'hello world')
18
+ assert(comment.comment?)
19
+ assert(!@xml.root.comment?)
20
+ end
21
+
22
+ def test_many_comments
23
+ 100.times {
24
+ Nokogiri::XML::Comment.new(@xml, 'hello world')
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,742 @@
1
+ require "helper"
2
+
3
+ require 'uri'
4
+
5
+ module Nokogiri
6
+ module XML
7
+ class TestDocument < Nokogiri::TestCase
8
+ URI = if URI.const_defined?(:DEFAULT_PARSER)
9
+ ::URI::DEFAULT_PARSER
10
+ else
11
+ ::URI
12
+ end
13
+
14
+ def setup
15
+ super
16
+ @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
17
+ end
18
+
19
+ def test_root_set_to_nil
20
+ @xml.root = nil
21
+ assert_equal nil, @xml.root
22
+ end
23
+
24
+ def test_collect_namespaces
25
+ doc = Nokogiri::XML(<<-eoxml)
26
+ <xml>
27
+ <foo xmlns='hello'>
28
+ <bar xmlns:foo='world' />
29
+ </foo>
30
+ </xml>
31
+ eoxml
32
+ assert_equal({"xmlns"=>"hello", "xmlns:foo"=>"world"},
33
+ doc.collect_namespaces)
34
+ end
35
+
36
+ def test_subclass_initialize_modify # testing a segv
37
+ Class.new(Nokogiri::XML::Document) {
38
+ def initialize
39
+ super
40
+ body_node = Nokogiri::XML::Node.new "body", self
41
+ body_node.content = "stuff"
42
+ self.root = body_node
43
+ end
44
+ }.new
45
+ end
46
+
47
+ def test_create_text_node
48
+ txt = @xml.create_text_node 'foo'
49
+ assert_instance_of Nokogiri::XML::Text, txt
50
+ assert_equal 'foo', txt.text
51
+ assert_equal @xml, txt.document
52
+ end
53
+
54
+ def test_create_text_node_with_block
55
+ @xml.create_text_node 'foo' do |txt|
56
+ assert_instance_of Nokogiri::XML::Text, txt
57
+ assert_equal 'foo', txt.text
58
+ assert_equal @xml, txt.document
59
+ end
60
+ end
61
+
62
+ def test_create_element
63
+ elm = @xml.create_element('foo')
64
+ assert_instance_of Nokogiri::XML::Element, elm
65
+ assert_equal 'foo', elm.name
66
+ assert_equal @xml, elm.document
67
+ end
68
+
69
+ def test_create_element_with_block
70
+ @xml.create_element('foo') do |elm|
71
+ assert_instance_of Nokogiri::XML::Element, elm
72
+ assert_equal 'foo', elm.name
73
+ assert_equal @xml, elm.document
74
+ end
75
+ end
76
+
77
+ def test_create_element_with_attributes
78
+ elm = @xml.create_element('foo',:a => "1")
79
+ assert_instance_of Nokogiri::XML::Element, elm
80
+ assert_instance_of Nokogiri::XML::Attr, elm.attributes["a"]
81
+ assert_equal "1", elm["a"]
82
+ end
83
+
84
+ def test_create_element_with_namespace
85
+ elm = @xml.create_element('foo',:'xmlns:foo' => 'http://tenderlovemaking.com')
86
+ assert_equal 'http://tenderlovemaking.com', elm.namespaces['xmlns:foo']
87
+ end
88
+
89
+ def test_create_element_with_hyphenated_namespace
90
+ elm = @xml.create_element('foo',:'xmlns:SOAP-ENC' => 'http://tenderlovemaking.com')
91
+ assert_equal 'http://tenderlovemaking.com', elm.namespaces['xmlns:SOAP-ENC']
92
+ end
93
+
94
+ def test_create_element_with_content
95
+ elm = @xml.create_element('foo',"needs more xml/violence")
96
+ assert_equal "needs more xml/violence", elm.content
97
+ end
98
+
99
+ def test_create_cdata
100
+ cdata = @xml.create_cdata("abc")
101
+ assert_instance_of Nokogiri::XML::CDATA, cdata
102
+ assert_equal "abc", cdata.content
103
+ end
104
+
105
+ def test_create_cdata_with_block
106
+ @xml.create_cdata("abc") do |cdata|
107
+ assert_instance_of Nokogiri::XML::CDATA, cdata
108
+ assert_equal "abc", cdata.content
109
+ end
110
+ end
111
+
112
+ def test_create_comment
113
+ comment = @xml.create_comment("abc")
114
+ assert_instance_of Nokogiri::XML::Comment, comment
115
+ assert_equal "abc", comment.content
116
+ end
117
+
118
+ def test_create_comment_with_block
119
+ @xml.create_comment("abc") do |comment|
120
+ assert_instance_of Nokogiri::XML::Comment, comment
121
+ assert_equal "abc", comment.content
122
+ end
123
+ end
124
+
125
+ def test_pp
126
+ out = StringIO.new('')
127
+ ::PP.pp @xml, out
128
+ assert_operator out.string.length, :>, 0
129
+ end
130
+
131
+ def test_create_internal_subset_on_existing_subset
132
+ assert_not_nil @xml.internal_subset
133
+ assert_raises(RuntimeError) do
134
+ @xml.create_internal_subset('staff', nil, 'staff.dtd')
135
+ end
136
+ end
137
+
138
+ def test_create_internal_subset
139
+ xml = Nokogiri::XML('<root />')
140
+ assert_nil xml.internal_subset
141
+
142
+ xml.create_internal_subset('name', nil, 'staff.dtd')
143
+ ss = xml.internal_subset
144
+ assert_equal 'name', ss.name
145
+ assert_nil ss.external_id
146
+ assert_equal 'staff.dtd', ss.system_id
147
+ end
148
+
149
+ def test_external_subset
150
+ assert_nil @xml.external_subset
151
+ Dir.chdir(ASSETS_DIR) do
152
+ @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) { |cfg|
153
+ cfg.dtdload
154
+ }
155
+ end
156
+ assert @xml.external_subset
157
+ end
158
+
159
+ def test_create_external_subset_fails_with_existing_subset
160
+ assert_nil @xml.external_subset
161
+ Dir.chdir(ASSETS_DIR) do
162
+ @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) { |cfg|
163
+ cfg.dtdload
164
+ }
165
+ end
166
+ assert @xml.external_subset
167
+
168
+ assert_raises(RuntimeError) do
169
+ @xml.create_external_subset('staff', nil, 'staff.dtd')
170
+ end
171
+ end
172
+
173
+ def test_create_external_subset
174
+ dtd = @xml.create_external_subset('staff', nil, 'staff.dtd')
175
+ assert_nil dtd.external_id
176
+ assert_equal 'staff.dtd', dtd.system_id
177
+ assert_equal 'staff', dtd.name
178
+ assert_equal dtd, @xml.external_subset
179
+ end
180
+
181
+ def test_version
182
+ assert_equal '1.0', @xml.version
183
+ end
184
+
185
+ def test_add_namespace
186
+ assert_raise NoMethodError do
187
+ @xml.add_namespace('foo', 'bar')
188
+ end
189
+ end
190
+
191
+ def test_attributes
192
+ assert_raise NoMethodError do
193
+ @xml.attributes
194
+ end
195
+ end
196
+
197
+ def test_namespace
198
+ assert_raise NoMethodError do
199
+ @xml.namespace
200
+ end
201
+ end
202
+
203
+ def test_namespace_definitions
204
+ assert_raise NoMethodError do
205
+ @xml.namespace_definitions
206
+ end
207
+ end
208
+
209
+ def test_line
210
+ assert_raise NoMethodError do
211
+ @xml.line
212
+ end
213
+ end
214
+
215
+ def test_empty_node_converted_to_html_is_not_self_closing
216
+ doc = Nokogiri::XML('<a></a>')
217
+ assert_equal "<a></a>", doc.inner_html
218
+ end
219
+
220
+ def test_fragment
221
+ fragment = @xml.fragment
222
+ assert_equal 0, fragment.children.length
223
+ end
224
+
225
+ def test_add_child_fragment_with_single_node
226
+ doc = Nokogiri::XML::Document.new
227
+ fragment = doc.fragment('<hello />')
228
+ doc.add_child fragment
229
+ assert_equal '/hello', doc.at('//hello').path
230
+ assert_equal 'hello', doc.root.name
231
+ end
232
+
233
+ def test_add_child_fragment_with_multiple_nodes
234
+ doc = Nokogiri::XML::Document.new
235
+ fragment = doc.fragment('<hello /><goodbye />')
236
+ assert_raises(RuntimeError) do
237
+ doc.add_child fragment
238
+ end
239
+ end
240
+
241
+ def test_add_child_with_multiple_roots
242
+ assert_raises(RuntimeError) do
243
+ @xml << Node.new('foo', @xml)
244
+ end
245
+ end
246
+
247
+ def test_add_child_with_string
248
+ doc = Nokogiri::XML::Document.new
249
+ doc.add_child "<div>quack!</div>"
250
+ assert_equal 1, doc.root.children.length
251
+ assert_equal "quack!", doc.root.children.first.content
252
+ end
253
+
254
+ def test_move_root_to_document_with_no_root
255
+ sender = Nokogiri::XML('<root>foo</root>')
256
+ newdoc = Nokogiri::XML::Document.new
257
+ newdoc.root = sender.root
258
+ end
259
+
260
+ def test_move_root_with_existing_root_gets_gcd
261
+ doc = Nokogiri::XML('<root>test</root>')
262
+ doc2 = Nokogiri::XML("<root>#{'x' * 5000000}</root>")
263
+ doc2.root = doc.root
264
+ end
265
+
266
+ def test_validate
267
+ if Nokogiri.uses_libxml?
268
+ assert_equal 44, @xml.validate.length
269
+ else
270
+ xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) {|cfg| cfg.dtdvalid}
271
+ assert_equal 40, xml.validate.length
272
+ end
273
+ end
274
+
275
+ def test_validate_no_internal_subset
276
+ doc = Nokogiri::XML('<test/>')
277
+ assert_nil doc.validate
278
+ end
279
+
280
+ def test_clone
281
+ assert @xml.clone
282
+ end
283
+
284
+ def test_document_should_not_have_default_ns
285
+ doc = Nokogiri::XML::Document.new
286
+
287
+ assert_raises NoMethodError do
288
+ doc.default_namespace = 'http://innernet.com/'
289
+ end
290
+
291
+ assert_raises NoMethodError do
292
+ doc.add_namespace_definition('foo', 'bar')
293
+ end
294
+ end
295
+
296
+ def test_parse_handles_nil_gracefully
297
+ @doc = Nokogiri::XML::Document.parse(nil)
298
+ assert_instance_of Nokogiri::XML::Document, @doc
299
+ end
300
+
301
+ def test_parse_takes_block
302
+ options = nil
303
+ Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) do |cfg|
304
+ options = cfg
305
+ end
306
+ assert options
307
+ end
308
+
309
+ def test_parse_yields_parse_options
310
+ options = nil
311
+ Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE) do |cfg|
312
+ options = cfg
313
+ options.nonet.nowarning.dtdattr
314
+ end
315
+ assert options.nonet?
316
+ assert options.nowarning?
317
+ assert options.dtdattr?
318
+ end
319
+
320
+ def test_XML_takes_block
321
+ options = nil
322
+ Nokogiri::XML(File.read(XML_FILE), XML_FILE) do |cfg|
323
+ options = cfg
324
+ options.nonet.nowarning.dtdattr
325
+ end
326
+ assert options.nonet?
327
+ assert options.nowarning?
328
+ assert options.dtdattr?
329
+ end
330
+
331
+ def test_subclass
332
+ klass = Class.new(Nokogiri::XML::Document)
333
+ doc = klass.new
334
+ assert_instance_of klass, doc
335
+ end
336
+
337
+ def test_subclass_initialize
338
+ klass = Class.new(Nokogiri::XML::Document) do
339
+ attr_accessor :initialized_with
340
+
341
+ def initialize(*args)
342
+ @initialized_with = args
343
+ end
344
+ end
345
+ doc = klass.new("1.0", 1)
346
+ assert_equal ["1.0", 1], doc.initialized_with
347
+ end
348
+
349
+ def test_subclass_dup
350
+ klass = Class.new(Nokogiri::XML::Document)
351
+ doc = klass.new.dup
352
+ assert_instance_of klass, doc
353
+ end
354
+
355
+ def test_subclass_parse
356
+ klass = Class.new(Nokogiri::XML::Document)
357
+ doc = klass.parse(File.read(XML_FILE))
358
+ # lame hack uses root to avoid comparing DOCTYPE tags which can appear out of order.
359
+ # I should really finish lorax and use that here.
360
+ assert_equal @xml.root.to_s, doc.root.to_s
361
+ assert_instance_of klass, doc
362
+ end
363
+
364
+ def test_document_parse_method
365
+ xml = Nokogiri::XML::Document.parse(File.read(XML_FILE))
366
+ # lame hack uses root to avoid comparing DOCTYPE tags which can appear out of order.
367
+ # I should really finish lorax and use that here.
368
+ assert_equal @xml.root.to_s, xml.root.to_s
369
+ end
370
+
371
+ def test_encoding=
372
+ @xml.encoding = 'UTF-8'
373
+ assert_match 'UTF-8', @xml.to_xml
374
+
375
+ @xml.encoding = 'EUC-JP'
376
+ assert_match 'EUC-JP', @xml.to_xml
377
+ end
378
+
379
+ def test_namespace_should_not_exist
380
+ assert_raises(NoMethodError) {
381
+ @xml.namespace
382
+ }
383
+ end
384
+
385
+ def test_non_existant_function
386
+ # WTF. I don't know why this is different between MRI and Jruby
387
+ # They should be the same... Either way, raising an exception
388
+ # is the correct thing to do.
389
+ exception = RuntimeError
390
+
391
+ if !Nokogiri.uses_libxml? || (Nokogiri.uses_libxml? && Nokogiri::VERSION_INFO['libxml']['platform'] == 'jruby')
392
+ exception = Nokogiri::XML::XPath::SyntaxError
393
+ end
394
+
395
+ assert_raises(exception) {
396
+ @xml.xpath('//name[foo()]')
397
+ }
398
+ end
399
+
400
+ def test_ancestors
401
+ assert_equal 0, @xml.ancestors.length
402
+ end
403
+
404
+ def test_root_node_parent_is_document
405
+ parent = @xml.root.parent
406
+ assert_equal @xml, parent
407
+ assert_instance_of Nokogiri::XML::Document, parent
408
+ end
409
+
410
+ def test_xmlns_is_automatically_registered
411
+ doc = Nokogiri::XML(<<-eoxml)
412
+ <root xmlns="http://tenderlovemaking.com/">
413
+ <foo>
414
+ bar
415
+ </foo>
416
+ </root>
417
+ eoxml
418
+ assert_equal 1, doc.css('xmlns|foo').length
419
+ assert_equal 1, doc.css('foo').length
420
+ assert_equal 0, doc.css('|foo').length
421
+ assert_equal 1, doc.xpath('//xmlns:foo').length
422
+ assert_equal 1, doc.search('xmlns|foo').length
423
+ assert_equal 1, doc.search('//xmlns:foo').length
424
+ assert doc.at('xmlns|foo')
425
+ assert doc.at('//xmlns:foo')
426
+ assert doc.at('foo')
427
+ end
428
+
429
+ def test_xmlns_is_registered_for_nodesets
430
+ doc = Nokogiri::XML(<<-eoxml)
431
+ <root xmlns="http://tenderlovemaking.com/">
432
+ <foo>
433
+ <bar>
434
+ baz
435
+ </bar>
436
+ </foo>
437
+ </root>
438
+ eoxml
439
+ assert_equal 1, doc.css('xmlns|foo').css('xmlns|bar').length
440
+ assert_equal 1, doc.css('foo').css('bar').length
441
+ assert_equal 1, doc.xpath('//xmlns:foo').xpath('./xmlns:bar').length
442
+ assert_equal 1, doc.search('xmlns|foo').search('xmlns|bar').length
443
+ assert_equal 1, doc.search('//xmlns:foo').search('./xmlns:bar').length
444
+ end
445
+
446
+ def test_to_xml_with_indent
447
+ doc = Nokogiri::XML('<root><foo><bar/></foo></root>')
448
+ doc = Nokogiri::XML(doc.to_xml(:indent => 5))
449
+
450
+ assert_indent 5, doc
451
+ end
452
+
453
+ def test_write_xml_to_with_indent
454
+ io = StringIO.new
455
+ doc = Nokogiri::XML('<root><foo><bar/></foo></root>')
456
+ doc.write_xml_to io, :indent => 5
457
+ io.rewind
458
+ doc = Nokogiri::XML(io.read)
459
+ assert_indent 5, doc
460
+ end
461
+
462
+ # wtf... osx's libxml sucks.
463
+ unless !Nokogiri.uses_libxml? || Nokogiri::LIBXML_VERSION =~ /^2\.6\./
464
+ def test_encoding
465
+ xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE, 'UTF-8')
466
+ assert_equal 'UTF-8', xml.encoding
467
+ end
468
+ end
469
+
470
+ def test_document_has_errors
471
+ doc = Nokogiri::XML(<<-eoxml)
472
+ <foo><bar></foo>
473
+ eoxml
474
+ assert doc.errors.length > 0
475
+ doc.errors.each do |error|
476
+ assert_match error.message, error.inspect
477
+ assert_match error.message, error.to_s
478
+ end
479
+ end
480
+
481
+ def test_strict_document_throws_syntax_error
482
+ assert_raises(Nokogiri::XML::SyntaxError) {
483
+ Nokogiri::XML('<foo><bar></foo>', nil, nil, 0)
484
+ }
485
+
486
+ assert_raises(Nokogiri::XML::SyntaxError) {
487
+ Nokogiri::XML('<foo><bar></foo>') { |cfg|
488
+ cfg.strict
489
+ }
490
+ }
491
+
492
+ assert_raises(Nokogiri::XML::SyntaxError) {
493
+ Nokogiri::XML(StringIO.new('<foo><bar></foo>')) { |cfg|
494
+ cfg.strict
495
+ }
496
+ }
497
+ end
498
+
499
+ def test_XML_function
500
+ xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
501
+ assert xml.xml?
502
+ end
503
+
504
+ def test_url
505
+ assert @xml.url
506
+ assert_equal XML_FILE, URI.unescape(@xml.url).sub('file:///', '')
507
+ end
508
+
509
+ def test_document_parent
510
+ xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
511
+ assert_raises(NoMethodError) {
512
+ xml.parent
513
+ }
514
+ end
515
+
516
+ def test_document_name
517
+ xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
518
+ assert_equal 'document', xml.name
519
+ end
520
+
521
+ def test_parse_can_take_io
522
+ xml = nil
523
+ File.open(XML_FILE, 'rb') { |f|
524
+ xml = Nokogiri::XML(f)
525
+ }
526
+ assert xml.xml?
527
+ set = xml.search('//employee')
528
+ assert set.length > 0
529
+ end
530
+
531
+ def test_search_on_empty_documents
532
+ doc = Nokogiri::XML::Document.new
533
+ ns = doc.search('//foo')
534
+ assert_equal 0, ns.length
535
+
536
+ ns = doc.css('foo')
537
+ assert_equal 0, ns.length
538
+
539
+ ns = doc.xpath('//foo')
540
+ assert_equal 0, ns.length
541
+ end
542
+
543
+ def test_bad_xpath_raises_syntax_error
544
+ assert_raises(XML::XPath::SyntaxError) {
545
+ @xml.xpath('\\')
546
+ }
547
+ end
548
+
549
+ def test_find_with_namespace
550
+ doc = Nokogiri::XML.parse(<<-eoxml)
551
+ <x xmlns:tenderlove='http://tenderlovemaking.com/'>
552
+ <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
553
+ </x>
554
+ eoxml
555
+
556
+ ctx = Nokogiri::XML::XPathContext.new(doc)
557
+ ctx.register_ns 'tenderlove', 'http://tenderlovemaking.com/'
558
+ set = ctx.evaluate('//tenderlove:foo')
559
+ assert_equal 1, set.length
560
+ assert_equal 'foo', set.first.name
561
+
562
+ # It looks like only the URI is important:
563
+ ctx = Nokogiri::XML::XPathContext.new(doc)
564
+ ctx.register_ns 'america', 'http://tenderlovemaking.com/'
565
+ set = ctx.evaluate('//america:foo')
566
+ assert_equal 1, set.length
567
+ assert_equal 'foo', set.first.name
568
+
569
+ # Its so important that a missing slash will cause it to return nothing
570
+ ctx = Nokogiri::XML::XPathContext.new(doc)
571
+ ctx.register_ns 'america', 'http://tenderlovemaking.com'
572
+ set = ctx.evaluate('//america:foo')
573
+ assert_equal 0, set.length
574
+ end
575
+
576
+ def test_xml?
577
+ assert @xml.xml?
578
+ end
579
+
580
+ def test_document
581
+ assert @xml.document
582
+ end
583
+
584
+ def test_singleton_methods
585
+ assert node_set = @xml.search('//name')
586
+ assert node_set.length > 0
587
+ node = node_set.first
588
+ def node.test
589
+ 'test'
590
+ end
591
+ assert node_set = @xml.search('//name')
592
+ assert_equal 'test', node_set.first.test
593
+ end
594
+
595
+ def test_multiple_search
596
+ assert node_set = @xml.search('//employee', '//name')
597
+ employees = @xml.search('//employee')
598
+ names = @xml.search('//name')
599
+ assert_equal(employees.length + names.length, node_set.length)
600
+ end
601
+
602
+ def test_node_set_index
603
+ assert node_set = @xml.search('//employee')
604
+
605
+ assert_equal(5, node_set.length)
606
+ assert node_set[4]
607
+ assert_nil node_set[5]
608
+ end
609
+
610
+ def test_search
611
+ assert node_set = @xml.search('//employee')
612
+
613
+ assert_equal(5, node_set.length)
614
+
615
+ node_set.each do |node|
616
+ assert_equal('employee', node.name)
617
+ end
618
+ end
619
+
620
+ def test_dump
621
+ assert @xml.serialize
622
+ assert @xml.to_xml
623
+ end
624
+
625
+ def test_dup
626
+ dup = @xml.dup
627
+ assert_instance_of Nokogiri::XML::Document, dup
628
+ assert dup.xml?, 'duplicate should be xml'
629
+ end
630
+
631
+ def test_new
632
+ doc = nil
633
+ doc = Nokogiri::XML::Document.new
634
+ assert doc
635
+ assert doc.xml?
636
+ assert_nil doc.root
637
+ end
638
+
639
+ def test_set_root
640
+ doc = nil
641
+ doc = Nokogiri::XML::Document.new
642
+ assert doc
643
+ assert doc.xml?
644
+ assert_nil doc.root
645
+ node = Nokogiri::XML::Node.new("b", doc) { |n|
646
+ n.content = 'hello world'
647
+ }
648
+ assert_equal('hello world', node.content)
649
+ doc.root = node
650
+ assert_equal(node, doc.root)
651
+ end
652
+
653
+ def test_remove_namespaces
654
+ doc = Nokogiri::XML <<-EOX
655
+ <root xmlns:a="http://a.flavorjon.es/" xmlns:b="http://b.flavorjon.es/">
656
+ <a:foo>hello from a</a:foo>
657
+ <b:foo>hello from b</b:foo>
658
+ <container xmlns:c="http://c.flavorjon.es/">
659
+ <c:foo c:attr='attr-value'>hello from c</c:foo>
660
+ </container>
661
+ </root>
662
+ EOX
663
+
664
+ namespaces = doc.root.namespaces
665
+
666
+ # assert on setup
667
+ assert_equal 2, doc.root.namespaces.length
668
+ assert_equal 3, doc.at_xpath("//container").namespaces.length
669
+ assert_equal 0, doc.xpath("//foo").length
670
+ assert_equal 1, doc.xpath("//a:foo").length
671
+ assert_equal 1, doc.xpath("//a:foo").length
672
+ assert_equal 1, doc.xpath("//x:foo", "x" => "http://c.flavorjon.es/").length
673
+ assert_match %r{foo c:attr}, doc.to_xml
674
+
675
+ doc.remove_namespaces!
676
+
677
+ assert_equal 0, doc.root.namespaces.length
678
+ assert_equal 0, doc.at_xpath("//container").namespaces.length
679
+ assert_equal 3, doc.xpath("//foo").length
680
+ assert_equal 0, doc.xpath("//a:foo", namespaces).length
681
+ assert_equal 0, doc.xpath("//a:foo", namespaces).length
682
+ assert_equal 0, doc.xpath("//x:foo", "x" => "http://c.flavorjon.es/").length
683
+ assert_match %r{foo attr}, doc.to_xml
684
+ end
685
+
686
+ def test_subset_is_decorated
687
+ x = Module.new do
688
+ def awesome!
689
+ end
690
+ end
691
+ util_decorate(@xml, x)
692
+
693
+ assert @xml.respond_to?(:awesome!)
694
+ assert node_set = @xml.search('//staff')
695
+ assert node_set.respond_to?(:awesome!)
696
+ assert subset = node_set.search('.//employee')
697
+ assert subset.respond_to?(:awesome!)
698
+ assert sub_subset = node_set.search('.//name')
699
+ assert sub_subset.respond_to?(:awesome!)
700
+ end
701
+
702
+ def test_decorator_is_applied
703
+ x = Module.new do
704
+ def awesome!
705
+ end
706
+ end
707
+ util_decorate(@xml, x)
708
+
709
+ assert @xml.respond_to?(:awesome!)
710
+ assert node_set = @xml.search('//employee')
711
+ assert node_set.respond_to?(:awesome!)
712
+ node_set.each do |node|
713
+ assert node.respond_to?(:awesome!), node.class
714
+ end
715
+ assert @xml.root.respond_to?(:awesome!)
716
+ assert @xml.children.respond_to?(:awesome!)
717
+ end
718
+
719
+ def test_java_integration
720
+ if Nokogiri.jruby?
721
+ require 'java'
722
+ factory = javax.xml.parsers.DocumentBuilderFactory.newInstance
723
+ builder = factory.newDocumentBuilder
724
+ document = builder.newDocument
725
+ root = document.createElement("foo")
726
+ document.appendChild(root)
727
+ noko_doc = Nokogiri::XML::Document.wrap(document)
728
+ assert_equal 'foo', noko_doc.root.name
729
+
730
+ noko_doc = Nokogiri::XML(<<eoxml)
731
+ <foo xmlns='hello'>
732
+ <bar xmlns:foo='world' />
733
+ </foo>
734
+ eoxml
735
+ dom = noko_doc.to_java
736
+ assert dom.kind_of? org.w3c.dom.Document
737
+ assert_equal 'foo', dom.getDocumentElement().getTagName()
738
+ end
739
+ end
740
+ end
741
+ end
742
+ end