nokogiri 1.4.7 → 1.5.0.beta.1

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 (164) hide show
  1. data/CHANGELOG.ja.rdoc +8 -83
  2. data/CHANGELOG.rdoc +6 -80
  3. data/Manifest.txt +4 -74
  4. data/README.ja.rdoc +5 -1
  5. data/README.rdoc +8 -22
  6. data/Rakefile +79 -60
  7. data/bin/nokogiri +1 -6
  8. data/deps.rip +5 -0
  9. data/ext/nokogiri/extconf.rb +32 -53
  10. data/ext/nokogiri/nokogiri.c +0 -2
  11. data/ext/nokogiri/nokogiri.h +0 -9
  12. data/ext/nokogiri/xml_document.c +0 -14
  13. data/ext/nokogiri/xml_dtd.c +2 -2
  14. data/ext/nokogiri/xml_io.c +7 -32
  15. data/ext/nokogiri/xml_node.c +31 -103
  16. data/ext/nokogiri/xml_node_set.c +8 -8
  17. data/ext/nokogiri/xml_reader.c +1 -20
  18. data/ext/nokogiri/xml_sax_parser.c +3 -5
  19. data/ext/nokogiri/xml_sax_parser_context.c +0 -40
  20. data/ext/nokogiri/xml_xpath_context.c +2 -35
  21. data/ext/nokogiri/xslt_stylesheet.c +6 -124
  22. data/lib/nokogiri.rb +7 -3
  23. data/lib/nokogiri/css.rb +3 -6
  24. data/lib/nokogiri/css/generated_parser.rb +669 -0
  25. data/lib/nokogiri/css/generated_tokenizer.rb +145 -0
  26. data/lib/nokogiri/css/parser.rb +70 -665
  27. data/lib/nokogiri/css/parser.y +1 -6
  28. data/lib/nokogiri/css/tokenizer.rb +3 -148
  29. data/lib/nokogiri/css/tokenizer.rex +1 -1
  30. data/lib/nokogiri/css/xpath_visitor.rb +14 -16
  31. data/lib/nokogiri/decorators/slop.rb +3 -5
  32. data/lib/nokogiri/html.rb +3 -2
  33. data/lib/nokogiri/html/document.rb +18 -134
  34. data/lib/nokogiri/html/document_fragment.rb +21 -26
  35. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  36. data/lib/nokogiri/html/sax/parser.rb +2 -6
  37. data/lib/nokogiri/version.rb +4 -9
  38. data/lib/nokogiri/xml/attribute_decl.rb +1 -1
  39. data/lib/nokogiri/xml/builder.rb +1 -1
  40. data/lib/nokogiri/xml/document.rb +3 -27
  41. data/lib/nokogiri/xml/document_fragment.rb +2 -9
  42. data/lib/nokogiri/xml/dtd.rb +1 -12
  43. data/lib/nokogiri/xml/element_decl.rb +1 -1
  44. data/lib/nokogiri/xml/entity_decl.rb +1 -1
  45. data/lib/nokogiri/xml/node.rb +75 -172
  46. data/lib/nokogiri/xml/node/save_options.rb +0 -10
  47. data/lib/nokogiri/xml/node_set.rb +3 -28
  48. data/lib/nokogiri/xml/parse_options.rb +0 -8
  49. data/lib/nokogiri/xml/reader.rb +6 -44
  50. data/lib/nokogiri/xml/sax/document.rb +5 -9
  51. data/lib/nokogiri/xml/schema.rb +1 -7
  52. data/lib/nokogiri/xslt.rb +5 -9
  53. data/tasks/cross_compile.rb +12 -27
  54. data/tasks/test.rb +0 -0
  55. data/test/css/test_parser.rb +19 -40
  56. data/test/css/test_tokenizer.rb +0 -8
  57. data/test/helper.rb +1 -4
  58. data/test/html/sax/test_parser.rb +21 -47
  59. data/test/html/sax/test_parser_context.rb +2 -2
  60. data/test/html/test_document.rb +3 -58
  61. data/test/html/test_document_encoding.rb +0 -53
  62. data/test/html/test_document_fragment.rb +13 -82
  63. data/test/html/test_element_description.rb +4 -2
  64. data/test/html/test_node.rb +0 -9
  65. data/test/test_memory_leak.rb +2 -57
  66. data/test/test_nokogiri.rb +14 -20
  67. data/test/test_reader.rb +7 -47
  68. data/test/test_xslt_transforms.rb +5 -8
  69. data/test/xml/sax/test_parser.rb +17 -34
  70. data/test/xml/sax/test_parser_context.rb +0 -50
  71. data/test/xml/sax/test_push_parser.rb +1 -18
  72. data/test/xml/test_attr.rb +4 -31
  73. data/test/xml/test_attribute_decl.rb +7 -3
  74. data/test/xml/test_builder.rb +5 -5
  75. data/test/xml/test_cdata.rb +3 -3
  76. data/test/xml/test_document.rb +18 -15
  77. data/test/xml/test_document_fragment.rb +20 -19
  78. data/test/xml/test_dtd.rb +13 -18
  79. data/test/xml/test_element_content.rb +1 -1
  80. data/test/xml/test_element_decl.rb +1 -1
  81. data/test/xml/test_entity_decl.rb +12 -10
  82. data/test/xml/test_namespace.rb +7 -5
  83. data/test/xml/test_node.rb +15 -54
  84. data/test/xml/test_node_reparenting.rb +42 -85
  85. data/test/xml/test_node_set.rb +2 -61
  86. data/test/xml/test_schema.rb +0 -5
  87. data/test/xml/test_text.rb +2 -11
  88. data/test/xml/test_unparented_node.rb +1 -1
  89. data/test/xml/test_xpath.rb +7 -43
  90. metadata +131 -155
  91. data/.gemtest +0 -0
  92. data/ext/nokogiri/depend +0 -358
  93. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  94. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  95. data/lib/nokogiri/css/parser_extras.rb +0 -91
  96. data/lib/nokogiri/ffi/encoding_handler.rb +0 -42
  97. data/lib/nokogiri/ffi/html/document.rb +0 -28
  98. data/lib/nokogiri/ffi/html/element_description.rb +0 -81
  99. data/lib/nokogiri/ffi/html/entity_lookup.rb +0 -16
  100. data/lib/nokogiri/ffi/html/sax/parser_context.rb +0 -38
  101. data/lib/nokogiri/ffi/io_callbacks.rb +0 -42
  102. data/lib/nokogiri/ffi/libxml.rb +0 -420
  103. data/lib/nokogiri/ffi/structs/common_node.rb +0 -38
  104. data/lib/nokogiri/ffi/structs/html_elem_desc.rb +0 -24
  105. data/lib/nokogiri/ffi/structs/html_entity_desc.rb +0 -13
  106. data/lib/nokogiri/ffi/structs/xml_alloc.rb +0 -16
  107. data/lib/nokogiri/ffi/structs/xml_attr.rb +0 -20
  108. data/lib/nokogiri/ffi/structs/xml_attribute.rb +0 -27
  109. data/lib/nokogiri/ffi/structs/xml_buffer.rb +0 -16
  110. data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +0 -11
  111. data/lib/nokogiri/ffi/structs/xml_document.rb +0 -117
  112. data/lib/nokogiri/ffi/structs/xml_dtd.rb +0 -28
  113. data/lib/nokogiri/ffi/structs/xml_element.rb +0 -26
  114. data/lib/nokogiri/ffi/structs/xml_element_content.rb +0 -17
  115. data/lib/nokogiri/ffi/structs/xml_entity.rb +0 -32
  116. data/lib/nokogiri/ffi/structs/xml_enumeration.rb +0 -12
  117. data/lib/nokogiri/ffi/structs/xml_node.rb +0 -28
  118. data/lib/nokogiri/ffi/structs/xml_node_set.rb +0 -53
  119. data/lib/nokogiri/ffi/structs/xml_notation.rb +0 -11
  120. data/lib/nokogiri/ffi/structs/xml_ns.rb +0 -15
  121. data/lib/nokogiri/ffi/structs/xml_parser_context.rb +0 -20
  122. data/lib/nokogiri/ffi/structs/xml_parser_input.rb +0 -19
  123. data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +0 -14
  124. data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +0 -51
  125. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +0 -124
  126. data/lib/nokogiri/ffi/structs/xml_schema.rb +0 -13
  127. data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +0 -31
  128. data/lib/nokogiri/ffi/structs/xml_text_reader.rb +0 -12
  129. data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +0 -38
  130. data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +0 -35
  131. data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +0 -20
  132. data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +0 -13
  133. data/lib/nokogiri/ffi/weak_bucket.rb +0 -40
  134. data/lib/nokogiri/ffi/xml/attr.rb +0 -41
  135. data/lib/nokogiri/ffi/xml/attribute_decl.rb +0 -27
  136. data/lib/nokogiri/ffi/xml/cdata.rb +0 -19
  137. data/lib/nokogiri/ffi/xml/comment.rb +0 -18
  138. data/lib/nokogiri/ffi/xml/document.rb +0 -174
  139. data/lib/nokogiri/ffi/xml/document_fragment.rb +0 -21
  140. data/lib/nokogiri/ffi/xml/dtd.rb +0 -67
  141. data/lib/nokogiri/ffi/xml/element_content.rb +0 -43
  142. data/lib/nokogiri/ffi/xml/element_decl.rb +0 -19
  143. data/lib/nokogiri/ffi/xml/entity_decl.rb +0 -36
  144. data/lib/nokogiri/ffi/xml/entity_reference.rb +0 -19
  145. data/lib/nokogiri/ffi/xml/namespace.rb +0 -44
  146. data/lib/nokogiri/ffi/xml/node.rb +0 -559
  147. data/lib/nokogiri/ffi/xml/node_set.rb +0 -150
  148. data/lib/nokogiri/ffi/xml/processing_instruction.rb +0 -20
  149. data/lib/nokogiri/ffi/xml/reader.rb +0 -236
  150. data/lib/nokogiri/ffi/xml/relax_ng.rb +0 -85
  151. data/lib/nokogiri/ffi/xml/sax/parser.rb +0 -143
  152. data/lib/nokogiri/ffi/xml/sax/parser_context.rb +0 -79
  153. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +0 -51
  154. data/lib/nokogiri/ffi/xml/schema.rb +0 -109
  155. data/lib/nokogiri/ffi/xml/syntax_error.rb +0 -98
  156. data/lib/nokogiri/ffi/xml/text.rb +0 -18
  157. data/lib/nokogiri/ffi/xml/xpath.rb +0 -9
  158. data/lib/nokogiri/ffi/xml/xpath_context.rb +0 -153
  159. data/lib/nokogiri/ffi/xslt/stylesheet.rb +0 -77
  160. data/test/decorators/test_slop.rb +0 -16
  161. data/test/ffi/test_document.rb +0 -35
  162. data/test/files/encoding.html +0 -82
  163. data/test/files/encoding.xhtml +0 -84
  164. data/test/xslt/test_custom_functions.rb +0 -94
@@ -127,15 +127,6 @@ module Nokogiri
127
127
  assert_equal 'foo&bar&baz', node['href']
128
128
  end
129
129
 
130
- def test_parse_config_option
131
- node = @html.at('div')
132
- options = nil
133
- node.parse("<div></div>") do |config|
134
- options = config
135
- end
136
- assert_equal Nokogiri::XML::ParseOptions::DEFAULT_HTML, options.to_i
137
- end
138
-
139
130
  def test_fragment_handler_does_not_regurge_on_invalid_attributes
140
131
  iframe = %Q{<iframe style="width: 0%; height: 0px" src="http://someurl" allowtransparency></iframe>}
141
132
  assert_nothing_raised { @html.at('div').fragment(iframe) }
@@ -1,38 +1,16 @@
1
1
  require "helper"
2
2
 
3
3
  class TestMemoryLeak < Nokogiri::TestCase
4
-
5
4
  if ENV['NOKOGIRI_GC'] # turning these off by default for now
6
-
7
5
  def test_dont_hurt_em_why
8
6
  content = File.open("#{File.dirname(__FILE__)}/files/dont_hurt_em_why.xml").read
9
7
  ndoc = Nokogiri::XML(content)
10
8
  2.times do
11
- ndoc.search('status text').first.inner_text
12
- ndoc.search('user name').first.inner_text
9
+ info = ndoc.search('status text').first.inner_text
10
+ url = ndoc.search('user name').first.inner_text
13
11
  GC.start
14
12
  end
15
13
  end
16
-
17
- class BadIO
18
- def read(*args)
19
- raise 'hell'
20
- end
21
-
22
- def write(*args)
23
- raise 'chickens'
24
- end
25
- end
26
-
27
- def test_for_mem_leak_on_io_callbacks
28
- io = File.open SNUGGLES_FILE
29
- reader = Nokogiri::XML.parse(io)
30
-
31
- (10**10).times do
32
- Nokogiri::XML.parse(BadIO.new) rescue nil
33
- doc.write BadIO.new rescue nil
34
- end
35
- end
36
14
 
37
15
  def test_for_memory_leak
38
16
  begin
@@ -62,39 +40,6 @@ class TestMemoryLeak < Nokogiri::TestCase
62
40
  puts "\ndike is not installed, skipping memory leak test"
63
41
  end
64
42
  end
65
-
66
- if Nokogiri.ffi?
67
- [ ['Node', 'p', nil],
68
- ['CDATA', nil, 'content'],
69
- ['Comment', nil, 'content'],
70
- ['DocumentFragment', nil],
71
- ['EntityReference', nil, 'p'],
72
- ['ProcessingInstruction', nil, 'p', 'content'] ].each do |klass, *args|
73
-
74
- define_method "test_for_leaked_#{klass}_nodes" do
75
- Nokogiri::LibXML.expects(:xmlAddChild).at_least(1) # more than once shows we're GCing properly
76
- 10.times {
77
- xml = Nokogiri::XML("<root></root>")
78
- 2.times { Nokogiri::XML.const_get(klass).new(*(args.collect{|arg| arg || xml})) }
79
- GC.start
80
- }
81
- GC.start
82
- end
83
-
84
- end
85
-
86
- def test_for_leaked_attr_nodes
87
- Nokogiri::LibXML.expects(:xmlFreePropList).at_least(1) # more than once shows we're GCing properly
88
- 10.times {
89
- xml = Nokogiri::XML("<root></root>")
90
- 2.times { Nokogiri::XML::Attr.new(xml, "p") }
91
- GC.start
92
- }
93
- GC.start
94
- end
95
-
96
- end # if ffi
97
-
98
43
  end # if NOKOGIRI_GC
99
44
 
100
45
  private
@@ -4,34 +4,28 @@ class TestNokogiri < Nokogiri::TestCase
4
4
  def test_versions
5
5
  version_match = /\d+\.\d+\.\d+/
6
6
  assert_match version_match, Nokogiri::VERSION
7
- assert_match version_match, Nokogiri::LIBXML_VERSION
8
-
9
- if defined?(FFI) && defined?(Nokogiri::LibXML)
10
- assert_equal 'ffi', Nokogiri::VERSION_INFO['libxml']['binding']
11
- if RUBY_PLATFORM =~ /java/
12
- assert_equal 'jruby', Nokogiri::VERSION_INFO['libxml']['platform']
13
- else
14
- assert_equal 'ruby', Nokogiri::VERSION_INFO['libxml']['platform']
15
- end
16
- assert Nokogiri.ffi?
17
- else
7
+
8
+ assert_equal Nokogiri::VERSION_INFO['ruby']['version'], ::RUBY_VERSION
9
+ assert_equal Nokogiri::VERSION_INFO['ruby']['platform'], ::RUBY_PLATFORM
10
+
11
+ if Nokogiri.uses_libxml?
12
+ assert_match version_match, Nokogiri::LIBXML_VERSION
18
13
  assert_equal 'extension', Nokogiri::VERSION_INFO['libxml']['binding']
19
14
 
20
15
  assert_match version_match, Nokogiri::VERSION_INFO['libxml']['compiled']
21
16
  assert_equal Nokogiri::LIBXML_VERSION, Nokogiri::VERSION_INFO['libxml']['compiled']
22
- assert ! Nokogiri.ffi?
23
- end
24
17
 
25
- assert_match version_match, Nokogiri::VERSION_INFO['libxml']['loaded']
26
- Nokogiri::LIBXML_PARSER_VERSION =~ /(\d)(\d{2})(\d{2})/
27
- major = $1.to_i
28
- minor = $2.to_i
29
- bug = $3.to_i
30
- assert_equal "#{major}.#{minor}.#{bug}", Nokogiri::VERSION_INFO['libxml']['loaded']
18
+ assert_match version_match, Nokogiri::VERSION_INFO['libxml']['loaded']
19
+ Nokogiri::LIBXML_PARSER_VERSION =~ /(\d)(\d{2})(\d{2})/
20
+ major = $1.to_i
21
+ minor = $2.to_i
22
+ bug = $3.to_i
23
+ assert_equal "#{major}.#{minor}.#{bug}", Nokogiri::VERSION_INFO['libxml']['loaded']
24
+ end
31
25
  end
32
26
 
33
27
  def test_libxml_iconv
34
- assert Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED)
28
+ assert Nokogiri.const_defined?(:LIBXML_ICONV_ENABLED) if Nokogiri.uses_libxml?
35
29
  end
36
30
 
37
31
  def test_parse_with_io
data/test/test_reader.rb CHANGED
@@ -8,32 +8,6 @@ class TestReader < Nokogiri::TestCase
8
8
  assert_equal io, reader.source
9
9
  end
10
10
 
11
- def test_empty_element?
12
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
13
- <xml><city>Paris</city><state/></xml>
14
- eoxml
15
-
16
- results = reader.map do |node|
17
- if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE
18
- node.empty_element?
19
- end
20
- end
21
- assert_equal [false, false, nil, nil, true, nil], results
22
- end
23
-
24
- def test_self_closing?
25
- reader = Nokogiri::XML::Reader.from_memory(<<-eoxml)
26
- <xml><city>Paris</city><state/></xml>
27
- eoxml
28
-
29
- results = reader.map do |node|
30
- if node.node_type == Nokogiri::XML::Node::ELEMENT_NODE
31
- node.self_closing?
32
- end
33
- end
34
- assert_equal [false, false, nil, nil, true, nil], results
35
- end
36
-
37
11
  def test_reader_takes_block
38
12
  options = nil
39
13
  Nokogiri::XML::Reader(File.read(XML_FILE), XML_FILE) do |cfg|
@@ -81,22 +55,9 @@ class TestReader < Nokogiri::TestCase
81
55
  assert_equal [false, false, false, false, false, false, false],
82
56
  reader.map { |x| x.default? }
83
57
  end
84
-
85
- class ReallyBadIO
86
- def read(size)
87
- 'a' * size ** 10
88
- end
89
- end
90
-
91
- unless Nokogiri.ffi?
92
- def test_io_that_reads_too_much
93
- io = ReallyBadIO.new
94
- Nokogiri::XML::Reader(io)
95
- end
96
- end
97
58
 
98
59
  def test_in_memory
99
- assert Nokogiri::XML::Reader(<<-eoxml)
60
+ reader = Nokogiri::XML::Reader(<<-eoxml)
100
61
  <x xmlns:tenderlove='http://tenderlovemaking.com/'>
101
62
  <tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
102
63
  </x>
@@ -110,12 +71,7 @@ class TestReader < Nokogiri::TestCase
110
71
  </x>
111
72
  eoxml
112
73
  reader = Nokogiri::XML::Reader(xml)
113
- if Nokogiri.ffi?
114
- assert_not_nil reader.source
115
- assert reader.source.is_a?(FFI::MemoryPointer)
116
- else
117
- assert_equal xml, reader.source
118
- end
74
+ assert_equal xml, reader.source
119
75
  end
120
76
 
121
77
  def test_default?
@@ -147,9 +103,13 @@ class TestReader < Nokogiri::TestCase
147
103
  <foo>
148
104
  </x>
149
105
  eoxml
150
- assert_raises(Nokogiri::XML::SyntaxError) do
106
+ error_happened = false
107
+ begin
151
108
  reader.each { |node| }
109
+ rescue Nokogiri::XML::SyntaxError => ex
110
+ error_happened = true
152
111
  end
112
+ assert error_happened
153
113
  assert 1, reader.errors.length
154
114
  end
155
115
 
@@ -1,11 +1,13 @@
1
1
  require "helper"
2
2
 
3
3
  class TestXsltTransforms < Nokogiri::TestCase
4
+
4
5
  def setup
5
6
  @doc = Nokogiri::XML(File.open(XML_FILE))
6
7
  end
7
8
 
8
- if Nokogiri.uses_libxml?
9
+ if Nokogiri.uses_libxml? && Nokogiri::VERSION_INFO['libxml']['loaded'] > '2.6.16'
10
+
9
11
  def test_class_methods
10
12
  style = Nokogiri::XSLT(File.read(XSLT_FILE))
11
13
 
@@ -157,7 +159,7 @@ encoding="iso-8859-1" indent="yes"/>
157
159
  Nokogiri::XSLT.quote_params(params.to_a.flatten)))
158
160
  check_params result_doc, params
159
161
  end
160
- end
162
+ end
161
163
 
162
164
  def test_xslt_parse_error
163
165
  xslt_str = <<-EOX
@@ -178,16 +180,11 @@ encoding="iso-8859-1" indent="yes"/>
178
180
  assert_raises(RuntimeError) { Nokogiri::XSLT.parse(xslt_str) }
179
181
  end
180
182
 
181
- def test_passing_a_non_document_to_transform
182
- xsl = Nokogiri::XSLT('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"></xsl:stylesheet>')
183
- assert_raises(ArgumentError) { xsl.transform("<div></div>") }
184
- assert_raises(ArgumentError) { xsl.transform(Nokogiri::HTML("").css("body")) }
185
- end
186
-
187
183
  def check_params result_doc, params
188
184
  result_doc.xpath('/root/params/*').each do |p|
189
185
  assert_equal p.content, params[p.name.intern]
190
186
  end
191
187
  end
188
+
192
189
  end
193
190
  end
@@ -24,7 +24,7 @@ module Nokogiri
24
24
 
25
25
  assert block_called
26
26
 
27
- assert_equal [['foo', [['a', '&b']]]], doc.start_elements
27
+ assert_equal ['a', '&b'], doc.start_elements.first.last
28
28
  end
29
29
 
30
30
  def test_parser_context_yielded_in_memory
@@ -40,7 +40,7 @@ module Nokogiri
40
40
 
41
41
  assert block_called
42
42
 
43
- assert_equal [['foo', [['a', '&b']]]], doc.start_elements
43
+ assert_equal ['a', '&b'], doc.start_elements.first.last
44
44
  end
45
45
 
46
46
  def test_xml_decl
@@ -95,6 +95,7 @@ module Nokogiri
95
95
  <foo:bar>hello world</foo:bar>
96
96
  </root>
97
97
  eoxml
98
+
98
99
  assert @parser.document.start_elements_namespace.length > 0
99
100
  el = @parser.document.start_elements_namespace[1]
100
101
  assert_equal 'a', el.first
@@ -144,8 +145,12 @@ module Nokogiri
144
145
  end
145
146
 
146
147
  def test_start_is_called_without_namespace
147
- @parser.parse('<foo:f><bar></foo:f>')
148
- assert_equal ['foo:f', 'bar'],
148
+ @parser.parse(<<-eoxml)
149
+ <root xmlns:foo='http://foo.example.com/' xmlns='http://example.com/'>
150
+ <foo:f><bar></foo:f>
151
+ </root>
152
+ eoxml
153
+ assert_equal ['root', 'foo:f', 'bar'],
149
154
  @parser.document.start_elements.map { |x| x.first }
150
155
  end
151
156
 
@@ -291,39 +296,17 @@ module Nokogiri
291
296
  @parser.parse_memory(<<-eoxml)
292
297
  <p id="asdfasdf">Paragraph 1</p>
293
298
  eoxml
294
- assert_equal [["p", [["id", "asdfasdf"]]]],
295
- @parser.document.start_elements
296
- end
297
-
298
- def test_start_element_attrs_include_namespaces
299
- @parser.parse_memory(<<-eoxml)
300
- <p xmlns:foo='http://foo.example.com/'>Paragraph 1</p>
301
- eoxml
302
- assert_equal [["p", [['xmlns:foo', 'http://foo.example.com/']]]],
299
+ assert_equal [["p", ["id", "asdfasdf"]]],
303
300
  @parser.document.start_elements
304
301
  end
305
302
 
306
- def test_parse_document
307
- @parser.parse_memory(<<-eoxml)
308
- <p>Paragraph 1</p>
309
- <p>Paragraph 2</p>
310
- eoxml
311
- end
312
-
313
- def test_parser_attributes
314
- xml = <<-eoxml
315
- <?xml version="1.0" ?><root><foo a="&amp;b" c="&gt;d" /></root>
316
- eoxml
317
-
318
- block_called = false
319
- @parser.parse(xml) { |ctx|
320
- block_called = true
321
- ctx.replace_entities = true
322
- }
323
-
324
- assert block_called
325
-
326
- assert_equal [['root', []], ['foo', [['a', '&b'], ['c', '>d']]]], @parser.document.start_elements
303
+ if Nokogiri.uses_libxml? # JRuby SAXParser only parses well-formed XML documents
304
+ def test_parse_document
305
+ @parser.parse_memory(<<-eoxml)
306
+ <p>Paragraph 1</p>
307
+ <p>Paragraph 2</p>
308
+ eoxml
309
+ end
327
310
  end
328
311
  end
329
312
  end
@@ -6,56 +6,6 @@ module Nokogiri
6
6
  module XML
7
7
  module SAX
8
8
  class TestParserContext < Nokogiri::SAX::TestCase
9
- def setup
10
- @xml = '<hello>
11
-
12
- world
13
- <inter>
14
- <net>
15
- </net>
16
- </inter>
17
-
18
- </hello>'
19
- end
20
-
21
- class Counter < Nokogiri::XML::SAX::Document
22
- attr_accessor :context, :lines, :columns
23
- def initialize
24
- @context = nil
25
- @lines = []
26
- @columns = []
27
- end
28
-
29
- def start_element name, attrs = []
30
- @lines << [name, context.line]
31
- @columns << [name, context.column]
32
- end
33
- end
34
-
35
- def test_line_numbers
36
- sax_handler = Counter.new
37
-
38
- parser = Nokogiri::XML::SAX::Parser.new(sax_handler)
39
- parser.parse(@xml) do |ctx|
40
- sax_handler.context = ctx
41
- end
42
-
43
- assert_equal [["hello", 1], ["inter", 4], ["net", 5]],
44
- sax_handler.lines
45
- end
46
-
47
- def test_column_numbers
48
- sax_handler = Counter.new
49
-
50
- parser = Nokogiri::XML::SAX::Parser.new(sax_handler)
51
- parser.parse(@xml) do |ctx|
52
- sax_handler.context = ctx
53
- end
54
-
55
- assert_equal [["hello", 7], ["inter", 7], ["net", 9]],
56
- sax_handler.columns
57
- end
58
-
59
9
  def test_replace_entities
60
10
  pc = ParserContext.new StringIO.new('<root />'), 'UTF-8'
61
11
  pc.replace_entities = false
@@ -38,24 +38,7 @@ module Nokogiri
38
38
  <p id="asdfasdf">
39
39
  eoxml
40
40
 
41
- assert_equal [["p", [["id", "asdfasdf"]]]],
42
- @parser.document.start_elements
43
-
44
- @parser.<<(<<-eoxml)
45
- <!-- This is a comment -->
46
- Paragraph 1
47
- </p>
48
- eoxml
49
- assert_equal [' This is a comment '], @parser.document.comments
50
- @parser.finish
51
- end
52
-
53
- def test_start_element_with_namespaces
54
- @parser.<<(<<-eoxml)
55
- <p xmlns:foo="http://foo.example.com/">
56
- eoxml
57
-
58
- assert_equal [["p", [["xmlns:foo", "http://foo.example.com/"]]]],
41
+ assert_equal [["p", ["id", "asdfasdf"]]],
59
42
  @parser.document.start_elements
60
43
 
61
44
  @parser.<<(<<-eoxml)
@@ -4,12 +4,10 @@ module Nokogiri
4
4
  module XML
5
5
  class TestAttr < Nokogiri::TestCase
6
6
  def test_new
7
- assert_nothing_raised do
8
- 100.times {
9
- doc = Nokogiri::XML::Document.new
10
- Nokogiri::XML::Attr.new(doc, 'foo')
11
- }
12
- end
7
+ 100.times {
8
+ doc = Nokogiri::XML::Document.new
9
+ attribute = Nokogiri::XML::Attr.new(doc, 'foo')
10
+ }
13
11
  end
14
12
 
15
13
  def test_content=
@@ -35,31 +33,6 @@ module Nokogiri
35
33
  address.attribute_nodes.first.unlink
36
34
  assert_nil address['domestic']
37
35
  end
38
-
39
- def test_parsing_attribute_namespace
40
- doc = Nokogiri::XML <<-EOXML
41
- <root xmlns='http://google.com/' xmlns:f='http://flavorjon.es/'>
42
- <div f:myattr='foo'></div>
43
- </root>
44
- EOXML
45
-
46
- node = doc.at_css "div"
47
- attr = node.attributes["myattr"]
48
- assert_equal "http://flavorjon.es/", attr.namespace.href
49
- end
50
-
51
- def test_setting_attribute_namespace
52
- doc = Nokogiri::XML <<-EOXML
53
- <root xmlns='http://google.com/' xmlns:f='http://flavorjon.es/'>
54
- <div f:myattr='foo'></div>
55
- </root>
56
- EOXML
57
-
58
- node = doc.at_css "div"
59
- attr = node.attributes["myattr"]
60
- attr.add_namespace("fizzle", "http://fizzle.com/")
61
- assert_equal "http://fizzle.com/", attr.namespace.href
62
- end
63
36
  end
64
37
  end
65
38
  end