diff --git a/README.md b/README.md index 491fcc4..2ef386f 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ flowchart TB PureXML is a working, dependency-free XML library today: parse, emit, validate, query, and stream documents on macOS, Linux, Windows, and WASM. The test suite -currently runs **828 tests in 131 suites** (`swift test`). +currently runs **830 tests in 132 suites** (`swift test`). ### Shipped (libxml2-aligned surface) diff --git a/Tests/StrictRecoveringDifferentialTests.swift b/Tests/StrictRecoveringDifferentialTests.swift new file mode 100644 index 0000000..453bc42 --- /dev/null +++ b/Tests/StrictRecoveringDifferentialTests.swift @@ -0,0 +1,61 @@ +@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)") + } + } +}