summaryrefslogtreecommitdiff
path: root/test/rexml/parser/test_stream.rb
blob: c315833e4b6fe307af8ac5dc890323253d75e2b5 (plain)
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
require "test/unit"
require "rexml/document"
require "rexml/streamlistener"

module REXMLTests
  class TestStreamParser < Test::Unit::TestCase
    class NullListener
      include REXML::StreamListener
    end

    class TestInvalid < self
      def test_no_end_tag
        xml = "<root><sub>"
        exception = assert_raise(REXML::ParseException) do
          parse(xml)
        end
        assert_equal(<<-MESSAGE, exception.to_s)
Missing end tag for '/root/sub'
Line: 1
Position: #{xml.bytesize}
Last 80 unconsumed characters:
        MESSAGE
      end

      private
      def parse(xml, listener=nil)
        listener ||= NullListener.new
        REXML::Document.parse_stream(xml, listener)
      end
    end
  end
end