import Testing @testable import PureXML @Suite("Canonical XML 2.0: sequential prefix rewrite and QName-aware values") struct CanonicalPrefixRewriteTests { private func c14n(_ xml: String, _ options: PureXML.Canonical.Options) throws -> String { try PureXML.Canonical.canonicalize(PureXML.parse(xml), options: options) } private let sequential = PureXML.Canonical.Options(prefixRewrite: .sequential) @Test("Sequential rewrite renames a prefix to n0 and declares it at first use") func test_basicRewrite() throws { #expect(try c14n("", sequential) == "") } @Test("Documents differing only in prefix spelling canonicalize identically") func test_prefixIndependence() throws { let withP = try c14n("", sequential) let withQ = try c14n("", sequential) #expect(withP == withQ) } @Test("The default namespace is given a canonical prefix") func test_defaultNamespaceRewritten() throws { #expect(try c14n("", sequential) == "") } @Test("Prefixes are numbered in document order of first use") func test_documentOrderNumbering() throws { let xml = "" // urn:b is used first (by ), so it becomes n0; urn:a becomes n1. #expect(try c14n(xml, sequential) == "") } @Test("A QName-aware attribute value has its prefix rewritten too") func test_qnameAwareAttribute() throws { let options = PureXML.Canonical.Options( prefixRewrite: .sequential, qnameAwareLabels: [.init(localName: "type")], ) // with p bound to urn:x: type becomes the canonical prefix. let output = try c14n("", options) #expect(output == "") } @Test("Retain (the default) leaves prefixes untouched") func test_retainDefault() throws { #expect(try c14n("", .inclusive) == "") } }