@testable import PureXML
import Testing
@Suite("XSLT strip-space / preserve-space")
struct XSLTWhitespaceTests {
private let xsl = "xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\""
private func transform(_ stylesheet: String, _ source: String) throws -> String {
try PureXML.XSLT.transform(stylesheet: stylesheet, source: source)
}
@Test("strip-space removes whitespace-only text nodes; a copy reflects it")
func test_stripSpace() throws {
let style = """
"""
let source = "\n \n \n"
// The indentation whitespace between elements is stripped.
#expect(try transform(style, source) == "")
}
@Test("Without strip-space the whitespace is preserved")
func test_noStrip() throws {
let style = """
"""
let source = "\n \n"
#expect(try transform(style, source).contains("\n "))
}
@Test("preserve-space overrides strip-space for a named element")
func test_preserveOverrides() throws {
let style = """
"""
// strip-space="*" strips 's whitespace, but preserves its own.
let stripped = try transform(style, "\n \n")
#expect(stripped == "")
let kept = try transform(style, "\n \n")
#expect(kept.contains("\n "))
}
@Test("xml:space=preserve on a source element keeps its whitespace despite strip-space")
func test_xmlSpacePreserve() throws {
let style = """
"""
let source = "\n \n"
#expect(try transform(style, source).contains("\n "))
}
}