import Testing
@testable import PureXML
@Suite("XSLT key() with the context node and node-set values")
struct XSLTKeyNodeSetTests {
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 let source = """
- 1
- 2
- 3
ab
"""
@Test("key('k', .) uses the context node's string value")
func test_contextNode() throws {
let style = """
,
"""
// a -> 2 items, b -> 1 item.
#expect(try transform(style, source) == "2,1,")
}
@Test("key('k', node-set) unions the matches for every node's value")
func test_nodeSetValue() throws {
let style = """
"""
// a -> 2, b -> 1, unioned and de-duplicated -> 3.
#expect(try transform(style, source) == "3")
}
@Test("key with a string value still works")
func test_stringValue() throws {
let style = """
"""
#expect(try transform(style, source) == "2")
}
@Test("xsl:key with a union match pattern indexes every branch")
func test_unionMatchPattern() throws {
// match="a | b" indexes both a and b anywhere; the // must distribute over
// the union (previously only the first branch was matched anywhere, so a
// nested b was missed). Apache Xalan idkey45-48.
let style = """
,
"""
let source = ""
#expect(try transform(style, source) == "a,b,")
}
}