import Testing @testable import PureXML @Suite("Canonical XML") struct CanonicalTests { private func c14n(_ xml: String, _ options: PureXML.Canonical.Options = .inclusive) throws -> String { try PureXML.Canonical.canonicalize(PureXML.parse(xml), options: options) } @Test("Empty elements expand to start/end pairs") func test_emptyElement() throws { #expect(try c14n("") == "") } @Test("Attributes are sorted by namespace URI then local name") func test_attributeOrdering() throws { #expect(try c14n("") == "") } @Test("Text special characters are escaped, but not quotes") func test_textEscaping() throws { #expect(try c14n("1 < 2 & 3 > 4") == "1 < 2 & 3 > 4") } @Test("Attribute values escape quotes and whitespace, not >") func test_attributeEscaping() throws { let xml = "" #expect(try c14n(xml) == "") } @Test("Comments are omitted by default and kept when requested") func test_comments() throws { #expect(try c14n("") == "") let withComments = PureXML.Canonical.Options(includeComments: true) #expect(try c14n("", withComments) == "") } @Test("CDATA is rendered as escaped text") func test_cdata() throws { #expect(try c14n("") == "x<y") } @Test("Namespace declarations are rendered and sorted, default first") func test_namespaceOrdering() throws { let xml = "" #expect(try c14n(xml) == "") } @Test("Inclusive C14N keeps a namespace declared but only used by a child") func test_inclusiveKeepsUnused() throws { let xml = "" #expect(try c14n(xml) == "") } @Test("Exclusive C14N drops a namespace no element visibly uses") func test_exclusiveDropsUnused() throws { let xml = "" #expect(try c14n(xml, .exclusive) == "") } @Test("Exclusive C14N renders a namespace at the element that uses it") func test_exclusiveRendersAtUse() throws { let xml = "" #expect(try c14n(xml, .exclusive) == "") } @Test("A redundant child redeclaration is not rendered twice") func test_noRedundantDeclaration() throws { let xml = "" #expect(try c14n(xml) == "") } }