import Testing
@testable import PureXML
@Suite("XSLT xsl:output doctype-public / doctype-system")
struct XSLTDoctypeOutputTests {
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("doctype-system emits a SYSTEM doctype before the root")
func test_systemOnly() throws {
let style = """
"""
#expect(try transform(style, "") == "\n")
}
@Test("the html method names the doctype HTML regardless of the document element")
func test_publicAndSystem() throws {
// XSLT 1.0 16.2: the html output method's doctype name is HTML, not the
// document element name (here `root`), unlike the xml method (Apache
// Xalan output40, output48, output60).
let style = """
"""
let out = try transform(style, "")
#expect(out.hasPrefix("\n"))
#expect(out.contains(""))
}
@Test("the xml method still uses the document element name for the doctype")
func test_xmlMethodUsesElementName() throws {
let style = """
"""
#expect(try transform(style, "") == "\n")
}
@Test("the html method emits no doctype when the result has no element")
func test_htmlNoElementNoDoctype() throws {
// A doctype precedes the first element (16.2); a text-only result has
// none, so even the html method with doctype-public emits nothing.
let style = """
just text
"""
#expect(try transform(style, "") == "just text")
}
@Test("Without doctype-system no doctype is emitted")
func test_none() throws {
let style = """
"""
#expect(try transform(style, "") == "")
}
}