import Testing
@testable import PureXML
/// `xsl:number level="any"` numbers a node by the count of matching nodes that
/// precede it (in document order, ancestors included) plus one. The walk over
/// preceding nodes now visits each preceding sibling's subtree directly instead
/// of rescanning the child list per sibling. These pin that the numbering is
/// unchanged: sequential in document order across nesting, counting only the
/// nodes the `count` pattern matches.
@Suite("xsl:number level=any")
struct XSLTNumberAnyTests {
private func numbers(_ source: String, count: String = "item") throws -> [String] {
let style = """
"""
let out = try PureXML.XSLT.transform(stylesheet: style, source: source)
// Extract the digits between ....
return out.components(separatedBy: "").dropFirst().map { String($0.prefix(while: { $0 != "<" })) }
}
@Test("items are numbered sequentially in document order across nesting")
func test_sequential() throws {
let source = " "
#expect(try numbers(source) == ["1", "2", "3", "4"])
}
@Test("only nodes the count pattern matches are counted")
func test_countPattern() throws {
// elements are interleaved but not counted; items still 1..3.
let source = " "
#expect(try numbers(source) == ["1", "2", "3"])
}
@Test("a single item is number one")
func test_single() throws {
#expect(try numbers(" ") == ["1"])
}
}