File: test_push_parser.rb

package info (click to toggle)
ruby-nokogiri 1.18.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,076 kB
  • sloc: ansic: 38,893; xml: 27,665; ruby: 27,285; java: 15,348; cpp: 7,107; yacc: 244; sh: 208; makefile: 154; sed: 14
file content (69 lines) | stat: -rw-r--r-- 1,647 bytes parent folder | download | duplicates (2)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
# frozen_string_literal: true

require "helper"

describe Nokogiri::HTML4::SAX::PushParser do
  let(:parser) { Nokogiri::HTML4::SAX::PushParser.new(Nokogiri::SAX::TestCase::Doc.new) }

  it :test_end_document_called do
    parser << (<<~HTML)
      <p id="asdfasdf">
        <!-- This is a comment -->
        Paragraph 1
      </p>
    HTML
    refute(parser.document.end_document_called)
    parser.finish
    assert(parser.document.end_document_called)
  end

  it :test_start_element do
    parser << (<<~HTML)
      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
      <html><head><body><p id="asdfasdf">
    HTML

    assert_equal(
      [["html", []], ["head", []], ["body", []], ["p", [["id", "asdfasdf"]]]],
      parser.document.start_elements,
    )

    parser << (<<~HTML)
      <!-- This is a comment -->
      Paragraph 1
      </p></body></html>
    HTML
    assert_equal([" This is a comment "], parser.document.comments)
    parser.finish
  end

  it :test_chevron_partial_html do
    parser << (<<~HTML)
      <p id="asdfasdf">
    HTML

    parser << (<<-HTML)
        <!-- This is a comment -->
        Paragraph 1
      </p>
    HTML
    assert_equal([" This is a comment "], parser.document.comments)
    parser.finish
  end

  it :test_chevron do
    parser << (<<~HTML)
      <p id="asdfasdf">
        <!-- This is a comment -->
        Paragraph 1
      </p>
    HTML
    parser.finish
    assert_equal([" This is a comment "], parser.document.comments)
  end

  it :test_default_options do
    assert_equal(0, parser.options)
  end
end