import Testing
@testable import PureXML
@Suite("XSLT xsl:output cdata-section-elements")
struct XSLTCDATASectionTests {
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)
}
private func style(_ cdataElements: String, _ body: String) -> String {
"""
\(body)
"""
}
@Test("A named element's text is emitted as a CDATA section")
func test_wrapped() throws {
let out = try transform(style("script", ""), "")
#expect(out == "")
}
@Test("An element not named keeps escaped text")
func test_notNamed() throws {
let out = try transform(style("script", "a < b"), "")
#expect(out == "a < b")
}
@Test("Only the named element's own text is wrapped, not nested elements")
func test_nestedUnaffected() throws {
let out = try transform(style("outer", "xy < z"), "")
#expect(out == "y < z")
}
@Test("Multiple element names can be listed")
func test_multiple() throws {
let out = try transform(style("a b", "1 & 23 & 4"), "")
#expect(out == "")
}
}