PureXML/Tests/CoverageGateValueTypeTests.swift
Mihaela Mihaljevic 3cf44cccb9 test(ci): add an opt-in coverage gate; close the 0% value types it surfaces
The coverage analysis noted there is no mechanism that measures test completeness,
so a source file silently sitting at 0% (untested or dead) is invisible.

Add scripts/check-coverage.sh: it runs the instrumented suite, prints overall
line/region/function coverage and the lowest-covered files, and FAILS if any source
file is at 0% line coverage (the exact signal that found the earlier gaps). It is
opt-in (instrumented build + llvm-cov are slow and macOS-only) and skips cleanly
where xcrun is unavailable; an optional COVERAGE_REGION_FLOOR enforces a floor.

Running it immediately surfaced two more 0% value types, now closed by
CoverageGateValueTypeTests: the HTML tokenizer's `Token` (a custom Equatable) and
the public `Stream.Document` (built by API consumers, never internally). Overall
line coverage is now 92.66% with no source file at 0%, so the gate passes.

Tooling + tests only; +2 tests; full suite green (1570).
2026-06-22 16:38:30 +02:00

41 lines
2.2 KiB
Swift

import Testing
@testable import PureXML
/// Standing coverage for two value types the coverage gate (scripts/check-coverage.sh)
/// flagged at 0%: the HTML tokenizer's `Token` (a custom Equatable) and the public
/// `Stream.Document` (constructed by API consumers, never internally). Both are small
/// but their equality/accessors had no test exercising them.
@Suite("Value-type coverage (HTML Token, Stream.Document)")
struct CoverageGateValueTypeTests {
private typealias Token = PureXML.HTML.Token
@Test("HTML Token equality compares names, attributes, self-closing, and kind")
func test_htmlTokenEquality() {
#expect(Token.startTag(name: "a", attributes: [("href", "x")], selfClosing: false)
== Token.startTag(name: "a", attributes: [("href", "x")], selfClosing: false))
// A differing attribute value, attribute name, or self-closing flag is unequal.
#expect(Token.startTag(name: "a", attributes: [("id", "1")], selfClosing: false)
!= Token.startTag(name: "a", attributes: [("id", "2")], selfClosing: false))
#expect(Token.startTag(name: "a", attributes: [("id", "1")], selfClosing: false)
!= Token.startTag(name: "a", attributes: [("class", "1")], selfClosing: false))
#expect(Token.startTag(name: "a", attributes: [], selfClosing: true)
!= Token.startTag(name: "a", attributes: [], selfClosing: false))
#expect(Token.endTag(name: "p") == Token.endTag(name: "p"))
#expect(Token.text("x") == Token.text("x"))
#expect(Token.comment("c") == Token.comment("c"))
#expect(Token.doctype("html") == Token.doctype("html"))
// Different kinds with the same payload are unequal (the default branch).
#expect(Token.text("x") != Token.comment("x"))
}
@Test("Stream.Document carries its index and node with value equality")
func test_streamDocument() throws {
let node = try PureXML.parse("<a/>")
let doc = PureXML.Stream.Document(index: 2, node: node)
#expect(doc.index == 2)
#expect(doc.node == node)
#expect(doc == PureXML.Stream.Document(index: 2, node: node))
#expect(doc != PureXML.Stream.Document(index: 3, node: node))
}
}