File: stream_tests.rb

package info (click to toggle)
ruby-multi-xml 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 472 kB
  • sloc: ruby: 2,822; sh: 4; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 904 bytes parent folder | download
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
# Tests parsing from IO streams like pipes (not just strings)
module ParserStreamTests
  def test_duplexed_stream_parses_correctly
    rd, wr = IO.pipe
    Thread.new do
      "<user/>".each_char { |chunk| wr << chunk }
      wr.close
    end

    assert_equal({"user" => nil}, MultiXml.parse(rd))
  end
end

# Tests specific to SAX parsers that accept both String and IO input directly
module SaxParserTests
  def test_sax_parser_direct_string_input
    result = MultiXml.parser.parse("<root>content</root>")

    assert_equal({"root" => {"__content__" => "content"}}, result)
  end

  def test_sax_parser_direct_io_input
    result = MultiXml.parser.parse(StringIO.new("<root>content</root>"))

    assert_equal({"root" => {"__content__" => "content"}}, result)
  end

  def test_sax_parser_direct_empty_io_input
    result = MultiXml.parser.parse(StringIO.new(""))

    assert_empty(result)
  end
end