nokogiri 1.4.7-x86-mingw32 → 1.5.0-x86-mingw32

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 (132) hide show
  1. data/CHANGELOG.ja.rdoc +59 -1
  2. data/CHANGELOG.rdoc +51 -2
  3. data/Manifest.txt +66 -66
  4. data/README.ja.rdoc +4 -0
  5. data/README.rdoc +31 -3
  6. data/Rakefile +111 -135
  7. data/bin/nokogiri +1 -2
  8. data/ext/nokogiri/extconf.rb +9 -3
  9. data/ext/nokogiri/nokogiri.c +21 -3
  10. data/ext/nokogiri/nokogiri.h +0 -2
  11. data/ext/nokogiri/xml_node.c +0 -6
  12. data/ext/nokogiri/xml_relax_ng.c +0 -7
  13. data/ext/nokogiri/xml_sax_parser.c +9 -4
  14. data/ext/nokogiri/xslt_stylesheet.c +5 -1
  15. data/lib/nokogiri.rb +19 -25
  16. data/lib/nokogiri/1.8/nokogiri.so +0 -0
  17. data/lib/nokogiri/1.9/nokogiri.so +0 -0
  18. data/lib/nokogiri/css.rb +0 -1
  19. data/lib/nokogiri/html.rb +1 -0
  20. data/lib/nokogiri/html/document.rb +9 -2
  21. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  22. data/lib/nokogiri/version.rb +76 -31
  23. data/lib/nokogiri/xml/attribute_decl.rb +1 -1
  24. data/lib/nokogiri/xml/builder.rb +7 -0
  25. data/lib/nokogiri/xml/document.rb +17 -1
  26. data/lib/nokogiri/xml/document_fragment.rb +14 -0
  27. data/lib/nokogiri/xml/dtd.rb +1 -1
  28. data/lib/nokogiri/xml/element_decl.rb +1 -1
  29. data/lib/nokogiri/xml/entity_decl.rb +1 -1
  30. data/lib/nokogiri/xml/node.rb +39 -15
  31. data/lib/nokogiri/xml/node/save_options.rb +14 -5
  32. data/lib/nokogiri/xml/node_set.rb +7 -0
  33. data/lib/nokogiri/xml/reader.rb +2 -2
  34. data/lib/nokogiri/xml/sax/document.rb +2 -2
  35. data/lib/nokogiri/xslt/stylesheet.rb +1 -1
  36. data/nokogiri_help_responses.md +40 -0
  37. data/tasks/cross_compile.rb +134 -155
  38. data/tasks/nokogiri.org.rb +18 -0
  39. data/tasks/test.rb +2 -2
  40. data/test/files/metacharset.html +10 -0
  41. data/test/files/noencoding.html +47 -0
  42. data/test/helper.rb +2 -1
  43. data/test/html/sax/test_parser.rb +22 -5
  44. data/test/html/test_document.rb +21 -2
  45. data/test/html/test_document_encoding.rb +9 -1
  46. data/test/html/test_document_fragment.rb +5 -3
  47. data/test/html/test_element_description.rb +4 -2
  48. data/test/test_memory_leak.rb +4 -39
  49. data/test/test_nokogiri.rb +14 -20
  50. data/test/test_reader.rb +12 -8
  51. data/test/xml/node/test_save_options.rb +10 -2
  52. data/test/xml/sax/test_parser.rb +14 -7
  53. data/test/xml/test_attribute_decl.rb +7 -3
  54. data/test/xml/test_builder.rb +17 -0
  55. data/test/xml/test_document.rb +31 -4
  56. data/test/xml/test_dtd.rb +13 -3
  57. data/test/xml/test_element_content.rb +1 -1
  58. data/test/xml/test_element_decl.rb +1 -1
  59. data/test/xml/test_entity_decl.rb +12 -10
  60. data/test/xml/test_namespace.rb +7 -5
  61. data/test/xml/test_node.rb +21 -10
  62. data/test/xml/test_node_reparenting.rb +16 -3
  63. data/test/xml/test_node_set.rb +34 -0
  64. data/test/xslt/test_custom_functions.rb +2 -2
  65. data/test/xslt/test_exception_handling.rb +37 -0
  66. metadata +110 -88
  67. data/lib/nokogiri/ffi/encoding_handler.rb +0 -42
  68. data/lib/nokogiri/ffi/html/document.rb +0 -28
  69. data/lib/nokogiri/ffi/html/element_description.rb +0 -81
  70. data/lib/nokogiri/ffi/html/entity_lookup.rb +0 -16
  71. data/lib/nokogiri/ffi/html/sax/parser_context.rb +0 -38
  72. data/lib/nokogiri/ffi/io_callbacks.rb +0 -42
  73. data/lib/nokogiri/ffi/libxml.rb +0 -420
  74. data/lib/nokogiri/ffi/structs/common_node.rb +0 -38
  75. data/lib/nokogiri/ffi/structs/html_elem_desc.rb +0 -24
  76. data/lib/nokogiri/ffi/structs/html_entity_desc.rb +0 -13
  77. data/lib/nokogiri/ffi/structs/xml_alloc.rb +0 -16
  78. data/lib/nokogiri/ffi/structs/xml_attr.rb +0 -20
  79. data/lib/nokogiri/ffi/structs/xml_attribute.rb +0 -27
  80. data/lib/nokogiri/ffi/structs/xml_buffer.rb +0 -16
  81. data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +0 -11
  82. data/lib/nokogiri/ffi/structs/xml_document.rb +0 -117
  83. data/lib/nokogiri/ffi/structs/xml_dtd.rb +0 -28
  84. data/lib/nokogiri/ffi/structs/xml_element.rb +0 -26
  85. data/lib/nokogiri/ffi/structs/xml_element_content.rb +0 -17
  86. data/lib/nokogiri/ffi/structs/xml_entity.rb +0 -32
  87. data/lib/nokogiri/ffi/structs/xml_enumeration.rb +0 -12
  88. data/lib/nokogiri/ffi/structs/xml_node.rb +0 -28
  89. data/lib/nokogiri/ffi/structs/xml_node_set.rb +0 -53
  90. data/lib/nokogiri/ffi/structs/xml_notation.rb +0 -11
  91. data/lib/nokogiri/ffi/structs/xml_ns.rb +0 -15
  92. data/lib/nokogiri/ffi/structs/xml_parser_context.rb +0 -20
  93. data/lib/nokogiri/ffi/structs/xml_parser_input.rb +0 -19
  94. data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +0 -14
  95. data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +0 -51
  96. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +0 -124
  97. data/lib/nokogiri/ffi/structs/xml_schema.rb +0 -13
  98. data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +0 -31
  99. data/lib/nokogiri/ffi/structs/xml_text_reader.rb +0 -12
  100. data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +0 -38
  101. data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +0 -35
  102. data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +0 -20
  103. data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +0 -13
  104. data/lib/nokogiri/ffi/weak_bucket.rb +0 -40
  105. data/lib/nokogiri/ffi/xml/attr.rb +0 -41
  106. data/lib/nokogiri/ffi/xml/attribute_decl.rb +0 -27
  107. data/lib/nokogiri/ffi/xml/cdata.rb +0 -19
  108. data/lib/nokogiri/ffi/xml/comment.rb +0 -18
  109. data/lib/nokogiri/ffi/xml/document.rb +0 -174
  110. data/lib/nokogiri/ffi/xml/document_fragment.rb +0 -21
  111. data/lib/nokogiri/ffi/xml/dtd.rb +0 -67
  112. data/lib/nokogiri/ffi/xml/element_content.rb +0 -43
  113. data/lib/nokogiri/ffi/xml/element_decl.rb +0 -19
  114. data/lib/nokogiri/ffi/xml/entity_decl.rb +0 -36
  115. data/lib/nokogiri/ffi/xml/entity_reference.rb +0 -19
  116. data/lib/nokogiri/ffi/xml/namespace.rb +0 -44
  117. data/lib/nokogiri/ffi/xml/node.rb +0 -559
  118. data/lib/nokogiri/ffi/xml/node_set.rb +0 -150
  119. data/lib/nokogiri/ffi/xml/processing_instruction.rb +0 -20
  120. data/lib/nokogiri/ffi/xml/reader.rb +0 -236
  121. data/lib/nokogiri/ffi/xml/relax_ng.rb +0 -85
  122. data/lib/nokogiri/ffi/xml/sax/parser.rb +0 -143
  123. data/lib/nokogiri/ffi/xml/sax/parser_context.rb +0 -79
  124. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +0 -51
  125. data/lib/nokogiri/ffi/xml/schema.rb +0 -109
  126. data/lib/nokogiri/ffi/xml/syntax_error.rb +0 -98
  127. data/lib/nokogiri/ffi/xml/text.rb +0 -18
  128. data/lib/nokogiri/ffi/xml/xpath.rb +0 -9
  129. data/lib/nokogiri/ffi/xml/xpath_context.rb +0 -153
  130. data/lib/nokogiri/ffi/xslt/stylesheet.rb +0 -77
  131. data/lib/nokogiri/version_warning.rb +0 -14
  132. data/test/ffi/test_document.rb +0 -35
data/test/helper.rb CHANGED
@@ -7,7 +7,7 @@ require 'pp'
7
7
 
8
8
  require 'nokogiri'
9
9
 
10
- warn "#{__FILE__}:#{__LINE__}: libxml version info: #{Nokogiri::VERSION_INFO.inspect}"
10
+ warn "#{__FILE__}:#{__LINE__}: version info: #{Nokogiri::VERSION_INFO.inspect}"
11
11
 
12
12
  module Nokogiri
13
13
  class TestCase < MiniTest::Spec
@@ -23,6 +23,7 @@ module Nokogiri
23
23
  ENCODING_XHTML_FILE = File.join(ASSETS_DIR, 'encoding.xhtml')
24
24
  ENCODING_HTML_FILE = File.join(ASSETS_DIR, 'encoding.html')
25
25
  NOENCODING_FILE = File.join(ASSETS_DIR, 'noencoding.html')
26
+ METACHARSET_FILE = File.join(ASSETS_DIR, 'metacharset.html')
26
27
  PO_XML_FILE = File.join(ASSETS_DIR, 'po.xml')
27
28
  PO_SCHEMA_FILE = File.join(ASSETS_DIR, 'po.xsd')
28
29
  ADDRESS_SCHEMA_FILE = File.join(ASSETS_DIR, 'address_book.rlx')
@@ -24,7 +24,14 @@ module Nokogiri
24
24
 
25
25
  def test_parse_file
26
26
  @parser.parse_file(HTML_FILE)
27
- assert_equal 1110, @parser.document.end_elements.length
27
+
28
+ # Take a look at the comment in test_parse_document to know
29
+ # a possible reason to this difference.
30
+ if Nokogiri.uses_libxml?
31
+ assert_equal 1110, @parser.document.end_elements.length
32
+ else
33
+ assert_equal 1119, @parser.document.end_elements.length
34
+ end
28
35
  end
29
36
 
30
37
  def test_parse_file_nil_argument
@@ -65,8 +72,20 @@ module Nokogiri
65
72
  <p>Paragraph 1</p>
66
73
  <p>Paragraph 2</p>
67
74
  eoxml
68
- assert_equal([["html", []], ["body", []], ["p", []], ["p", []]],
69
- @parser.document.start_elements)
75
+
76
+ # JRuby version is different because of the internal implementation
77
+ # JRuby version uses NekoHTML which inserts empty "head" elements.
78
+ #
79
+ # Currently following features are set:
80
+ # "http://cyberneko.org/html/properties/names/elems" => "lower"
81
+ # "http://cyberneko.org/html/properties/names/attrs" => "lower"
82
+ if Nokogiri.uses_libxml?
83
+ assert_equal([["html", []], ["body", []], ["p", []], ["p", []]],
84
+ @parser.document.start_elements)
85
+ else
86
+ assert_equal([["html", []], ["head", []], ["body", []], ["p", []], ["p", []]],
87
+ @parser.document.start_elements)
88
+ end
70
89
  end
71
90
 
72
91
  def test_parser_attributes
@@ -92,8 +111,6 @@ module Nokogiri
92
111
 
93
112
  noshade_value = if Nokogiri.uses_libxml? && Nokogiri::VERSION_INFO['libxml']['loaded'] < '2.7.7'
94
113
  ['noshade', 'noshade']
95
- elsif Nokogiri.jruby?
96
- ['noshade', '']
97
114
  else
98
115
  ['noshade', nil]
99
116
  end
@@ -8,6 +8,12 @@ module Nokogiri
8
8
  @html = Nokogiri::HTML.parse(File.read(HTML_FILE))
9
9
  end
10
10
 
11
+ def test_nil_css
12
+ # Behavior is undefined but shouldn't break
13
+ assert @html.css(nil)
14
+ assert @html.xpath(nil)
15
+ end
16
+
11
17
  def test_exceptions_remove_newlines
12
18
  errors = @html.errors
13
19
  assert errors.length > 0, 'has errors'
@@ -87,7 +93,7 @@ module Nokogiri
87
93
  assert_nil doc.root
88
94
  end
89
95
 
90
- unless %w[2 6] === LIBXML_VERSION.split('.')[0..1]
96
+ unless Nokogiri.uses_libxml? && %w[2 6] === LIBXML_VERSION.split('.')[0..1]
91
97
  # FIXME: this is a hack around broken libxml versions
92
98
  def test_to_xhtml_with_indent
93
99
  doc = Nokogiri::HTML('<html><body><a>foo</a></body></html>')
@@ -178,7 +184,11 @@ eohtml
178
184
  </html>
179
185
  eohtml
180
186
  doc.title = 'new'
181
- assert_nil doc.title
187
+ if Nokogiri.uses_libxml?
188
+ assert_nil doc.title
189
+ else
190
+ assert_equal 'new', doc.title
191
+ end
182
192
  end
183
193
 
184
194
  def test_meta_encoding_without_head
@@ -222,6 +232,15 @@ eohtml
222
232
  }
223
233
  end
224
234
 
235
+ def test_parse_temp_file
236
+ temp_html_file = Tempfile.new("TEMP_HTML_FILE")
237
+ File.open(HTML_FILE, 'rb') { |f| temp_html_file.write f.read }
238
+ temp_html_file.close
239
+ temp_html_file.open
240
+ assert_equal Nokogiri::HTML.parse(File.read(HTML_FILE)).xpath('//div/a').length,
241
+ Nokogiri::HTML.parse(temp_html_file).xpath('//div/a').length
242
+ end
243
+
225
244
  def test_to_xhtml
226
245
  assert_match 'XHTML', @html.to_xhtml
227
246
  assert_match 'XHTML', @html.to_xhtml(:encoding => 'UTF-8')
@@ -96,6 +96,12 @@ module Nokogiri
96
96
  assert_equal from_string.to_s.size, from_stream.to_s.size
97
97
  end
98
98
 
99
+ def test_document_html_charset
100
+ html = Nokogiri::HTML(binopen(METACHARSET_FILE))
101
+ assert_equal 'iso-2022-jp', html.encoding
102
+ assert_equal 'たこ焼き仮面', html.title
103
+ end
104
+
99
105
  def test_document_xhtml_enc
100
106
  [ENCODING_XHTML_FILE, ENCODING_HTML_FILE].each { |file|
101
107
  doc_from_string_enc = Nokogiri::HTML(binread(file), nil, 'Shift_JIS')
@@ -115,7 +121,9 @@ module Nokogiri
115
121
  assert_equal(title, doc_from_string_enc.at('//title/text()').text)
116
122
  assert_equal(title, doc_from_string.at('//title/text()').text)
117
123
  assert_equal(title, doc_from_file_enc.at('//title/text()').text)
118
- assert_equal(title, doc_from_file.at('//title/text()').text)
124
+ unless Nokogiri.jruby? && file == ENCODING_HTML_FILE
125
+ assert_equal(title, doc_from_file.at('//title/text()').text)
126
+ end
119
127
 
120
128
  evil = (0..72).map { |i| '超' * i + '悪い事を構想中。' }
121
129
 
@@ -133,7 +133,8 @@ module Nokogiri
133
133
  def test_html_fragment_has_outer_text
134
134
  doc = "a<div>b</div>c"
135
135
  fragment = Nokogiri::HTML::Document.new.fragment(doc)
136
- if Nokogiri::VERSION_INFO['libxml']['loaded'] <= "2.6.16"
136
+ if Nokogiri.uses_libxml? &&
137
+ Nokogiri::VERSION_INFO['libxml']['loaded'] <= "2.6.16"
137
138
  assert_equal "a<div>b</div><p>c</p>", fragment.to_s
138
139
  else
139
140
  assert_equal "a<div>b</div>c", fragment.to_s
@@ -189,7 +190,8 @@ module Nokogiri
189
190
  def test_to_xhtml
190
191
  doc = "<span>foo<br></span><span>bar</span>"
191
192
  fragment = Nokogiri::HTML::Document.new.fragment(doc)
192
- if Nokogiri::VERSION_INFO['libxml']['loaded'] >= "2.7.0"
193
+ if !Nokogiri.uses_libxml? ||
194
+ Nokogiri::VERSION_INFO['libxml']['loaded'] >= "2.7.0"
193
195
  assert_equal "<span>foo<br /></span><span>bar</span>", fragment.to_xhtml
194
196
  else
195
197
  assert_equal "<span>foo<br></span><span>bar</span>", fragment.to_xhtml
@@ -246,7 +248,7 @@ module Nokogiri
246
248
  context_node = doc.at_css "div"
247
249
  frag = Nokogiri::HTML::DocumentFragment.new doc, "<hello>oh, hello there.</hello>", context_node
248
250
  assert frag.errors.any?{|err| err.to_s =~ /Tag hello invalid/}, "errors should be on the context node's document"
249
- assert ! frag.errors.any?{|err| err.to_s =~ /jimmy/}, "errors should not include pre-existing document errors"
251
+ assert frag.errors.none?{|err| err.to_s =~ /jimmy/}, "errors should not include pre-existing document errors"
250
252
  end
251
253
  end
252
254
  end
@@ -56,10 +56,12 @@ module Nokogiri
56
56
 
57
57
  def test_subelements
58
58
  sub_elements = ElementDescription['body'].sub_elements
59
- if Nokogiri::LIBXML_VERSION >= '2.7.7'
59
+ if Nokogiri.uses_libxml? && Nokogiri::LIBXML_VERSION >= '2.7.7'
60
60
  assert_equal 65, sub_elements.length
61
- else
61
+ elsif Nokogiri.uses_libxml?
62
62
  assert_equal 61, sub_elements.length
63
+ else
64
+ assert sub_elements.length > 0
63
65
  end
64
66
  end
65
67
 
@@ -1,9 +1,7 @@
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)
@@ -13,20 +11,20 @@ class TestMemoryLeak < Nokogiri::TestCase
13
11
  GC.start
14
12
  end
15
13
  end
16
-
14
+
17
15
  class BadIO
18
16
  def read(*args)
19
17
  raise 'hell'
20
18
  end
21
-
19
+
22
20
  def write(*args)
23
21
  raise 'chickens'
24
22
  end
25
23
  end
26
-
24
+
27
25
  def test_for_mem_leak_on_io_callbacks
28
26
  io = File.open SNUGGLES_FILE
29
- reader = Nokogiri::XML.parse(io)
27
+ Nokogiri::XML.parse(io)
30
28
 
31
29
  (10**10).times do
32
30
  Nokogiri::XML.parse(BadIO.new) rescue nil
@@ -62,39 +60,6 @@ class TestMemoryLeak < Nokogiri::TestCase
62
60
  puts "\ndike is not installed, skipping memory leak test"
63
61
  end
64
62
  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
63
  end # if NOKOGIRI_GC
99
64
 
100
65
  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
@@ -88,8 +88,17 @@ class TestReader < Nokogiri::TestCase
88
88
  end
89
89
  end
90
90
 
91
- unless Nokogiri.ffi?
92
- def test_io_that_reads_too_much
91
+ class ReallyBadIO4Java
92
+ def read(size=1)
93
+ 'a' * size ** 10
94
+ end
95
+ end
96
+
97
+ def test_io_that_reads_too_much
98
+ if Nokogiri.jruby?
99
+ io = ReallyBadIO4Java.new
100
+ Nokogiri::XML::Reader(io)
101
+ else
93
102
  io = ReallyBadIO.new
94
103
  Nokogiri::XML::Reader(io)
95
104
  end
@@ -110,12 +119,7 @@ class TestReader < Nokogiri::TestCase
110
119
  </x>
111
120
  eoxml
112
121
  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
122
+ assert_equal xml, reader.source
119
123
  end
120
124
 
121
125
  def test_default?
@@ -5,14 +5,22 @@ module Nokogiri
5
5
  class Node
6
6
  class TestSaveOptions < Nokogiri::TestCase
7
7
  SaveOptions.constants.each do |constant|
8
- class_eval %{
8
+ class_eval <<-EOEVAL
9
9
  def test_predicate_#{constant.downcase}
10
10
  options = SaveOptions.new(SaveOptions::#{constant})
11
11
  assert options.#{constant.downcase}?
12
12
 
13
13
  assert SaveOptions.new.#{constant.downcase}.#{constant.downcase}?
14
14
  end
15
- }
15
+ EOEVAL
16
+ end
17
+
18
+ def test_default_xml_save_options
19
+ if Nokogiri.jruby?
20
+ assert_equal 0, (SaveOptions::DEFAULT_XML & SaveOptions::FORMAT)
21
+ else
22
+ assert_equal SaveOptions::FORMAT, (SaveOptions::DEFAULT_XML & SaveOptions::FORMAT)
23
+ end
16
24
  end
17
25
  end
18
26
  end
@@ -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
 
@@ -303,11 +308,13 @@ module Nokogiri
303
308
  @parser.document.start_elements
304
309
  end
305
310
 
306
- def test_parse_document
307
- @parser.parse_memory(<<-eoxml)
308
- <p>Paragraph 1</p>
309
- <p>Paragraph 2</p>
310
- eoxml
311
+ if Nokogiri.uses_libxml? # JRuby SAXParser only parses well-formed XML documents
312
+ def test_parse_document
313
+ @parser.parse_memory(<<-eoxml)
314
+ <p>Paragraph 1</p>
315
+ <p>Paragraph 2</p>
316
+ eoxml
317
+ end
311
318
  end
312
319
 
313
320
  def test_parser_attributes
@@ -9,7 +9,7 @@ module Nokogiri
9
9
  <?xml version="1.0"?><?TEST-STYLE PIDATA?>
10
10
  <!DOCTYPE staff SYSTEM "staff.dtd" [
11
11
  <!ATTLIST br width CDATA "0">
12
- <!ATTLIST a width CDATA >
12
+ <!ATTLIST a width CDATA "0">
13
13
  <!ATTLIST payment type (check|cash) "cash">
14
14
  ]>
15
15
  <root />
@@ -64,12 +64,16 @@ module Nokogiri
64
64
  end
65
65
 
66
66
  def test_attribute_type
67
- assert_equal 1, @attr_decl.attribute_type
67
+ if Nokogiri.uses_libxml?
68
+ assert_equal 1, @attr_decl.attribute_type
69
+ else
70
+ assert_equal 'CDATA', @attr_decl.attribute_type
71
+ end
68
72
  end
69
73
 
70
74
  def test_default
71
75
  assert_equal '0', @attr_decl.default
72
- assert_nil @attrs[1].default
76
+ assert_equal '0', @attrs[1].default
73
77
  end
74
78
 
75
79
  def test_enumeration
@@ -3,6 +3,23 @@ require "helper"
3
3
  module Nokogiri
4
4
  module XML
5
5
  class TestBuilder < Nokogiri::TestCase
6
+ def test_attribute_sensitivity
7
+ xml = Nokogiri::XML::Builder.new { |x|
8
+ x.tag "hello", "abcDef" => "world"
9
+ }.to_xml
10
+ doc = Nokogiri.XML xml
11
+ assert_equal 'world', doc.root['abcDef']
12
+ end
13
+
14
+ def test_builder_escape
15
+ xml = Nokogiri::XML::Builder.new { |x|
16
+ x.condition "value < 1", :attr => "value < 1"
17
+ }.to_xml
18
+ doc = Nokogiri.XML xml
19
+ assert_equal 'value < 1', doc.root['attr']
20
+ assert_equal 'value < 1', doc.root.content
21
+ end
22
+
6
23
  def test_builder_namespace
7
24
  doc = Nokogiri::XML::Builder.new { |xml|
8
25
  xml.a("xmlns:a" => "x") do