From d15faed122b50f49a44b3750328ccacfa5494b31 Mon Sep 17 00:00:00 2001 From: Mihaela Mihaljevic Date: Mon, 22 Jun 2026 16:46:27 +0200 Subject: [PATCH] test(relaxng): cover include and externalRef resolution Exercise RelaxNGParserIncludes (plain include, define override, externalRef) through the schema loader; raises its line coverage from 24% to 81%. --- Tests/RelaxNGIncludeTests.swift | 63 +++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Tests/RelaxNGIncludeTests.swift diff --git a/Tests/RelaxNGIncludeTests.swift b/Tests/RelaxNGIncludeTests.swift new file mode 100644 index 0000000..70ab140 --- /dev/null +++ b/Tests/RelaxNGIncludeTests.swift @@ -0,0 +1,63 @@ +import Testing +@testable import PureXML + +/// RELAX NG `include` and `externalRef` resolution (Sources/Schema/RelaxNGParserIncludes.swift), +/// which a loader supplies. This path was under-covered; these exercise a plain +/// include, an include with a `define` override, and an externalRef. +@Suite("RELAX NG include / externalRef") +struct RelaxNGIncludeTests { + private let namespace = "xmlns='http://relaxng.org/ns/structure/1.0'" + + @Test("a plain include merges the loaded grammar's defines") + func test_plainInclude() throws { + let main = """ + + + + + """ + let lib = """ + + + + """ + let schema = try PureXML.Schema.RelaxNG(main, schemaLoader: { $0 == "lib.rng" ? lib : nil }) + #expect(try schema.validate("hi")) + #expect(try !schema.validate("")) + } + + @Test("an include override replaces the included define") + func test_includeOverride() throws { + // The includer redefines `body`; the loaded grammar's `body` (which allows + // text) is dropped in favor of the override (which allows only empty content). + let main = """ + + + + + + + """ + let lib = """ + + + + """ + let schema = try PureXML.Schema.RelaxNG(main, schemaLoader: { $0 == "lib.rng" ? lib : nil }) + #expect(try schema.validate("")) // override: empty content allowed + #expect(try !schema.validate("text")) // override removed the text pattern + } + + @Test("an externalRef pulls a pattern from another document") + func test_externalRef() throws { + let main = """ + + + + """ + let frag = "" + let schema = try PureXML.Schema.RelaxNG(main, schemaLoader: { $0 == "frag.rng" ? frag : nil }) + #expect(try schema.validate("x")) + #expect(try !schema.validate("")) + } +}