File: parser_selection_test.rb

package info (click to toggle)
ruby-rails-dom-testing 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 164 kB
  • sloc: ruby: 1,105; makefile: 4
file content (75 lines) | stat: -rw-r--r-- 3,960 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
70
71
72
73
74
75
# frozen_string_literal: true

require "test_helper"

class DomTestingParserSelectionTest < ActiveSupport::TestCase
  include DomTestingHelpers

  test "with default html4" do
    with_default_html_version(:html4) do
      assert_equal(Nokogiri::HTML4::Document, Rails::Dom::Testing.html_document)
      assert_equal(Nokogiri::HTML4::DocumentFragment, Rails::Dom::Testing.html_document_fragment)

      assert_equal(Nokogiri::HTML4::Document, Rails::Dom::Testing.html_document(html_version: :html4))
      assert_equal(Nokogiri::HTML4::DocumentFragment, Rails::Dom::Testing.html_document_fragment(html_version: :html4))

      if Rails::Dom::Testing.html5_support?
        assert_equal(Nokogiri::HTML5::Document, Rails::Dom::Testing.html_document(html_version: :html5))
        assert_equal(Nokogiri::HTML5::DocumentFragment, Rails::Dom::Testing.html_document_fragment(html_version: :html5))
      else
        assert_raises(NotImplementedError) { Rails::Dom::Testing.html_document(html_version: :html5) }
        assert_raises(NotImplementedError) { Rails::Dom::Testing.html_document_fragment(html_version: :html5) }
      end

      assert_raises(ArgumentError) { Rails::Dom::Testing.html_document(html_version: :html9) }
      assert_raises(ArgumentError) { Rails::Dom::Testing.html_document_fragment(html_version: :html9) }
    end
  end

  test "with default html5" do
    with_default_html_version(:html5) do
      if Rails::Dom::Testing.html5_support?
        assert_equal(Nokogiri::HTML5::Document, Rails::Dom::Testing.html_document)
        assert_equal(Nokogiri::HTML5::DocumentFragment, Rails::Dom::Testing.html_document_fragment)
      else
        assert_raises(NotImplementedError) { Rails::Dom::Testing.html_document }
        assert_raises(NotImplementedError) { Rails::Dom::Testing.html_document_fragment }
      end

      assert_equal(Nokogiri::HTML4::Document, Rails::Dom::Testing.html_document(html_version: :html4))
      assert_equal(Nokogiri::HTML4::DocumentFragment, Rails::Dom::Testing.html_document_fragment(html_version: :html4))

      if Rails::Dom::Testing.html5_support?
        assert_equal(Nokogiri::HTML5::Document, Rails::Dom::Testing.html_document(html_version: :html5))
        assert_equal(Nokogiri::HTML5::DocumentFragment, Rails::Dom::Testing.html_document_fragment(html_version: :html5))
      else
        assert_raises(NotImplementedError) { Rails::Dom::Testing.html_document(html_version: :html5) }
        assert_raises(NotImplementedError) { Rails::Dom::Testing.html_document_fragment(html_version: :html5) }
      end

      assert_raises(ArgumentError) { Rails::Dom::Testing.html_document(html_version: :html9) }
      assert_raises(ArgumentError) { Rails::Dom::Testing.html_document_fragment(html_version: :html9) }
    end
  end

  test "with invalid default" do
    with_default_html_version(:html8) do
      assert_raises(ArgumentError) { Rails::Dom::Testing.html_document }
      assert_raises(ArgumentError) { Rails::Dom::Testing.html_document_fragment }

      assert_equal(Nokogiri::HTML4::Document, Rails::Dom::Testing.html_document(html_version: :html4))
      assert_equal(Nokogiri::HTML4::DocumentFragment, Rails::Dom::Testing.html_document_fragment(html_version: :html4))

      if Rails::Dom::Testing.html5_support?
        assert_equal(Nokogiri::HTML5::Document, Rails::Dom::Testing.html_document(html_version: :html5))
        assert_equal(Nokogiri::HTML5::DocumentFragment, Rails::Dom::Testing.html_document_fragment(html_version: :html5))
      else
        assert_raises(NotImplementedError) { Rails::Dom::Testing.html_document(html_version: :html5) }
        assert_raises(NotImplementedError) { Rails::Dom::Testing.html_document_fragment(html_version: :html5) }
      end

      assert_raises(ArgumentError) { Rails::Dom::Testing.html_document(html_version: :html9) }
      assert_raises(ArgumentError) { Rails::Dom::Testing.html_document_fragment(html_version: :html9) }
    end
  end
end