File: test_parser_context.rb

package info (click to toggle)
ruby-nokogiri 1.13.10%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,416 kB
  • sloc: ansic: 38,198; xml: 28,086; ruby: 22,271; java: 15,517; cpp: 7,037; yacc: 244; sh: 148; makefile: 136
file content (55 lines) | stat: -rw-r--r-- 1,635 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
# frozen_string_literal: true

require "helper"

module Nokogiri
  module HTML
    module SAX
      class TestParserContext < Nokogiri::SAX::TestCase
        def test_from_io
          ctx = ParserContext.new(StringIO.new("fo"), "UTF-8")
          assert(ctx)
        end

        def test_from_string
          ctx = ParserContext.new("blah blah")
          assert(ctx)
        end

        def test_parse_with
          ctx = ParserContext.new("blah")
          assert_raises(ArgumentError) do
            ctx.parse_with(nil)
          end
        end

        def test_parse_with_sax_parser
          # assert_nothing_raised do
          xml = "<root />"
          ctx = ParserContext.new(xml)
          parser = Parser.new(Doc.new)
          ctx.parse_with(parser)
          # end
        end

        def test_from_file
          # assert_nothing_raised do
          ctx = ParserContext.file(HTML_FILE, "UTF-8")
          parser = Parser.new(Doc.new)
          ctx.parse_with(parser)
          # end
        end

        def test_graceful_handling_of_invalid_types
          assert_raises(TypeError) { ParserContext.new(0xcafecafe) }
          assert_raises(TypeError) { ParserContext.memory(0xcafecafe, "UTF-8") }
          assert_raises(TypeError) { ParserContext.io(0xcafecafe, 1) }
          assert_raises(TypeError) { ParserContext.io(StringIO.new("asdf"), "should be an index into ENCODINGS") }
          assert_raises(TypeError) { ParserContext.file(0xcafecafe, "UTF-8") }
          assert_raises(TypeError) { ParserContext.file("path/to/file", 0xcafecafe) }
        end
      end
    end
  end
end