@testable import PureXML import Testing @Suite("HTML5 document tree construction") struct HTMLDocumentTests { private func document(_ html: String) -> String { PureXML.HTML.serialize(PureXML.HTML.parseDocument(html)) } @Test("Implied html, head, and body wrap a bare fragment") func test_impliedStructure() { #expect(document("

hello

") == "

hello

") } @Test("Head-only elements are routed into the head") func test_headRouting() { let html = "T

body

" let expected = "T

body

" #expect(document(html) == expected) } @Test("Explicit html, head, and body are honored") func test_explicitStructure() { let html = "T

Hi

" #expect(document(html) == "T

Hi

") } @Test("Flow content before any head element starts the body") func test_flowStartsBody() { #expect(document("
x
") == "
x
") } @Test("A head element after body content stays in the body's flow") func test_explicitBodyThenContent() { let html = "

one

two

" #expect(document(html) == "

one

two

") } @Test("html attributes are preserved on the implied structure") func test_htmlAttributes() { #expect(document("

x

") == "

x

") } // MARK: Table tree construction /// Wraps a body fragment in the implied document structure for comparison. private func bodyDocument(_ inner: String) -> String { "\(inner)" } @Test("A bare table row gets an implied tbody") func test_impliedTbody() { #expect(document("
x
") == bodyDocument("
x
")) } @Test("A bare cell gets an implied tbody and row") func test_impliedRowAndSection() { #expect(document("
x
") == bodyDocument("
x
")) } @Test("An explicit section is not duplicated") func test_explicitSection() { #expect(document("
h
") == bodyDocument("
h
")) } @Test("Consecutive rows share one implied tbody") func test_consecutiveRows() { #expect(document("
a
b
") == bodyDocument("
a
b
")) } @Test("A stray element inside a table is foster-parented before it") func test_fosterElement() { #expect(document("x
") == bodyDocument("x
")) } @Test("Stray text inside a table is foster-parented before it") func test_fosterText() { #expect(document("text
c
") == bodyDocument("text
c
")) } @Test("Well-formed cell content is not foster-parented") func test_noFosterInCell() { #expect(document("
x
") == bodyDocument("
x
")) } @Test("A template's content nests inside it") func test_templateContent() { #expect(document("") == bodyDocument("")) } }