Pin the last untested-but-correct paths surfaced by the coverage audit: flow-style emission of double scalars, BatchReport.description across multiple sources, the unkeyed superDecoder reading successive indexes, the PreflightScanner scheme-colon exception that must not flag a missing mapping space, and the tagged stream-validation throwing overload that wraps failures in a document-indexed issue collection. Each assertion was measured against actual behavior before being pinned.
71 lines
3.0 KiB
Swift
71 lines
3.0 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("Additional Coverage")
|
|
struct AdditionalCoverageTests {
|
|
@Test("Flow style emits double scalars in sequences and mappings")
|
|
func test_flowEmitsDoubleScalars() {
|
|
let options = PureYAML.Emitting.Options(scalarStyle: .plainWhenSafe, collectionStyle: .flow)
|
|
#expect(PureYAML.dump(.sequence([.double(3.5), .int(2)]), options: options) == "[3.5, 2]\n")
|
|
#expect(
|
|
PureYAML.dump(.mapping(.init([.init(key: "k", value: .double(1.5))])), options: options)
|
|
== "{\"k\": 1.5}\n",
|
|
)
|
|
}
|
|
|
|
@Test("Batch report description concatenates diagnostics across every source")
|
|
func test_batchReportDescriptionConcatenatesAllSources() {
|
|
let report = PureYAML.validationReports([
|
|
.init(name: "a.yaml", yaml: "x: 1\nx: 2\n"),
|
|
.init(name: "b.yaml", yaml: "y: 1\ny: 2\n"),
|
|
])
|
|
#expect(report.description == """
|
|
a.yaml: document[0]: $.x: error: validation: Duplicate mapping key 'x'
|
|
b.yaml: document[0]: $.y: error: validation: Duplicate mapping key 'y'
|
|
""")
|
|
}
|
|
|
|
@Test("Unkeyed super decoders read successive indexes")
|
|
func test_unkeyedSuperDecoderReadsCurrentIndex() throws {
|
|
let decoded = try PureYAML.decode(SuperDecodedPair.self, from: .sequence([.string("one"), .string("two")]))
|
|
#expect(decoded.first == "one")
|
|
#expect(decoded.second == "two")
|
|
}
|
|
|
|
@Test("Preflight does not flag a scheme colon that has no mapping space")
|
|
func test_preflightAllowsSchemeColonWithoutSpace() {
|
|
#expect(PureYAML.diagnosticValidationReport("a://b\n", file: "f.yaml").isValid)
|
|
|
|
let flagged = PureYAML.diagnosticValidationReport("a:b\n", file: "f.yaml")
|
|
#expect(!flagged.isValid)
|
|
#expect(flagged.diagnostics.contains { $0.code == "missingMappingSpace" })
|
|
}
|
|
|
|
@Test("Tagged stream validation throws a document-indexed issue collection")
|
|
func test_taggedStreamValidationThrowsDocumentIndexedCollection() throws {
|
|
let documents = try PureYAML.parseTaggedStream("first: !!timestamp 2020\n---\nsecond: ok\n")
|
|
#expect(documents.map(\.index) == [0, 1])
|
|
do {
|
|
_ = try PureYAML.Tagged.Validator().validate(documents, strict: true)
|
|
Issue.record("expected a thrown issue collection")
|
|
} catch let collection as PureYAML.Stream.Issue.Collection {
|
|
#expect(collection.issues.count == 1)
|
|
#expect(collection.issues.first?.documentIndex == 0)
|
|
#expect(collection.issues.first?.issue.reason == "Unsupported built-in tag 'tag:yaml.org,2002:timestamp'")
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct SuperDecodedPair: Decodable {
|
|
var first: String
|
|
var second: String
|
|
|
|
init(from decoder: any Decoder) throws {
|
|
var container = try decoder.unkeyedContainer()
|
|
let firstDecoder = try container.superDecoder()
|
|
let secondDecoder = try container.superDecoder()
|
|
first = try String(from: firstDecoder)
|
|
second = try String(from: secondDecoder)
|
|
}
|
|
}
|