import Testing @testable import PureXML /// Result-tree namespace fixup (XSLT 1.0 section 7.1). A namespaced attribute /// with no usable in-scope prefix gets a generated `ns` prefix and a matching /// `xmlns:ns` declaration; an unqualified element reached under an inherited /// default namespace undeclares that default with `xmlns=""`. These run on every /// transform result (`XSLTNamespaceFixup.apply`, called from the serializer) but /// were previously only exercised on the prefix-already-present path. @Suite("XSLT result-tree namespace fixup") struct XSLTNamespaceFixupTests { private let xsl = "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"" private func transform(_ template: String) throws -> String { let style = """ \(template) """ return try PureXML.XSLT.transform(stylesheet: style, source: "") } @Test("a namespaced attribute with no carried prefix gets a generated ns0 prefix") func test_attributePrefixGenerated() throws { #expect(try transform(#"v"#) == #""#) } @Test("two attributes in distinct namespaces take ns0 then ns1") func test_twoAttributePrefixesIncrement() throws { #expect(try transform(#"12"#) == #""#) } @Test("an unqualified element under an inherited default namespace undeclares it") func test_undeclareInheritedDefault() throws { #expect(try transform(#""#) == #""#) } }