From 3ffbff91ede95e4e9531a94caa763ee7a43ccc5d Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Fri, 26 Jun 2026 08:22:34 +0200 Subject: [PATCH] test(xslt): cover result-tree namespace fixup generation paths (#319) Adds XSLTNamespaceFixupTests for the previously-untested live paths in XSLTNamespaceFixup.apply: generated ns0/ns1 prefixes for namespaced attributes with no carried prefix, and xmlns="" undeclaration of an inherited default namespace on an unqualified element (XSLT 1.0 7.1). Exact serialized-output assertions, matching the existing XSLT test idiom. --- Tests/XSLTNamespaceFixupTests.swift | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Tests/XSLTNamespaceFixupTests.swift diff --git a/Tests/XSLTNamespaceFixupTests.swift b/Tests/XSLTNamespaceFixupTests.swift new file mode 100644 index 0000000..aada10c --- /dev/null +++ b/Tests/XSLTNamespaceFixupTests.swift @@ -0,0 +1,41 @@ +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(#""#) + == #""#) + } +}