import Testing
@testable import PureXML
/// `xsl:number` level single and multiple rank a node among its parent's
/// matching children. That rank now comes from a per-parent-and-pattern cache
/// (built once) instead of rescanning the child list per numbered node. These
/// pin that the numbers are unchanged: the position among matching siblings for
/// the default and an explicit count, a partial-match count, and the
/// multiple-level path that numbers each matching ancestor.
@Suite("xsl:number level single and multiple")
struct XSLTNumberSingleTests {
private func transform(_ source: String, template: String) throws -> String {
let style = """
\(template)
"""
return try PureXML.XSLT.transform(stylesheet: style, source: source)
}
@Test("default and explicit count rank a node among its same-name siblings")
func test_single() throws {
let source = " "
let template = #""#
#expect(try transform(source, template: template).hasSuffix("123"))
let explicit = #""#
#expect(try transform(source, template: explicit).hasSuffix("123"))
}
@Test("a partial-match count numbers only the matching siblings")
func test_partialMatch() throws {
// The elements are interleaved but not counted, so the items
// keep ranks 1, 2, 3 among the item siblings.
let source = " "
let template = #""#
#expect(try transform(source, template: template).hasSuffix("123"))
}
@Test("multiple level numbers each matching ancestor")
func test_multiple() throws {
let source = ""
// The innermost elements: the two inside the first sec are 1.1 and
// 1.2; the last top-level sec is 2.
let template = #""#
let out = try transform(source, template: template)
#expect(out.hasSuffix("1.11.22"))
}
}