1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
# frozen_string_literal: true
require "helper"
describe Nokogiri::XML::SyntaxError do
it ".new accepts a message" do
error = Nokogiri::XML::SyntaxError.new("hello")
assert_equal "hello", error.message
end
describe ".aggregate" do
describe "when there are no errors" do
it "returns nil" do
assert_nil(Nokogiri::XML::SyntaxError.aggregate([]))
end
end
describe "when there is exactly one error" do
it "returns the error" do
error = Nokogiri::XML::SyntaxError.new("hello")
assert_equal(error, Nokogiri::XML::SyntaxError.aggregate([error]))
end
end
describe "when there are multiple errors" do
it "returns a new error with the messages of all errors" do
errors = [
Nokogiri::XML::SyntaxError.new("hello"),
Nokogiri::XML::SyntaxError.new("there"),
Nokogiri::XML::SyntaxError.new("world"),
]
aggregate = Nokogiri::XML::SyntaxError.aggregate(errors)
assert_equal(<<~MSG.chomp, aggregate.to_s)
Multiple errors encountered:
hello
there
world
MSG
end
end
end
it "describes the syntax error encountered" do
if Nokogiri.uses_libxml?
bad_doc = Nokogiri::XML("test")
error = bad_doc.errors.first
assert_equal "1:1: FATAL: Start tag expected, '<' not found", error.message
assert_equal 1, error.line
assert_equal 1, error.column
assert_equal 3, error.level
else
bad_doc = Nokogiri::XML("<root>test</bar>")
error = bad_doc.errors.first
assert_equal "The element type \"root\" must be terminated by the matching end-tag \"</root>\".", error.message
assert_nil error.line
assert_nil error.column
assert_nil error.level
end
assert_nil error.path
end
end
|