Skip to content

Commit

Permalink
Test fixes for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
cfis committed Jan 8, 2024
1 parent f881aab commit 96fd008
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 339 deletions.
33 changes: 22 additions & 11 deletions test/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_nil_document
LibXML::XML::Parser.document(nil)
end

assert_equal("Must pass an LibXML::XML::Document object", error.to_s)
assert_equal("Must pass an LibXML::XML::Document object", error.message)
end

def test_file
Expand All @@ -44,15 +44,15 @@ def test_noexistent_file
LibXML::XML::Parser.file('i_dont_exist.xml')
end

assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.to_s)
assert_equal('Warning: failed to load external entity "i_dont_exist.xml".', error.message)
end

def test_nil_file
error = assert_raises(TypeError) do
LibXML::XML::Parser.file(nil)
end

assert_match(/nil into String/, error.to_s)
assert_match(/nil into String/, error.message)
end

def test_file_encoding
Expand All @@ -63,7 +63,11 @@ def test_file_encoding
parser.parse
end

assert(error.to_s.match(/Fatal error: Extra content at the end of the document/))
if windows?
assert_match(/Fatal error: Opening and ending tag mismatch/, error.message)
else
assert_match(/Fatal error: Extra content at the end of the document/, error.message)
end

parser = LibXML::XML::Parser.file(file, :encoding => LibXML::XML::Encoding::UTF_8)
doc = parser.parse
Expand Down Expand Up @@ -108,7 +112,7 @@ def test_nil_io
LibXML::XML::Parser.io(nil)
end

assert_equal("Must pass in an IO object", error.to_s)
assert_equal("Must pass in an IO object", error.message)
end

def test_string_io
Expand Down Expand Up @@ -153,7 +157,7 @@ def test_nil_string
LibXML::XML::Parser.string(nil)
end

assert_equal("wrong argument type nil (expected String)", error.to_s)
assert_equal("wrong argument type nil (expected String)", error.message)
end

def test_string_options
Expand Down Expand Up @@ -212,7 +216,7 @@ def test_string_encoding
end

assert_equal("Fatal error: Input is not proper UTF-8, indicate encoding !\nBytes: 0xF6 0x74 0x6C 0x65 at :2.",
error.to_s)
error.message)

# Parse as ISO_8859_1:
parser = LibXML::XML::Parser.string(xml, :encoding => LibXML::XML::Encoding::ISO_8859_1)
Expand Down Expand Up @@ -281,16 +285,23 @@ def test_bad_xml

refute_nil(error)
assert_kind_of(LibXML::XML::Error, error)
assert_equal("Fatal error: Extra content at the end of the document at :1.", error.message)
if windows?
assert_equal("Fatal error: Couldn't find end of Start Tag ruby_array line 1 at :1.", error.message)
assert_equal(LibXML::XML::Error::GT_REQUIRED, error.code)
assert_equal("ruby_array", error.str1)
assert_equal(1, error.int1)
else
assert_equal("Fatal error: Extra content at the end of the document at :1.", error.message)
assert_equal(LibXML::XML::Error::DOCUMENT_END, error.code)
assert_nil(error.str1)
assert_equal(0, error.int1)
end
assert_equal(LibXML::XML::Error::PARSER, error.domain)
assert_equal(LibXML::XML::Error::DOCUMENT_END, error.code)
assert_equal(LibXML::XML::Error::FATAL, error.level)
assert_nil(error.file)
assert_equal(1, error.line)
assert_nil(error.str1)
assert_nil(error.str2)
assert_nil(error.str3)
assert_equal(0, error.int1)
assert_equal(34, error.int2)
assert_nil(error.node)
end
Expand Down
4 changes: 2 additions & 2 deletions test/test_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def test_string_encoding
reader = LibXML::XML::Reader.string(xml, :encoding => LibXML::XML::Encoding::ISO_8859_1)
reader.read

# Encoding is always null for strings, very annoying!
assert_equal(reader.encoding, LibXML::XML::Encoding::NONE)
encoding = windows? ? LibXML::XML::Encoding::ISO_8859_1 : LibXML::XML::Encoding::NONE
assert_equal(reader.encoding, encoding)
end
end
Loading

0 comments on commit 96fd008

Please sign in to comment.