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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
# encoding: utf-8
# frozen_string_literal: true
require "helper"
describe Nokogiri::HTML5 do
describe "Document#quirks_mode" do
let(:document) { Nokogiri::HTML5::Document.parse(html) }
describe "without parsing anything" do
it "returns nil" do
assert_nil(Nokogiri::HTML5::Document.new.quirks_mode)
end
end
describe "on a document with a doctype" do
let(:html) { "<!DOCTYPE html><p>hello</p>" }
it "returns NO_QUIRKS" do
assert_equal(Nokogiri::HTML5::QuirksMode::NO_QUIRKS, document.quirks_mode)
end
end
describe "on a document without a doctype" do
let(:html) { "<html><p>hello</p>" }
it "returns QUIRKS" do
assert_equal(Nokogiri::HTML5::QuirksMode::QUIRKS, document.quirks_mode)
end
end
end
describe "DocumentFragment#quirks_mode" do
let(:input) { "<p><table>" }
let(:no_quirks_output) { "<p></p><table></table>" }
let(:quirks_output) { "<p><table></table></p>" }
describe "without parsing anything" do
let(:fragment) { Nokogiri::HTML5::DocumentFragment.new(Nokogiri::HTML5::Document.new) }
it "returns nil" do
assert_nil(fragment.quirks_mode)
end
end
describe "in context" do
describe "document did not invoke the parser" do
let(:document) { Nokogiri::HTML5::Document.new }
it "parses the fragment in no-quirks mode" do
context_node = document.create_element("div")
fragment = context_node.fragment(input)
assert_equal(Nokogiri::HTML5::QuirksMode::NO_QUIRKS, fragment.quirks_mode)
assert_equal(no_quirks_output, fragment.to_html)
end
end
describe "document has a doctype" do
let(:document) { Nokogiri::HTML5::Document.parse("<!DOCTYPE html><div>") }
it "parses the fragment in no-quirks mode" do
context_node = document.at_css("div")
fragment = context_node.fragment(input)
assert_equal(Nokogiri::HTML5::QuirksMode::NO_QUIRKS, fragment.quirks_mode)
assert_equal(no_quirks_output, fragment.to_html)
end
describe "context node is just a tag name and not a real node" do
it "parses the fragment in no-quirks mode" do
fragment = Nokogiri::HTML5::DocumentFragment.new(document, input, "body")
assert_equal(Nokogiri::HTML5::QuirksMode::NO_QUIRKS, fragment.quirks_mode)
assert_equal(no_quirks_output, fragment.to_html)
end
end
end
describe "document does not have a doctype" do
let(:document) { Nokogiri::HTML5::Document.parse("<div>") }
it "parses the fragment in quirks mode" do
context_node = document.at_css("div")
fragment = context_node.fragment(input)
assert_equal(Nokogiri::HTML5::QuirksMode::QUIRKS, fragment.quirks_mode)
assert_equal(quirks_output, fragment.to_html)
end
describe "context node is just a tag name and not a real node" do
it "parses the fragment in no-quirks mode" do
fragment = Nokogiri::HTML5::DocumentFragment.new(document, input, "body")
assert_equal(Nokogiri::HTML5::QuirksMode::NO_QUIRKS, fragment.quirks_mode)
assert_equal(no_quirks_output, fragment.to_html)
end
end
end
end
describe "no context" do
describe "document did not invoke the parser" do
let(:document) { Nokogiri::HTML5::Document.new }
it "parses the fragment in no-quirks mode" do
fragment = document.fragment(input)
assert_equal(Nokogiri::HTML5::QuirksMode::NO_QUIRKS, fragment.quirks_mode)
assert_equal(no_quirks_output, fragment.to_html)
end
end
describe "document has a doctype" do
let(:document) { Nokogiri::HTML5::Document.parse("<!DOCTYPE html><div>") }
it "parses the fragment in no-quirks mode" do
fragment = document.fragment(input)
assert_equal(Nokogiri::HTML5::QuirksMode::NO_QUIRKS, fragment.quirks_mode)
assert_equal(no_quirks_output, fragment.to_html)
end
end
describe "document does not have a doctype" do
let(:document) { Nokogiri::HTML5::Document.parse("<div>") }
it "parses the fragment in no-quirks mode" do
fragment = document.fragment(input)
assert_equal(Nokogiri::HTML5::QuirksMode::NO_QUIRKS, fragment.quirks_mode)
assert_equal(no_quirks_output, fragment.to_html)
end
end
end
end
end if Nokogiri.uses_gumbo?
|