import Testing @testable import PureXML @Suite("Canonical XML: node-set (position-based) selection") struct CanonicalSelectionTests { private func select( _ xml: String, _ options: PureXML.Canonical.Options = .inclusive, where predicate: @escaping (PureXML.Model.TreeNode) -> Bool, ) throws -> String { let document = try PureXML.parseTree(xml) return PureXML.Canonical.Canonicalizer(options: options).canonicalize(document, including: predicate) } @Test("An excluded element and its subtree are dropped") func test_excludeSubtree() throws { let output = try select("") { $0.name?.localName != "b" } #expect(output == "") } @Test("An excluded middle element is omitted but its selected child is kept") func test_omitMiddleKeepChild() throws { let output = try select("") { $0.name?.localName != "skip" } #expect(output == "") } @Test("A selected node exposed by omitted ancestors re-declares its namespace context") func test_exposedReDeclaresNamespace() throws { let output = try select("") { $0.name?.localName == "keep" } #expect(output == "") } @Test("Selecting every node reproduces the ordinary canonical form") func test_selectAllMatchesWholeTree() throws { let xml = "hi" let selected = try select(xml) { _ in true } let whole = try PureXML.Canonical.canonicalize(PureXML.parse(xml)) #expect(selected == whole) #expect(selected == "hi") } }