2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2013-09-03 09:57:18 -04:00
|
|
|
require "test/unit"
|
|
|
|
require "rexml/document"
|
|
|
|
require "rexml/parsers/treeparser"
|
|
|
|
|
2014-05-27 08:07:40 -04:00
|
|
|
module REXMLTests
|
2013-09-03 09:57:18 -04:00
|
|
|
class TestTreeParser < Test::Unit::TestCase
|
|
|
|
class TestInvalid < self
|
2013-09-03 09:58:24 -04:00
|
|
|
def test_unmatched_close_tag
|
2013-09-03 09:57:18 -04:00
|
|
|
xml = "<root></not-root>"
|
|
|
|
exception = assert_raise(REXML::ParseException) do
|
|
|
|
parse(xml)
|
|
|
|
end
|
|
|
|
assert_equal(<<-MESSAGE, exception.to_s)
|
2018-12-19 21:49:10 -05:00
|
|
|
Missing end tag for 'root' (got 'not-root')
|
2013-09-03 09:57:18 -04:00
|
|
|
Line: 1
|
2013-09-03 10:02:10 -04:00
|
|
|
Position: #{xml.bytesize}
|
2013-09-03 09:57:18 -04:00
|
|
|
Last 80 unconsumed characters:
|
|
|
|
MESSAGE
|
|
|
|
end
|
|
|
|
|
2013-09-03 10:01:20 -04:00
|
|
|
def test_no_close_tag
|
|
|
|
xml = "<root>"
|
|
|
|
exception = assert_raise(REXML::ParseException) do
|
|
|
|
parse(xml)
|
|
|
|
end
|
|
|
|
assert_equal(<<-MESSAGE, exception.to_s)
|
|
|
|
No close tag for /root
|
|
|
|
Line: 1
|
|
|
|
Position: #{xml.bytesize}
|
|
|
|
Last 80 unconsumed characters:
|
|
|
|
MESSAGE
|
|
|
|
end
|
|
|
|
|
2013-09-03 09:57:18 -04:00
|
|
|
private
|
|
|
|
def parse(xml)
|
|
|
|
document = REXML::Document.new
|
|
|
|
parser = REXML::Parsers::TreeParser.new(xml, document)
|
|
|
|
parser.parse
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-05-27 06:21:10 -04:00
|
|
|
end
|