nokogiri 1.2.3 → 1.3.0

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 +206 -19
  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 +128 -12
  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,35 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "helper"))
2
+
3
+ if defined?(Nokogiri::LibXML)
4
+
5
+ class FFI::TestDocument < Nokogiri::TestCase
6
+
7
+ def test_ruby_doc_reflection
8
+ doc = Nokogiri::XML("<root><foo>foo</foo></root>")
9
+ assert_equal doc, doc.cstruct.ruby_doc
10
+ end
11
+
12
+ def test_ruby_doc_setter
13
+ doc = Nokogiri::XML("<root><foo>foo</foo></root>")
14
+ foo = "foobar"
15
+ doc.cstruct.ruby_doc = foo
16
+ assert_equal foo, doc.cstruct.ruby_doc
17
+ end
18
+
19
+ def test_node_set
20
+ doc = Nokogiri::XML("<root><foo>foo</foo></root>")
21
+ assert_instance_of Nokogiri::LibXML::XmlNodeSetCast, doc.cstruct.node_set
22
+ end
23
+
24
+ def test_node_set_contains_unlinked_nodes
25
+ doc = Nokogiri::XML("<root><foo>foo</foo></root>")
26
+ node = doc.xpath('//foo').first
27
+ assert_equal 0, doc.cstruct.node_set[:nodeNr]
28
+ node.unlink
29
+ assert_equal 1, doc.cstruct.node_set[:nodeNr]
30
+ assert_equal node.cstruct.pointer, doc.cstruct.node_set[:nodeTab].get_pointer(0)
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,12 @@
1
+ <element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
2
+ <oneOrMore>
3
+ <element name="card">
4
+ <element name="name">
5
+ <text/>
6
+ </element>
7
+ <element name="email">
8
+ <text/>
9
+ </element>
10
+ </element>
11
+ </oneOrMore>
12
+ </element>
@@ -0,0 +1,10 @@
1
+ <addressBook>
2
+ <card>
3
+ <name>John Smith</name>
4
+ <email>js@example.com</email>
5
+ </card>
6
+ <card>
7
+ <name>Fred Bloggs</name>
8
+ <email>fb@example.net</email>
9
+ </card>
10
+ </addressBook>
@@ -0,0 +1,32 @@
1
+ <?xml version="1.0"?>
2
+ <purchaseOrder orderDate="1999-10-20">
3
+ <shipTo country="US">
4
+ <name>Alice Smith</name>
5
+ <street>123 Maple Street</street>
6
+ <city>Mill Valley</city>
7
+ <state>CA</state>
8
+ <zip>90952</zip>
9
+ </shipTo>
10
+ <billTo country="US">
11
+ <name>Robert Smith</name>
12
+ <street>8 Oak Avenue</street>
13
+ <city>Old Town</city>
14
+ <state>PA</state>
15
+ <zip>95819</zip>
16
+ </billTo>
17
+ <comment>Hurry, my lawn is going wild!</comment>
18
+ <items>
19
+ <item partNum="872-AA">
20
+ <productName>Lawnmower</productName>
21
+ <quantity>1</quantity>
22
+ <USPrice>148.95</USPrice>
23
+ <comment>Confirm this is electric</comment>
24
+ </item>
25
+ <item partNum="926-AA">
26
+ <productName>Baby Monitor</productName>
27
+ <quantity>1</quantity>
28
+ <USPrice>39.98</USPrice>
29
+ <shipDate>1999-05-21</shipDate>
30
+ </item>
31
+ </items>
32
+ </purchaseOrder>
@@ -0,0 +1,66 @@
1
+ <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
2
+
3
+ <xsd:annotation>
4
+ <xsd:documentation xml:lang="en">
5
+ Purchase order schema for Example.com.
6
+ Copyright 2000 Example.com. All rights reserved.
7
+ </xsd:documentation>
8
+ </xsd:annotation>
9
+
10
+ <xsd:element name="purchaseOrder" type="PurchaseOrderType"/>
11
+
12
+ <xsd:element name="comment" type="xsd:string"/>
13
+
14
+ <xsd:complexType name="PurchaseOrderType">
15
+ <xsd:sequence>
16
+ <xsd:element name="shipTo" type="USAddress"/>
17
+ <xsd:element name="billTo" type="USAddress"/>
18
+ <xsd:element ref="comment" minOccurs="0"/>
19
+ <xsd:element name="items" type="Items"/>
20
+ </xsd:sequence>
21
+ <xsd:attribute name="orderDate" type="xsd:date"/>
22
+ </xsd:complexType>
23
+
24
+ <xsd:complexType name="USAddress">
25
+ <xsd:sequence>
26
+ <xsd:element name="name" type="xsd:string"/>
27
+ <xsd:element name="street" type="xsd:string"/>
28
+ <xsd:element name="city" type="xsd:string"/>
29
+ <xsd:element name="state" type="xsd:string"/>
30
+ <xsd:element name="zip" type="xsd:decimal"/>
31
+ </xsd:sequence>
32
+ <xsd:attribute name="country" type="xsd:NMTOKEN"
33
+ fixed="US"/>
34
+ </xsd:complexType>
35
+
36
+ <xsd:complexType name="Items">
37
+ <xsd:sequence>
38
+ <xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
39
+ <xsd:complexType>
40
+ <xsd:sequence>
41
+ <xsd:element name="productName" type="xsd:string"/>
42
+ <xsd:element name="quantity">
43
+ <xsd:simpleType>
44
+ <xsd:restriction base="xsd:positiveInteger">
45
+ <xsd:maxExclusive value="100"/>
46
+ </xsd:restriction>
47
+ </xsd:simpleType>
48
+ </xsd:element>
49
+ <xsd:element name="USPrice" type="xsd:decimal"/>
50
+ <xsd:element ref="comment" minOccurs="0"/>
51
+ <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
52
+ </xsd:sequence>
53
+ <xsd:attribute name="partNum" type="SKU" use="required"/>
54
+ </xsd:complexType>
55
+ </xsd:element>
56
+ </xsd:sequence>
57
+ </xsd:complexType>
58
+
59
+ <!-- Stock Keeping Unit, a code for identifying products -->
60
+ <xsd:simpleType name="SKU">
61
+ <xsd:restriction base="xsd:string">
62
+ <xsd:pattern value="\d{3}-[A-Z]{2}"/>
63
+ </xsd:restriction>
64
+ </xsd:simpleType>
65
+
66
+ </xsd:schema>
@@ -1,4 +1,6 @@
1
+ Process.setrlimit(Process::RLIMIT_CORE, Process::RLIM_INFINITY) unless RUBY_PLATFORM =~ /(java|mswin|mingw)/i
1
2
  $VERBOSE = true
3
+ require 'rubygems'
2
4
  require 'test/unit'
3
5
 
4
6
  %w(../lib ../ext).each do |path|
@@ -7,14 +9,20 @@ end
7
9
 
8
10
  require 'nokogiri'
9
11
 
12
+ warn "#{__FILE__}:#{__LINE__}: libxml version info: #{Nokogiri::VERSION_INFO.inspect}"
13
+
10
14
  module Nokogiri
11
15
  class TestCase < Test::Unit::TestCase
12
- ASSETS_DIR = File.join(File.dirname(__FILE__), 'files')
13
- XML_FILE = File.join(ASSETS_DIR, 'staff.xml')
14
- XSLT_FILE = File.join(ASSETS_DIR, 'staff.xslt')
15
- EXSLT_FILE = File.join(ASSETS_DIR, 'exslt.xslt')
16
- EXML_FILE = File.join(ASSETS_DIR, 'exslt.xml')
17
- HTML_FILE = File.join(ASSETS_DIR, 'tlm.html')
16
+ ASSETS_DIR = File.join(File.dirname(__FILE__), 'files')
17
+ XML_FILE = File.join(ASSETS_DIR, 'staff.xml')
18
+ XSLT_FILE = File.join(ASSETS_DIR, 'staff.xslt')
19
+ EXSLT_FILE = File.join(ASSETS_DIR, 'exslt.xslt')
20
+ EXML_FILE = File.join(ASSETS_DIR, 'exslt.xml')
21
+ HTML_FILE = File.join(ASSETS_DIR, 'tlm.html')
22
+ PO_XML_FILE = File.join(ASSETS_DIR, 'po.xml')
23
+ PO_SCHEMA_FILE = File.join(ASSETS_DIR, 'po.xsd')
24
+ ADDRESS_SCHEMA_FILE = File.join(ASSETS_DIR, 'address_book.rlx')
25
+ ADDRESS_XML_FILE = File.join(ASSETS_DIR, 'address_book.xml')
18
26
 
19
27
  unless RUBY_VERSION >= '1.9'
20
28
  undef :default_test
@@ -30,13 +38,25 @@ module Nokogiri
30
38
  GC.start
31
39
  end
32
40
  end
41
+
42
+ def assert_indent amount, doc, message = nil
43
+ nodes = []
44
+ doc.traverse do |node|
45
+ nodes << node if node.text? && node.blank?
46
+ end
47
+ assert nodes.length > 0
48
+ nodes.each do |node|
49
+ len = node.content.gsub(/[\r\n]/, '').length
50
+ assert_equal(0, len % amount, message)
51
+ end
52
+ end
33
53
  end
34
54
 
35
55
  module SAX
36
56
  class TestCase < Nokogiri::TestCase
37
57
  class Doc < XML::SAX::Document
38
- attr_reader :start_elements, :start_document_called
39
- attr_reader :end_elements, :end_document_called
58
+ attr_reader :start_elements, :start_elements_ns, :start_document_called
59
+ attr_reader :end_elements, :end_elements_ns, :end_document_called
40
60
  attr_reader :data, :comments, :cdata_blocks
41
61
  attr_reader :errors, :warnings
42
62
 
@@ -65,11 +85,21 @@ module Nokogiri
65
85
  super
66
86
  end
67
87
 
88
+ def start_element_ns *args
89
+ (@start_elements_ns ||= []) << args
90
+ super
91
+ end
92
+
68
93
  def end_element *args
69
94
  (@end_elements ||= []) << args
70
95
  super
71
96
  end
72
97
 
98
+ def end_element_ns *args
99
+ (@end_elements_ns ||= []) << args
100
+ super
101
+ end
102
+
73
103
  def characters string
74
104
  @data ||= []
75
105
  @data += [string]
@@ -14,6 +14,12 @@ module Nokogiri
14
14
  assert_equal 1110, @parser.document.end_elements.length
15
15
  end
16
16
 
17
+ def test_parse_file_nil_argument
18
+ assert_raises(ArgumentError) {
19
+ @parser.parse_file(nil)
20
+ }
21
+ end
22
+
17
23
  def test_parse_file_non_existant
18
24
  assert_raise Errno::ENOENT do
19
25
  @parser.parse_file('foo')
@@ -26,6 +32,12 @@ module Nokogiri
26
32
  end
27
33
  end
28
34
 
35
+ def test_parse_memory_nil
36
+ assert_raise ArgumentError do
37
+ @parser.parse_memory(nil)
38
+ end
39
+ end
40
+
29
41
  def test_parse_document
30
42
  @parser.parse_memory(<<-eoxml)
31
43
  <p>Paragraph 1</p>
@@ -16,7 +16,7 @@ module Nokogiri
16
16
  end
17
17
 
18
18
  def test_hash_as_attributes_for_attribute_method
19
- html = Nokogiri::HTML::Builder.new {
19
+ html = Nokogiri::HTML::Builder.new { ||
20
20
  div.slide(:class => 'another_class') {
21
21
  span 'Slide 1'
22
22
  }
@@ -36,7 +36,7 @@ module Nokogiri
36
36
 
37
37
  def test_href_with_attributes
38
38
  uri = 'http://tenderlovemaking.com/'
39
- built = Nokogiri::XML::Builder.new { |x|
39
+ built = Nokogiri::XML::Builder.new {
40
40
  div {
41
41
  a('King Khan & The Shrines', :href => uri)
42
42
  }
@@ -128,6 +128,29 @@ module Nokogiri
128
128
  builder = Nokogiri::HTML::Builder.new { text foo }
129
129
  assert builder.to_html.include?("foo!")
130
130
  end
131
+
132
+ def test_builder_with_param
133
+ doc = Nokogiri::HTML::Builder.new { |html|
134
+ html.body {
135
+ html.p "hello world"
136
+ }
137
+ }.doc
138
+
139
+ assert node = doc.xpath('//body/p').first
140
+ assert_equal 'hello world', node.content
141
+ end
142
+
143
+ def test_builder_with_id
144
+ text = "hello world"
145
+ doc = Nokogiri::HTML::Builder.new { |html|
146
+ html.body {
147
+ html.id_ text
148
+ }
149
+ }.doc
150
+
151
+ assert node = doc.xpath('//body/id').first
152
+ assert_equal text, node.content
153
+ end
131
154
  end
132
155
  end
133
156
  end
@@ -8,10 +8,86 @@ module Nokogiri
8
8
  @html = Nokogiri::HTML.parse(File.read(HTML_FILE))
9
9
  end
10
10
 
11
- def test_emtpy_string_returns_empty_doc
11
+ def test_document_takes_config_block
12
+ options = nil
13
+ Nokogiri::HTML(File.read(HTML_FILE), HTML_FILE) do |cfg|
14
+ options = cfg
15
+ options.nonet.nowarning.dtdattr
16
+ end
17
+ assert options.nonet?
18
+ assert options.nowarning?
19
+ assert options.dtdattr?
20
+ end
21
+
22
+ def test_parse_takes_config_block
23
+ options = nil
24
+ Nokogiri::HTML.parse(File.read(HTML_FILE), HTML_FILE) do |cfg|
25
+ options = cfg
26
+ options.nonet.nowarning.dtdattr
27
+ end
28
+ assert options.nonet?
29
+ assert options.nowarning?
30
+ assert options.dtdattr?
31
+ end
32
+
33
+ def test_subclass
34
+ klass = Class.new(Nokogiri::HTML::Document)
35
+ doc = klass.new
36
+ assert_instance_of klass, doc
37
+ end
38
+
39
+ def test_subclass_initialize
40
+ klass = Class.new(Nokogiri::HTML::Document) do
41
+ attr_accessor :initialized_with
42
+
43
+ def initialize(*args)
44
+ @initialized_with = args
45
+ end
46
+ end
47
+ doc = klass.new("uri", "external_id", 1)
48
+ assert_equal ["uri", "external_id", 1], doc.initialized_with
49
+ end
50
+
51
+ def test_subclass_dup
52
+ klass = Class.new(Nokogiri::HTML::Document)
53
+ doc = klass.new.dup
54
+ assert_instance_of klass, doc
55
+ end
56
+
57
+ def test_subclass_parse
58
+ klass = Class.new(Nokogiri::HTML::Document)
59
+ doc = klass.parse(File.read(HTML_FILE))
60
+ assert_equal @html.to_s, doc.to_s
61
+ assert_instance_of klass, doc
62
+ end
63
+
64
+ def test_document_parse_method
65
+ html = Nokogiri::HTML::Document.parse(File.read(HTML_FILE))
66
+ assert_equal @html.to_s, html.to_s
67
+ end
68
+
69
+ def test_empty_string_returns_empty_doc
12
70
  doc = Nokogiri::HTML('')
13
71
  end
14
72
 
73
+ unless %w[2 6] === LIBXML_VERSION.split('.')[0..1]
74
+ # FIXME: this is a hack around broken libxml versions
75
+ def test_to_xhtml_with_indent
76
+ doc = Nokogiri::HTML('<html><body><a>foo</a></body></html>')
77
+ doc = Nokogiri::HTML(doc.to_xhtml(:indent => 2))
78
+ assert_indent 2, doc
79
+ end
80
+
81
+ def test_write_to_xhtml_with_indent
82
+ io = StringIO.new
83
+ doc = Nokogiri::HTML('<html><body><a>foo</a></body></html>')
84
+ doc.write_xhtml_to io, :indent => 5
85
+ io.rewind
86
+ doc = Nokogiri::HTML(io.read)
87
+ assert_indent 5, doc
88
+ end
89
+ end
90
+
15
91
  def test_swap_should_not_exist
16
92
  assert_raises(NoMethodError) {
17
93
  @html.swap
@@ -24,6 +100,15 @@ module Nokogiri
24
100
  }
25
101
  end
26
102
 
103
+ def test_meta_encoding
104
+ assert_equal 'UTF-8', @html.meta_encoding
105
+ end
106
+
107
+ def test_meta_encoding=
108
+ @html.meta_encoding = 'EUC-JP'
109
+ assert_equal 'EUC-JP', @html.meta_encoding
110
+ end
111
+
27
112
  def test_root_node_parent_is_document
28
113
  parent = @html.root.parent
29
114
  assert_equal @html, parent
@@ -44,14 +129,16 @@ module Nokogiri
44
129
 
45
130
  def test_parse_io
46
131
  assert doc = File.open(HTML_FILE, 'rb') { |f|
47
- Document.read_io(f, nil, 'UTF-8', PARSE_NOERROR | PARSE_NOWARNING)
132
+ Document.read_io(f, nil, 'UTF-8',
133
+ XML::ParseOptions::NOERROR | XML::ParseOptions::NOWARNING
134
+ )
48
135
  }
49
136
  end
50
137
 
51
138
  def test_to_xhtml
52
139
  assert_match 'XHTML', @html.to_xhtml
53
- assert_match 'XHTML', @html.to_xhtml('UTF-8')
54
- assert_match 'UTF-8', @html.to_xhtml('UTF-8')
140
+ assert_match 'XHTML', @html.to_xhtml(:encoding => 'UTF-8')
141
+ assert_match 'UTF-8', @html.to_xhtml(:encoding => 'UTF-8')
55
142
  end
56
143
 
57
144
  def test_no_xml_header
@@ -211,22 +298,6 @@ module Nokogiri
211
298
  assert_equal 2, Nokogiri::HTML.fragment("<br/><hr/>").children.length
212
299
  end
213
300
 
214
- def test_fragment
215
- fragment = Nokogiri::HTML.fragment(<<-eohtml)
216
- <div>
217
- <b>Hello World</b>
218
- </div>
219
- eohtml
220
- assert_equal 1, fragment.children.length
221
- assert_equal 'div', fragment.children.first.name
222
- assert_match(/Hello World/, fragment.to_html)
223
-
224
- # libxml2 is broken in 2.6.16 and 2.6.17
225
- unless [16, 17].include?(Nokogiri::LIBXML_VERSION.split('.').last.to_i)
226
- assert_equal 1, fragment.css('div').length
227
- end
228
- end
229
-
230
301
  def test_relative_css_finder
231
302
  doc = Nokogiri::HTML(<<-eohtml)
232
303
  <html>