-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathparser_selection_test.rb
75 lines (61 loc) · 3.87 KB
/
parser_selection_test.rb
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