Skip to content

Commit a31c095

Browse files
committed
test: update to accommodate JRuby
1 parent f124ef9 commit a31c095

File tree

2 files changed

+36
-35
lines changed

2 files changed

+36
-35
lines changed

test/html4/test_document.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,9 @@ def test_capturing_nonparse_errors_during_node_copy_between_docs
664664
node2 = doc2.at_css("#unique")
665665
original_errors1 = doc1.errors.dup
666666
original_errors2 = doc2.errors.dup
667-
assert(original_errors1.any? { |e| e.to_s.include?("foo1") }, "it should complain about the tag name")
668-
assert(original_errors2.any? { |e| e.to_s.include?("foo2") }, "it should complain about the tag name")
667+
668+
refute_empty(original_errors1)
669+
refute_empty(original_errors2)
669670

670671
node1.add_child(node2)
671672

test/html4/test_document_fragment.rb

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -221,36 +221,28 @@ def test_unclosed_script_tag
221221

222222
def test_error_propagation_on_fragment_parse
223223
frag = Nokogiri::HTML4::DocumentFragment.parse("<hello>oh, hello there</goodbye>")
224-
assert(frag.errors.any? { |err| err.to_s.include?("Unexpected end tag") }, "errors should be copied to the fragment")
224+
refute_empty(frag.errors)
225225
end
226226

227227
def test_error_propagation_on_fragment_parse_in_node_context
228228
doc = Nokogiri::HTML4::Document.parse("<html><body><div></div></body></html>")
229229
context_node = doc.at_css("div")
230230
frag = Nokogiri::HTML4::DocumentFragment.new(doc, "<hello>oh, hello there</goodbye>", context_node)
231-
assert(
232-
frag.errors.any? do |err|
233-
err.to_s.include?("Unexpected end tag")
234-
end,
235-
"errors should be on the context node's document",
236-
)
231+
refute_empty(frag.errors)
237232
end
238233

239234
def test_error_propagation_on_fragment_parse_in_node_context_should_not_include_preexisting_errors
240-
doc = Nokogiri::HTML4::Document.parse("<html><body><div></div></jimmy></body></html>")
241-
assert(doc.errors.any? { |err| err.to_s.include?("jimmy") }, "assert on setup")
235+
doc = Nokogiri::HTML4::Document.parse("<html><body><div></jimmy></body></html>")
236+
refute_empty(doc.errors)
237+
doc_errors = doc.errors.map(&:to_s)
242238

243239
context_node = doc.at_css("div")
244240
frag = Nokogiri::HTML4::DocumentFragment.new(doc, "<hello>oh, hello there.</goodbye>", context_node)
245-
assert(
246-
frag.errors.any? do |err|
247-
err.to_s.include?("goodbye")
248-
end,
249-
"errors should be on the context node's document",
250-
)
241+
refute_empty(frag.errors)
242+
251243
assert(
252244
frag.errors.none? do |err|
253-
err.to_s.include?("jimmy")
245+
doc_errors.include?(err.to_s)
254246
end,
255247
"errors should not include pre-existing document errors",
256248
)
@@ -273,8 +265,9 @@ def test_capturing_nonparse_errors_during_node_copy_between_fragments
273265
node2 = frag2.at_css("#unique")
274266
original_errors1 = frag1.errors.dup
275267
original_errors2 = frag2.errors.dup
276-
assert(original_errors1.any? { |e| e.to_s.include?("Unexpected end tag") })
277-
assert(original_errors2.any? { |e| e.to_s.include?("Unexpected end tag") })
268+
269+
refute_empty(original_errors1)
270+
refute_empty(original_errors2)
278271

279272
node1.add_child(node2)
280273

@@ -363,10 +356,17 @@ def test_parse_with_io
363356
Nokogiri::XML::ParseOptions.new(Nokogiri::XML::ParseOptions::DEFAULT_HTML).norecover
364357
end
365358

359+
let(:html4_huge) do
360+
Nokogiri::XML::ParseOptions.new(Nokogiri::XML::ParseOptions::DEFAULT_HTML).huge
361+
end
362+
366363
let(:input) { "<div>foo</div>" }
367364

368365
it "sets the test up correctly" do
366+
refute_predicate(html4_default, :strict?)
367+
refute_predicate(html4_default, :huge?)
369368
assert_predicate(html4_strict, :strict?)
369+
assert_predicate(html4_huge, :huge?)
370370
end
371371

372372
describe "HTML4.fragment" do
@@ -378,22 +378,22 @@ def test_parse_with_io
378378
end
379379

380380
it "accepts options" do
381-
frag = Nokogiri::HTML4.fragment(input, nil, html4_strict)
381+
frag = Nokogiri::HTML4.fragment(input, nil, html4_huge)
382382

383383
assert_equal("<div>foo</div>", frag.to_html)
384-
assert_equal(html4_strict, frag.parse_options)
384+
assert_equal(html4_huge, frag.parse_options)
385385
end
386386

387387
it "takes a config block" do
388388
default_config = nil
389389
frag = Nokogiri::HTML4.fragment(input) do |config|
390390
default_config = config.dup
391-
config.strict
391+
config.huge
392392
end
393393

394394
assert_equal(html4_default, default_config)
395-
refute_predicate(default_config, :strict?)
396-
assert_predicate(frag.parse_options, :strict?)
395+
refute_predicate(default_config, :huge?)
396+
assert_predicate(frag.parse_options, :huge?)
397397
end
398398
end
399399

@@ -406,22 +406,22 @@ def test_parse_with_io
406406
end
407407

408408
it "accepts options" do
409-
frag = Nokogiri::HTML4::DocumentFragment.parse(input, nil, html4_strict)
409+
frag = Nokogiri::HTML4::DocumentFragment.parse(input, nil, html4_huge)
410410

411411
assert_equal("<div>foo</div>", frag.to_html)
412-
assert_equal(html4_strict, frag.parse_options)
412+
assert_equal(html4_huge, frag.parse_options)
413413
end
414414

415415
it "takes a config block" do
416416
default_config = nil
417417
frag = Nokogiri::HTML4::DocumentFragment.parse(input) do |config|
418418
default_config = config.dup
419-
config.strict
419+
config.huge
420420
end
421421

422422
assert_equal(html4_default, default_config)
423-
refute_predicate(default_config, :strict?)
424-
assert_predicate(frag.parse_options, :strict?)
423+
refute_predicate(default_config, :huge?)
424+
assert_predicate(frag.parse_options, :huge?)
425425
end
426426
end
427427

@@ -435,22 +435,22 @@ def test_parse_with_io
435435
end
436436

437437
it "accepts options" do
438-
frag = Nokogiri::HTML4::DocumentFragment.new(Nokogiri::HTML4::Document.new, input, nil, html4_strict)
438+
frag = Nokogiri::HTML4::DocumentFragment.new(Nokogiri::HTML4::Document.new, input, nil, html4_huge)
439439

440440
assert_equal("<div>foo</div>", frag.to_html)
441-
assert_equal(html4_strict, frag.parse_options)
441+
assert_equal(html4_huge, frag.parse_options)
442442
end
443443

444444
it "takes a config block" do
445445
default_config = nil
446446
frag = Nokogiri::HTML4::DocumentFragment.new(Nokogiri::HTML4::Document.new, input) do |config|
447447
default_config = config.dup
448-
config.strict
448+
config.huge
449449
end
450450

451451
assert_equal(html4_default, default_config)
452-
refute_predicate(default_config, :strict?)
453-
assert_predicate(frag.parse_options, :strict?)
452+
refute_predicate(default_config, :huge?)
453+
assert_predicate(frag.parse_options, :huge?)
454454
end
455455
end
456456

0 commit comments

Comments
 (0)