nokogiri 1.2.3-java → 1.3.0-java

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 (200) hide show
  1. data/.autotest +14 -2
  2. data/CHANGELOG.ja.rdoc +38 -0
  3. data/CHANGELOG.rdoc +43 -0
  4. data/Manifest.txt +80 -5
  5. data/README.ja.rdoc +12 -11
  6. data/README.rdoc +4 -2
  7. data/Rakefile +103 -173
  8. data/bin/nokogiri +47 -0
  9. data/ext/nokogiri/extconf.rb +19 -13
  10. data/ext/nokogiri/html_document.c +39 -3
  11. data/ext/nokogiri/html_document.h +1 -1
  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.h +1 -1
  15. data/ext/nokogiri/html_sax_parser.h +1 -1
  16. data/ext/nokogiri/{native.c → nokogiri.c} +11 -3
  17. data/ext/nokogiri/{native.h → nokogiri.h} +18 -4
  18. data/ext/nokogiri/xml_attr.c +14 -5
  19. data/ext/nokogiri/xml_attr.h +1 -1
  20. data/ext/nokogiri/xml_cdata.c +15 -6
  21. data/ext/nokogiri/xml_cdata.h +1 -1
  22. data/ext/nokogiri/xml_comment.c +13 -4
  23. data/ext/nokogiri/xml_comment.h +1 -1
  24. data/ext/nokogiri/xml_document.c +50 -41
  25. data/ext/nokogiri/xml_document.h +1 -1
  26. data/ext/nokogiri/xml_document_fragment.c +12 -4
  27. data/ext/nokogiri/xml_document_fragment.h +1 -1
  28. data/ext/nokogiri/xml_dtd.c +1 -1
  29. data/ext/nokogiri/xml_dtd.h +1 -1
  30. data/ext/nokogiri/xml_entity_reference.c +13 -4
  31. data/ext/nokogiri/xml_entity_reference.h +1 -1
  32. data/ext/nokogiri/xml_io.h +1 -1
  33. data/ext/nokogiri/xml_namespace.c +69 -0
  34. data/ext/nokogiri/xml_namespace.h +12 -0
  35. data/ext/nokogiri/xml_node.c +232 -124
  36. data/ext/nokogiri/xml_node.h +3 -4
  37. data/ext/nokogiri/xml_node_set.c +204 -17
  38. data/ext/nokogiri/xml_node_set.h +1 -1
  39. data/ext/nokogiri/xml_processing_instruction.c +14 -4
  40. data/ext/nokogiri/xml_processing_instruction.h +1 -1
  41. data/ext/nokogiri/xml_reader.c +87 -7
  42. data/ext/nokogiri/xml_reader.h +1 -1
  43. data/ext/nokogiri/xml_relax_ng.c +106 -0
  44. data/ext/nokogiri/xml_relax_ng.h +9 -0
  45. data/ext/nokogiri/xml_sax_parser.c +122 -2
  46. data/ext/nokogiri/xml_sax_parser.h +1 -1
  47. data/ext/nokogiri/xml_sax_push_parser.c +1 -0
  48. data/ext/nokogiri/xml_sax_push_parser.h +1 -1
  49. data/ext/nokogiri/xml_schema.c +107 -0
  50. data/ext/nokogiri/xml_schema.h +9 -0
  51. data/ext/nokogiri/xml_syntax_error.h +1 -1
  52. data/ext/nokogiri/xml_text.c +10 -3
  53. data/ext/nokogiri/xml_text.h +1 -1
  54. data/ext/nokogiri/xml_xpath.h +1 -1
  55. data/ext/nokogiri/xml_xpath_context.h +1 -1
  56. data/ext/nokogiri/xslt_stylesheet.c +29 -16
  57. data/ext/nokogiri/xslt_stylesheet.h +1 -1
  58. data/lib/action-nokogiri.rb +7 -1
  59. data/lib/nokogiri.rb +21 -5
  60. data/lib/nokogiri/css/generated_parser.rb +49 -14
  61. data/lib/nokogiri/css/generated_tokenizer.rb +2 -2
  62. data/lib/nokogiri/css/node.rb +13 -3
  63. data/lib/nokogiri/css/parser.rb +8 -0
  64. data/lib/nokogiri/css/parser.y +7 -7
  65. data/lib/nokogiri/css/tokenizer.rb +2 -0
  66. data/lib/nokogiri/css/xpath_visitor.rb +10 -6
  67. data/lib/nokogiri/decorators/hpricot/node.rb +1 -1
  68. data/lib/nokogiri/decorators/hpricot/node_set.rb +2 -2
  69. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +2 -0
  70. data/lib/nokogiri/decorators/slop.rb +3 -1
  71. data/lib/nokogiri/ffi/html/document.rb +37 -0
  72. data/lib/nokogiri/ffi/html/element_description.rb +85 -0
  73. data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
  74. data/lib/nokogiri/ffi/html/sax/parser.rb +21 -0
  75. data/lib/nokogiri/ffi/io_callbacks.rb +32 -0
  76. data/lib/nokogiri/ffi/libxml.rb +314 -0
  77. data/lib/nokogiri/ffi/structs/common_node.rb +26 -0
  78. data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
  79. data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
  80. data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
  81. data/lib/nokogiri/ffi/structs/xml_attr.rb +19 -0
  82. data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
  83. data/lib/nokogiri/ffi/structs/xml_document.rb +108 -0
  84. data/lib/nokogiri/ffi/structs/xml_dtd.rb +26 -0
  85. data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
  86. data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
  87. data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
  88. data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
  89. data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
  90. data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
  91. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +14 -0
  92. data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
  93. data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
  94. data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
  95. data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +37 -0
  96. data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
  97. data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
  98. data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
  99. data/lib/nokogiri/ffi/xml/attr.rb +41 -0
  100. data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
  101. data/lib/nokogiri/ffi/xml/comment.rb +18 -0
  102. data/lib/nokogiri/ffi/xml/document.rb +107 -0
  103. data/lib/nokogiri/ffi/xml/document_fragment.rb +26 -0
  104. data/lib/nokogiri/ffi/xml/dtd.rb +42 -0
  105. data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
  106. data/lib/nokogiri/ffi/xml/namespace.rb +38 -0
  107. data/lib/nokogiri/ffi/xml/node.rb +380 -0
  108. data/lib/nokogiri/ffi/xml/node_set.rb +130 -0
  109. data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
  110. data/lib/nokogiri/ffi/xml/reader.rb +217 -0
  111. data/lib/nokogiri/ffi/xml/relax_ng.rb +51 -0
  112. data/lib/nokogiri/ffi/xml/sax/parser.rb +148 -0
  113. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +38 -0
  114. data/lib/nokogiri/ffi/xml/schema.rb +55 -0
  115. data/lib/nokogiri/ffi/xml/syntax_error.rb +76 -0
  116. data/lib/nokogiri/ffi/xml/text.rb +18 -0
  117. data/lib/nokogiri/ffi/xml/xpath.rb +19 -0
  118. data/lib/nokogiri/ffi/xml/xpath_context.rb +135 -0
  119. data/lib/nokogiri/ffi/xslt/stylesheet.rb +47 -0
  120. data/lib/nokogiri/hpricot.rb +14 -3
  121. data/lib/nokogiri/html.rb +11 -46
  122. data/lib/nokogiri/html/builder.rb +27 -1
  123. data/lib/nokogiri/html/document.rb +62 -6
  124. data/lib/nokogiri/html/document_fragment.rb +15 -0
  125. data/lib/nokogiri/html/element_description.rb +23 -0
  126. data/lib/nokogiri/html/entity_lookup.rb +2 -0
  127. data/lib/nokogiri/html/sax/parser.rb +27 -1
  128. data/lib/nokogiri/version.rb +26 -1
  129. data/lib/nokogiri/version_warning.rb +11 -0
  130. data/lib/nokogiri/xml.rb +25 -51
  131. data/lib/nokogiri/xml/builder.rb +166 -10
  132. data/lib/nokogiri/xml/cdata.rb +3 -1
  133. data/lib/nokogiri/xml/document.rb +39 -6
  134. data/lib/nokogiri/xml/document_fragment.rb +41 -1
  135. data/lib/nokogiri/xml/dtd.rb +3 -1
  136. data/lib/nokogiri/xml/entity_declaration.rb +3 -1
  137. data/lib/nokogiri/xml/fragment_handler.rb +24 -3
  138. data/lib/nokogiri/xml/namespace.rb +7 -0
  139. data/lib/nokogiri/xml/node.rb +314 -65
  140. data/lib/nokogiri/xml/node/save_options.rb +12 -2
  141. data/lib/nokogiri/xml/node_set.rb +58 -8
  142. data/lib/nokogiri/xml/parse_options.rb +80 -0
  143. data/lib/nokogiri/xml/processing_instruction.rb +2 -0
  144. data/lib/nokogiri/xml/reader.rb +42 -3
  145. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  146. data/lib/nokogiri/xml/sax.rb +0 -7
  147. data/lib/nokogiri/xml/sax/document.rb +84 -0
  148. data/lib/nokogiri/xml/sax/parser.rb +38 -2
  149. data/lib/nokogiri/xml/sax/push_parser.rb +12 -0
  150. data/lib/nokogiri/xml/schema.rb +65 -0
  151. data/lib/nokogiri/xml/syntax_error.rb +11 -0
  152. data/lib/nokogiri/xml/xpath.rb +1 -1
  153. data/lib/nokogiri/xml/xpath_context.rb +2 -0
  154. data/lib/nokogiri/xslt.rb +21 -1
  155. data/lib/nokogiri/xslt/stylesheet.rb +19 -0
  156. data/lib/xsd/xmlparser/nokogiri.rb +12 -2
  157. data/tasks/test.rb +42 -19
  158. data/test/css/test_parser.rb +29 -0
  159. data/test/ffi/test_document.rb +35 -0
  160. data/test/files/address_book.rlx +12 -0
  161. data/test/files/address_book.xml +10 -0
  162. data/test/files/po.xml +32 -0
  163. data/test/files/po.xsd +66 -0
  164. data/test/helper.rb +38 -8
  165. data/test/html/sax/test_parser.rb +12 -0
  166. data/test/html/test_builder.rb +25 -2
  167. data/test/html/test_document.rb +91 -20
  168. data/test/html/test_document_fragment.rb +97 -0
  169. data/test/html/test_element_description.rb +95 -0
  170. data/test/html/test_node.rb +66 -3
  171. data/test/test_convert_xpath.rb +1 -1
  172. data/test/test_memory_leak.rb +57 -18
  173. data/test/test_nokogiri.rb +24 -2
  174. data/test/test_reader.rb +77 -0
  175. data/test/test_xslt_transforms.rb +120 -82
  176. data/test/xml/node/test_subclass.rb +44 -0
  177. data/test/xml/sax/test_parser.rb +9 -0
  178. data/test/xml/sax/test_push_parser.rb +24 -0
  179. data/test/xml/test_attr.rb +7 -0
  180. data/test/xml/test_builder.rb +48 -0
  181. data/test/xml/test_cdata.rb +19 -0
  182. data/test/xml/test_comment.rb +6 -0
  183. data/test/xml/test_document.rb +101 -2
  184. data/test/xml/test_document_fragment.rb +55 -3
  185. data/test/xml/test_entity_reference.rb +4 -0
  186. data/test/xml/test_namespace.rb +43 -0
  187. data/test/xml/test_node.rb +255 -8
  188. data/test/xml/test_node_attributes.rb +34 -0
  189. data/test/xml/test_node_encoding.rb +9 -2
  190. data/test/xml/test_node_set.rb +197 -1
  191. data/test/xml/test_parse_options.rb +52 -0
  192. data/test/xml/test_processing_instruction.rb +5 -0
  193. data/test/xml/test_relax_ng.rb +60 -0
  194. data/test/xml/test_schema.rb +65 -0
  195. data/test/xml/test_text.rb +5 -0
  196. data/test/xml/test_unparented_node.rb +3 -3
  197. metadata +129 -13
  198. data/lib/nokogiri/xml/comment.rb +0 -6
  199. data/lib/nokogiri/xml/element.rb +0 -6
  200. data/lib/nokogiri/xml/text.rb +0 -6
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestNodeAttributes < Nokogiri::TestCase
6
+ def test_attribute_with_ns
7
+ doc = Nokogiri::XML <<-eoxml
8
+ <root xmlns:tlm='http://tenderlovemaking.com/'>
9
+ <node tlm:foo='bar' foo='baz' />
10
+ </root>
11
+ eoxml
12
+
13
+ node = doc.at('node')
14
+
15
+ assert_equal 'bar',
16
+ node.attribute_with_ns('foo', 'http://tenderlovemaking.com/').value
17
+ end
18
+
19
+ def test_namespace_key?
20
+ doc = Nokogiri::XML <<-eoxml
21
+ <root xmlns:tlm='http://tenderlovemaking.com/'>
22
+ <node tlm:foo='bar' foo='baz' />
23
+ </root>
24
+ eoxml
25
+
26
+ node = doc.at('node')
27
+
28
+ assert node.namespaced_key?('foo', 'http://tenderlovemaking.com/')
29
+ assert node.namespaced_key?('foo', nil)
30
+ assert !node.namespaced_key?('foo', 'foo')
31
+ end
32
+ end
33
+ end
34
+ end
@@ -49,7 +49,8 @@ module Nokogiri
49
49
  assert_equal 'UTF-8', doc.encoding
50
50
  n = doc.xpath('//part:tire', { 'part' => 'http://schwinn.com/' }).first
51
51
  assert n
52
- assert_equal doc.encoding, n.namespace.encoding.name
52
+ assert_equal doc.encoding, n.namespace.href.encoding.name
53
+ assert_equal doc.encoding, n.namespace.prefix.encoding.name
53
54
  end
54
55
 
55
56
  def test_namespace_as_hash
@@ -66,9 +67,15 @@ module Nokogiri
66
67
  doc = Nokogiri::XML(xml, nil, 'UTF-8')
67
68
  assert_equal 'UTF-8', doc.encoding
68
69
  assert n = doc.xpath('//car').first
70
+
71
+ n.namespace_definitions.each do |nd|
72
+ assert_equal doc.encoding, nd.href.encoding.name
73
+ assert_equal doc.encoding, nd.prefix.encoding.name
74
+ end
75
+
69
76
  n.namespaces.each do |k,v|
70
- assert_equal doc.encoding, v.encoding.name
71
77
  assert_equal doc.encoding, k.encoding.name
78
+ assert_equal doc.encoding, v.encoding.name
72
79
  end
73
80
  end
74
81
  end
@@ -5,7 +5,63 @@ module Nokogiri
5
5
  class TestNodeSet < Nokogiri::TestCase
6
6
  def setup
7
7
  super
8
- @xml = Nokogiri::XML.parse(File.read(XML_FILE), XML_FILE)
8
+ @xml = Nokogiri::XML(File.read(XML_FILE), XML_FILE)
9
+ end
10
+
11
+ def test_double_equal
12
+ assert node_set_one = @xml.xpath('//employee')
13
+ assert node_set_two = @xml.xpath('//employee')
14
+
15
+ assert_not_equal node_set_one.object_id, node_set_two.object_id
16
+
17
+ assert_equal node_set_one, node_set_two
18
+ end
19
+
20
+ def test_node_set_not_equal_to_string
21
+ node_set_one = @xml.xpath('//employee')
22
+ assert_not_equal node_set_one, "asdfadsf"
23
+ end
24
+
25
+ def test_out_of_order_not_equal
26
+ one = @xml.xpath('//employee')
27
+ two = @xml.xpath('//employee')
28
+ two.push two.shift
29
+ assert_not_equal one, two
30
+ end
31
+
32
+ def test_shorter_is_not_equal
33
+ node_set_one = @xml.xpath('//employee')
34
+ node_set_two = @xml.xpath('//employee')
35
+ node_set_two.delete(node_set_two.first)
36
+
37
+ assert_not_equal node_set_one, node_set_two
38
+ end
39
+
40
+ def test_pop
41
+ set = @xml.xpath('//employee')
42
+ last = set.last
43
+ assert_equal last, set.pop
44
+ end
45
+
46
+ def test_shift
47
+ set = @xml.xpath('//employee')
48
+ first = set.first
49
+ assert_equal first, set.shift
50
+ end
51
+
52
+ def test_shift_empty
53
+ set = Nokogiri::XML::NodeSet.new(@xml)
54
+ assert_nil set.shift
55
+ end
56
+
57
+ def test_pop_empty
58
+ set = Nokogiri::XML::NodeSet.new(@xml)
59
+ assert_nil set.pop
60
+ end
61
+
62
+ def test_first_takes_arguments
63
+ assert node_set = @xml.xpath('//employee')
64
+ assert_equal 2, node_set.first(2).length
9
65
  end
10
66
 
11
67
  def test_dup
@@ -36,6 +92,12 @@ module Nokogiri
36
92
  assert set.at('bar')
37
93
  end
38
94
 
95
+ def test_children_has_document
96
+ set = @xml.root.children
97
+ assert_instance_of(NodeSet, set)
98
+ assert_equal @xml, set.document
99
+ end
100
+
39
101
  def test_length_size
40
102
  assert node_set = @xml.search('//employee')
41
103
  assert_equal node_set.length, node_set.size
@@ -67,6 +129,11 @@ module Nokogiri
67
129
  assert node_set = @xml.search('//employee')
68
130
  assert_equal node_set.first, node_set.at(0)
69
131
  end
132
+
133
+ def test_percent
134
+ assert node_set = @xml.search('//employee')
135
+ assert_equal node_set.first, node_set % 0
136
+ end
70
137
 
71
138
  def test_to_ary
72
139
  assert node_set = @xml.search('//employee')
@@ -85,6 +152,36 @@ module Nokogiri
85
152
  assert node_set.include?(node)
86
153
  end
87
154
 
155
+ def test_delete_with_invalid_argument
156
+ employees = @xml.search("//employee")
157
+ positions = @xml.search("//position")
158
+
159
+ assert_raises(ArgumentError) { employees.delete(positions) }
160
+ end
161
+
162
+ def test_delete_when_present
163
+ employees = @xml.search("//employee")
164
+ wally = employees.first
165
+ assert employees.include?(wally) # testing setup
166
+ length = employees.length
167
+
168
+ result = employees.delete(wally)
169
+ assert_equal result, wally
170
+ assert ! employees.include?(wally)
171
+ assert length-1, employees.length
172
+ end
173
+
174
+ def test_delete_when_not_present
175
+ employees = @xml.search("//employee")
176
+ phb = @xml.search("//position").first
177
+ assert ! employees.include?(phb) # testing setup
178
+ length = employees.length
179
+
180
+ result = employees.delete(phb)
181
+ assert_nil result
182
+ assert length, employees.length
183
+ end
184
+
88
185
  def test_unlink
89
186
  xml = Nokogiri::XML.parse(<<-eoxml)
90
187
  <root>
@@ -167,6 +264,105 @@ module Nokogiri
167
264
  assert_equal 'wrapper', employees[0].parent.name
168
265
  assert_equal 'employee', @xml.search("//wrapper").first.children[0].name
169
266
  end
267
+
268
+ def test_plus_operator
269
+ names = @xml.search("name")
270
+ positions = @xml.search("position")
271
+
272
+ names_len = names.length
273
+ positions_len = positions.length
274
+
275
+ assert_raises(ArgumentError) { result = names + positions.first }
276
+
277
+ result = names + positions
278
+ assert_equal names_len, names.length
279
+ assert_equal positions_len, positions.length
280
+ assert_equal names.length + positions.length, result.length
281
+
282
+ names += positions
283
+ assert_equal result.length, names.length
284
+ end
285
+
286
+ def test_minus_operator
287
+ employees = @xml.search("//employee")
288
+ females = @xml.search("//employee[gender[text()='Female']]")
289
+
290
+ employees_len = employees.length
291
+ females_len = females.length
292
+
293
+ assert_raises(ArgumentError) { result = employees - females.first }
294
+
295
+ result = employees - females
296
+ assert_equal employees_len, employees.length
297
+ assert_equal females_len, females.length
298
+ assert_equal employees.length - females.length, result.length
299
+
300
+ employees -= females
301
+ assert_equal result.length, employees.length
302
+ end
303
+
304
+ def test_array_index
305
+ employees = @xml.search("//employee")
306
+ other = @xml.search("//position").first
307
+
308
+ assert_equal 3, employees.index(employees[3])
309
+ assert_nil employees.index(other)
310
+ end
311
+
312
+ def test_array_slice_with_start_and_end
313
+ employees = @xml.search("//employee")
314
+ assert_equal [employees[1], employees[2], employees[3]], employees[1,3].to_a
315
+ end
316
+
317
+ def test_array_index_bracket_equivalence
318
+ employees = @xml.search("//employee")
319
+ assert_equal [employees[1], employees[2], employees[3]], employees[1,3].to_a
320
+ assert_equal [employees[1], employees[2], employees[3]], employees.slice(1,3).to_a
321
+ end
322
+
323
+ def test_array_slice_with_negative_start
324
+ employees = @xml.search("//employee")
325
+ assert_equal [employees[2]], employees[-3,1].to_a
326
+ assert_equal [employees[2], employees[3]], employees[-3,2].to_a
327
+ end
328
+
329
+ def test_array_slice_with_invalid_args
330
+ employees = @xml.search("//employee")
331
+ assert_nil employees[99, 1] # large start
332
+ assert_nil employees[1, -1] # negative len
333
+ assert_equal [], employees[1, 0].to_a # zero len
334
+ end
335
+
336
+ def test_array_slice_with_range
337
+ employees = @xml.search("//employee")
338
+ assert_equal [employees[1], employees[2], employees[3]], employees[1..3].to_a
339
+ assert_equal [employees[0], employees[1], employees[2], employees[3]], employees[0..3].to_a
340
+ end
341
+
342
+ def test_intersection_with_no_overlap
343
+ employees = @xml.search("//employee")
344
+ positions = @xml.search("//position")
345
+
346
+ assert_equal [], (employees & positions).to_a
347
+ end
348
+
349
+ def test_intersection
350
+ employees = @xml.search("//employee")
351
+ first_set = employees[0..2]
352
+ second_set = employees[2..4]
353
+
354
+ assert_equal [employees[2]], (first_set & second_set).to_a
355
+ end
356
+
357
+ def test_include?
358
+ employees = @xml.search("//employee")
359
+ yes = employees.first
360
+ no = @xml.search("//position").first
361
+
362
+ assert employees.include?(yes)
363
+ assert ! employees.include?(no)
364
+ end
365
+
170
366
  end
171
367
  end
172
368
  end
@@ -0,0 +1,52 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestParseOptions < Nokogiri::TestCase
6
+ def test_new
7
+ options = Nokogiri::XML::ParseOptions.new
8
+ assert_equal 0, options.options
9
+ end
10
+
11
+ def test_to_i
12
+ options = Nokogiri::XML::ParseOptions.new
13
+ assert_equal 0, options.to_i
14
+ end
15
+
16
+ ParseOptions.constants.each do |constant|
17
+ next if constant == 'STRICT'
18
+ class_eval %{
19
+ def test_predicate_#{constant.downcase}
20
+ options = ParseOptions.new(ParseOptions::#{constant})
21
+ assert options.#{constant.downcase}?
22
+
23
+ assert ParseOptions.new.#{constant.downcase}.#{constant.downcase}?
24
+ end
25
+ }
26
+ end
27
+
28
+ def test_strict_noent
29
+ options = ParseOptions.new.recover.noent
30
+ assert !options.strict?
31
+ end
32
+
33
+ def test_new_with_argument
34
+ options = Nokogiri::XML::ParseOptions.new 1 << 1
35
+ assert_equal 1 << 1, options.options
36
+ end
37
+
38
+ def test_chaining
39
+ options = Nokogiri::XML::ParseOptions.new.recover.noent
40
+ assert options.recover?
41
+ assert options.noent?
42
+ end
43
+
44
+ def test_inspect
45
+ options = Nokogiri::XML::ParseOptions.new.recover.noent
46
+ ins = options.inspect
47
+ assert_match(/recover/, ins)
48
+ assert_match(/noent/, ins)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -20,6 +20,11 @@ module Nokogiri
20
20
  assert ref = ProcessingInstruction.new(@xml, 'name', 'content')
21
21
  assert_instance_of ProcessingInstruction, ref
22
22
  end
23
+
24
+ def test_many_new
25
+ 100.times { ProcessingInstruction.new(@xml, 'foo', 'bar') }
26
+ @xml.root << ProcessingInstruction.new(@xml, 'foo', 'bar')
27
+ end
23
28
  end
24
29
  end
25
30
  end
@@ -0,0 +1,60 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestRelaxNG < Nokogiri::TestCase
6
+ def setup
7
+ assert @schema = Nokogiri::XML::RelaxNG(File.read(ADDRESS_SCHEMA_FILE))
8
+ end
9
+
10
+ def test_parse_with_memory
11
+ assert_instance_of Nokogiri::XML::RelaxNG, @schema
12
+ assert_equal 0, @schema.errors.length
13
+ end
14
+
15
+ def test_new
16
+ assert schema = Nokogiri::XML::RelaxNG.new(
17
+ File.read(ADDRESS_SCHEMA_FILE))
18
+ assert_instance_of Nokogiri::XML::RelaxNG, schema
19
+ end
20
+
21
+ def test_parse_with_io
22
+ xsd = nil
23
+ File.open(ADDRESS_SCHEMA_FILE, 'rb') { |f|
24
+ assert xsd = Nokogiri::XML::RelaxNG(f)
25
+ }
26
+ assert_equal 0, xsd.errors.length
27
+ end
28
+
29
+ def test_parse_with_errors
30
+ xml = File.read(ADDRESS_SCHEMA_FILE).sub(/name="/, 'name=')
31
+ assert_raises(Nokogiri::XML::SyntaxError) {
32
+ Nokogiri::XML::RelaxNG(xml)
33
+ }
34
+ end
35
+
36
+ def test_validate_document
37
+ doc = Nokogiri::XML(File.read(ADDRESS_XML_FILE))
38
+ assert errors = @schema.validate(doc)
39
+ assert_equal 0, errors.length
40
+ end
41
+
42
+ def test_validate_invalid_document
43
+ # Empty address book is not allowed
44
+ read_doc = '<addressBook></addressBook>'
45
+
46
+ assert errors = @schema.validate(Nokogiri::XML(read_doc))
47
+ assert_equal 1, errors.length
48
+ end
49
+
50
+ def test_valid?
51
+ valid_doc = Nokogiri::XML(File.read(ADDRESS_XML_FILE))
52
+
53
+ invalid_doc = Nokogiri::XML('<addressBook></addressBook>')
54
+
55
+ assert(@schema.valid?(valid_doc))
56
+ assert(!@schema.valid?(invalid_doc))
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,65 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', "helper"))
2
+
3
+ module Nokogiri
4
+ module XML
5
+ class TestSchema < Nokogiri::TestCase
6
+ def setup
7
+ assert @xsd = Nokogiri::XML::Schema(File.read(PO_SCHEMA_FILE))
8
+ end
9
+
10
+ def test_parse_with_memory
11
+ assert_instance_of Nokogiri::XML::Schema, @xsd
12
+ assert_equal 0, @xsd.errors.length
13
+ end
14
+
15
+ def test_new
16
+ assert xsd = Nokogiri::XML::Schema.new(File.read(PO_SCHEMA_FILE))
17
+ assert_instance_of Nokogiri::XML::Schema, xsd
18
+ end
19
+
20
+ def test_parse_with_io
21
+ xsd = nil
22
+ File.open(PO_SCHEMA_FILE, 'rb') { |f|
23
+ assert xsd = Nokogiri::XML::Schema(f)
24
+ }
25
+ assert_equal 0, xsd.errors.length
26
+ end
27
+
28
+ def test_parse_with_errors
29
+ xml = File.read(PO_SCHEMA_FILE).sub(/name="/, 'name=')
30
+ assert_raises(Nokogiri::XML::SyntaxError) {
31
+ Nokogiri::XML::Schema(xml)
32
+ }
33
+ end
34
+
35
+ def test_validate_document
36
+ doc = Nokogiri::XML(File.read(PO_XML_FILE))
37
+ assert errors = @xsd.validate(doc)
38
+ assert_equal 0, errors.length
39
+ end
40
+
41
+ def test_validate_file
42
+ assert errors = @xsd.validate(PO_XML_FILE)
43
+ assert_equal 0, errors.length
44
+ end
45
+
46
+ def test_validate_invalid_document
47
+ read_doc = File.read(PO_XML_FILE).gsub(/<city>[^<]*<\/city>/, '')
48
+
49
+ assert errors = @xsd.validate(Nokogiri::XML(read_doc))
50
+ assert_equal 2, errors.length
51
+ end
52
+
53
+ def test_valid?
54
+ valid_doc = Nokogiri::XML(File.read(PO_XML_FILE))
55
+
56
+ invalid_doc = Nokogiri::XML(
57
+ File.read(PO_XML_FILE).gsub(/<city>[^<]*<\/city>/, '')
58
+ )
59
+
60
+ assert(@xsd.valid?(valid_doc))
61
+ assert(!@xsd.valid?(invalid_doc))
62
+ end
63
+ end
64
+ end
65
+ end