import Testing @testable import PureXML @Suite("HTML5 adoption agency (misnested formatting elements)") struct HTMLAdoptionTests { private func body(_ html: String) -> String { let full = PureXML.HTML.serialize(PureXML.HTML.parseDocument(html)) let wrapper = "" guard full.hasPrefix(wrapper), full.hasSuffix("") else { return full } return String(full.dropFirst(wrapper.count).dropLast("".count)) } @Test("Overlapping formatting tags are nested") func test_overlapping() { #expect(body("") == "") } @Test("Content after a misnested close is re-wrapped (reconstruction)") func test_reconstruction() { #expect(body("X") == "X") } @Test("The fragment parser also reconstructs active formatting elements (#109)") func test_fragmentReconstruction() { // HTML.parse (fragment) now agrees with the document parser on // active-formatting reconstruction, not just the simple overlap case. #expect(PureXML.HTML.serialize(PureXML.HTML.parse("X")) == "X") #expect(PureXML.HTML.serialize(PureXML.HTML.parse("

12345

")) == "

12345

") } @Test("A block inside a formatting element triggers the furthest-block path") func test_furthestBlock() { #expect(body("1

23

") == "1

23

") } @Test("Nested anchors and formatting close cleanly") func test_nestedFormatting() { #expect(body("") == "") } @Test("The canonical adoption-agency example reparents correctly") func test_canonicalExample() { // The well-known html5lib case for the adoption agency algorithm. #expect(body("

12345

") == "

12345

") } @Test("Well-nested formatting is unchanged") func test_wellNested() { #expect(body("x") == "x") #expect(body("

bold and italic

") == "

bold and italic

") } }