@testable import PureXML import Testing /// Locks the strict and recovering parse paths together: the recovery code /// synthesizes events through machinery the strict path never exercises, so /// every well-formed document must produce the identical tree under both modes /// with no diagnostics. (#116: a recovery-synthesis bug is invisible to /// strict-path tests without this differential.) @Suite("Strict vs recovering parser differential") struct StrictRecoveringDifferentialTests { /// Well-formed documents spanning the constructs both paths must agree on, /// including the conformance-corpus inputs (kept in sync by inclusion). private let corpus = [ // The C14N conformance-corpus inputs. "", "", "x", "&]]>", "", "", // Structure: nesting, siblings, mixed content, whitespace. "deep", "123", "

text bold tail

", "\n \n \n", // Attributes: quoting, escapes, namespaces on attributes. "", "", "", // Entities and character references. "&<>"'", "AB", // Prolog and misc constructs. "", "", "", " kept ", // Default and redeclared namespaces. "", ] @Test("Well-formed documents parse identically in strict and recovering modes") func test_treesAgree() throws { for document in corpus { let strict = try PureXML.parse(document) let recovered = PureXML.read(document) #expect(recovered.diagnostics.isEmpty, "unexpected diagnostics for: \(document) -> \(recovered.diagnostics)") #expect(recovered.node == strict, "trees diverged for: \(document)") } } @Test("The recovering editor tree projects to the same node as strict parse") func test_readTreeAgrees() throws { for document in corpus { let strict = try PureXML.parse(document) let (tree, diagnostics) = PureXML.readTree(document) #expect(diagnostics.isEmpty, "unexpected diagnostics for: \(document)") #expect(tree.node == strict, "readTree diverged for: \(document)") } } }