@testable import PureXML import Testing @Suite("HTML") struct HTMLTests { private func roundTrip(_ html: String) -> String { PureXML.HTML.serialize(PureXML.HTML.parse(html)) } @Test("Void elements need no end tag and serialize without a slash") func test_voidElements() { #expect(roundTrip("

a
bc

") == "

a
bc

") } @Test("Optional end tags close implicitly") func test_optionalEndTags() { #expect(roundTrip("") == "") #expect(roundTrip("

first

second") == "

first

second

") } @Test("Table rows and cells close implicitly") func test_tableImpliedClose() { let html = "
ab
c
" #expect(roundTrip(html) == "
ab
c
") } @Test("Raw-text elements keep their content unescaped") func test_rawText() { let html = "" let parsed = PureXML.HTML.parse(html) #expect(PureXML.HTML.serialize(parsed) == html) } @Test("Attributes parse quoted, unquoted, and boolean forms") func test_attributes() { let parsed = PureXML.HTML.parse("") guard case let .document(children) = parsed, case let .element(element) = children.first else { Issue.record("expected an element") return } #expect(element.attributes.count == 3) #expect(element.attributes.contains { $0.name.description == "type" && $0.value == "text" }) #expect(element.attributes.contains { $0.name.description == "disabled" && $0.value == "" }) } @Test("Tag names are lowercased") func test_caseInsensitive() { #expect(roundTrip("
x
") == "
x
") } @Test("Character references are decoded and re-escaped") func test_entities() { #expect(roundTrip("

a & b < c A

") == "

a & b < c A

") #expect(roundTrip("

 ©

") == "

\u{A0}\u{A9}

") } @Test("Comments and an unmatched end tag are handled leniently") func test_lenient() { #expect(roundTrip("
text
") == "
text
") #expect(roundTrip("bold") == "bold") } @Test("A representative document round-trips") func test_document() { let html = "T" + "

Hi

Para with link.

" #expect(roundTrip(html) == html) } }