test(conformance): add an XSLT 1.0 transformation corpus
Grow the Tier-2 conformance corpus with 10 XSLT cases (value-of, for-each, if, choose/otherwise, sort, variable, format-number, concat, apply-templates, and a named template with a parameter) transformed through the public API and checked through the validation-driven harness against the spec output. Part of #105 (Tier 2)
This commit is contained in:
parent
62fea5c26c
commit
821cc2cf88
@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Added
|
||||
|
||||
- Conformance corpus harness (#105, Tier 2): the start of conformance-suite checking, expressed through the validation framework (the OpenAPIKit idiom). A `PureXML.Validation.ConformanceCase` is a `Validatable` named expectation (actual vs spec-authoritative expected output), and `Conformance.matchesExpected` is a `Validation<ConformanceCase, Void>` rule that emits one located `ValidationError` per diverging case, so a whole suite reports every failure at once with the case name as its coding path. Seeded with a Canonical XML 1.0 corpus (attribute ordering, empty-element expansion, comment removal, CDATA-to-escaped-text, processing instructions, namespace rendering) an XPath 1.0 core-function corpus, and an XSD datatype/facet corpus (length, range, pattern, enumeration, lexical space), and a RELAX NG pattern corpus (text, optional, repetition, choice, ordered group, attribute, interleave, empty). Growing the corpora against the official W3C/OASIS suites is the ongoing Tier-2 work.
|
||||
- Conformance corpus harness (#105, Tier 2): the start of conformance-suite checking, expressed through the validation framework (the OpenAPIKit idiom). A `PureXML.Validation.ConformanceCase` is a `Validatable` named expectation (actual vs spec-authoritative expected output), and `Conformance.matchesExpected` is a `Validation<ConformanceCase, Void>` rule that emits one located `ValidationError` per diverging case, so a whole suite reports every failure at once with the case name as its coding path. Seeded with a Canonical XML 1.0 corpus (attribute ordering, empty-element expansion, comment removal, CDATA-to-escaped-text, processing instructions, namespace rendering) an XPath 1.0 core-function corpus, and an XSD datatype/facet corpus (length, range, pattern, enumeration, lexical space), a RELAX NG pattern corpus (text, optional, repetition, choice, ordered group, attribute, interleave, empty), and an XSLT 1.0 transformation corpus (value-of, for-each, if, choose, sort, variable, format-number, apply-templates, call-template). Growing the corpora against the official W3C/OASIS suites is the ongoing Tier-2 work.
|
||||
- EXSLT extension functions (#105, Tier 3): the `common`, `math`, and `sets` EXSLT modules, dispatched by resolving a function's prefix to its namespace (so any prefix bound to an EXSLT namespace works). `math:min`, `math:max`, `math:highest`, `math:lowest`, `math:abs`, `math:sqrt` (with the EXSLT NaN rule for non-numeric nodes); `set:distinct`, `set:difference`, `set:intersection`, `set:has-same-node`, `set:leading`, `set:trailing` (by node identity and document order); `exsl:object-type`. `math:power` and the other transcendentals are omitted because they need a C math library, which the pure-Swift, Foundation-free target excludes; `exsl:node-set` awaits result-tree-fragment support.
|
||||
- Canonical XML 1.1 (#105, Tier 3): a `Canonical.Options.canonical11` preset and a `mergeInheritedBase` option. When canonicalizing a document subset, the `xml:base` values of the apex's omitted ancestors are merged into the apex by RFC 3986 reference resolution (vs. 1.0's nearest-ancestor rule), the apex's own relative `xml:base` is resolved against that chain, and `xml:id` is no longer inherited; `xml:lang` and `xml:space` still inherit the nearest. A self-contained RFC 3986 resolver (scheme/authority/path parsing, path merging, dot-segment removal) backs the merge.
|
||||
- Single-byte legacy encodings (#97): the byte decoder gains a table-based single-byte path and the full set of single-byte legacy encodings, selected by the XML declaration's `encoding` name for both the whole-buffer and streaming decoders: the complete ISO-8859 family (parts 2 through 16), Windows-1250/1251/1253/1254/1255/1256/1257/1258, and KOI8-R/U. Most are vendored verbatim from the authoritative `unicode.org` mapping files; ISO-8859-5/9/15 are derived exactly; Windows-1254 composes from Windows-1252. Multi-byte CJK encodings (#99) are tracked separately.
|
||||
|
||||
@ -99,7 +99,7 @@ flowchart TB
|
||||
|
||||
PureXML is a working, dependency-free XML library today: parse, emit, validate,
|
||||
query, and stream documents on macOS, Linux, Windows, and WASM. The test suite
|
||||
currently runs **812 tests in 125 suites** (`swift test`).
|
||||
currently runs **813 tests in 125 suites** (`swift test`).
|
||||
|
||||
### Shipped (libxml2-aligned surface)
|
||||
|
||||
|
||||
@ -139,6 +139,67 @@ struct ConformanceCorpusTests {
|
||||
}
|
||||
}
|
||||
|
||||
private struct XSLTSpec {
|
||||
let name: String
|
||||
let stylesheet: String
|
||||
let source: String
|
||||
let expected: String
|
||||
}
|
||||
|
||||
/// A text-output stylesheet wrapping a single `match="/"` template body, so
|
||||
/// the result is exactly the body's output with no stray whitespace.
|
||||
private func textSheet(_ body: String) -> String {
|
||||
"<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"
|
||||
+ "<xsl:output method=\"text\"/><xsl:template match=\"/\">\(body)</xsl:template></xsl:stylesheet>"
|
||||
}
|
||||
|
||||
/// XSLT 1.0 transformation conformance: a stylesheet over a source, with the
|
||||
/// text result checked against what the spec prescribes.
|
||||
private func xsltCorpus() throws -> [PureXML.Validation.ConformanceCase] {
|
||||
let multiTemplate = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"
|
||||
+ "<xsl:output method=\"text\"/>"
|
||||
+ "<xsl:template match=\"/\"><xsl:apply-templates select=\"/r/i\"/></xsl:template>"
|
||||
+ "<xsl:template match=\"i\">[<xsl:value-of select=\".\"/>]</xsl:template></xsl:stylesheet>"
|
||||
let calling = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"
|
||||
+ "<xsl:output method=\"text\"/>"
|
||||
+ "<xsl:template match=\"/\"><xsl:call-template name=\"greet\"><xsl:with-param name=\"who\" select=\"'world'\"/></xsl:call-template></xsl:template>"
|
||||
+ "<xsl:template name=\"greet\"><xsl:param name=\"who\"/>hi <xsl:value-of select=\"$who\"/></xsl:template></xsl:stylesheet>"
|
||||
let specs = [
|
||||
XSLTSpec(name: "value-of", stylesheet: textSheet("<xsl:value-of select=\"/r/x\"/>"), source: "<r><x>hi</x></r>", expected: "hi"),
|
||||
XSLTSpec(
|
||||
name: "for-each",
|
||||
stylesheet: textSheet("<xsl:for-each select=\"/r/i\"><xsl:value-of select=\".\"/></xsl:for-each>"),
|
||||
source: "<r><i>a</i><i>b</i></r>",
|
||||
expected: "ab",
|
||||
),
|
||||
XSLTSpec(name: "if", stylesheet: textSheet("<xsl:if test=\"/r/x\">yes</xsl:if>"), source: "<r><x>1</x></r>", expected: "yes"),
|
||||
XSLTSpec(
|
||||
name: "choose-otherwise",
|
||||
stylesheet: textSheet("<xsl:choose><xsl:when test=\"1=2\">no</xsl:when><xsl:otherwise>else</xsl:otherwise></xsl:choose>"),
|
||||
source: "<x/>",
|
||||
expected: "else",
|
||||
),
|
||||
XSLTSpec(
|
||||
name: "sort",
|
||||
stylesheet: textSheet("<xsl:for-each select=\"/r/i\"><xsl:sort select=\".\"/><xsl:value-of select=\".\"/></xsl:for-each>"),
|
||||
source: "<r><i>3</i><i>1</i><i>2</i></r>",
|
||||
expected: "123",
|
||||
),
|
||||
XSLTSpec(name: "variable", stylesheet: textSheet("<xsl:variable name=\"v\" select=\"'x'\"/><xsl:value-of select=\"$v\"/>"), source: "<x/>", expected: "x"),
|
||||
XSLTSpec(name: "format-number", stylesheet: textSheet("<xsl:value-of select=\"format-number(1234.5,'#,##0.00')\"/>"), source: "<x/>", expected: "1,234.50"),
|
||||
XSLTSpec(name: "concat", stylesheet: textSheet("<xsl:value-of select=\"concat(/r/a,'-',/r/b)\"/>"), source: "<r><a>x</a><b>y</b></r>", expected: "x-y"),
|
||||
XSLTSpec(name: "apply-templates", stylesheet: multiTemplate, source: "<r><i>a</i><i>b</i></r>", expected: "[a][b]"),
|
||||
XSLTSpec(name: "call-template-param", stylesheet: calling, source: "<x/>", expected: "hi world"),
|
||||
]
|
||||
return try specs.map { spec in
|
||||
try PureXML.Validation.ConformanceCase(
|
||||
name: spec.name,
|
||||
actual: PureXML.XSLT.transform(stylesheet: spec.stylesheet, source: spec.source),
|
||||
expected: spec.expected,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test("The C14N conformance corpus passes with no located failures")
|
||||
func test_corpusConforms() throws {
|
||||
let failures = try PureXML.Validation.Conformance.failures(in: canonicalCorpus())
|
||||
@ -163,6 +224,12 @@ struct ConformanceCorpusTests {
|
||||
#expect(failures.isEmpty, "\(failures.map(\.reason))")
|
||||
}
|
||||
|
||||
@Test("The XSLT transformation conformance corpus passes with no located failures")
|
||||
func test_xsltCorpusConforms() throws {
|
||||
let failures = try PureXML.Validation.Conformance.failures(in: xsltCorpus())
|
||||
#expect(failures.isEmpty, "\(failures.map(\.reason))")
|
||||
}
|
||||
|
||||
@Test("A divergent case is reported as a located conformance failure")
|
||||
func test_divergenceReported() {
|
||||
let bad = PureXML.Validation.ConformanceCase(name: "wrong", actual: "<a></a>", expected: "<b></b>")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user