The validation module already implemented the composable-rule idiom under its own names (Check/Issue/SubjectContext) and a value-type Validator with duplicated traversal machinery per layer. Renamed the core types to the canonical names (Validation/ValidationError/ValidationErrorCollection/ ValidationContext/BuiltinValidation/AnyValidation), converted Validator to a reference-type class with the two-tier default-rule split, and genericized it over both Subject and Document via a new Traversable protocol so the model and tagged layers share one walk engine instead of two copies. Wired the JSON-representability rule set into the same shape and closed the two missing pieces (unwrap combinator, JSON coverage/config-pin tests).
37 lines
1.4 KiB
Swift
37 lines
1.4 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("Arbitrary Any API Decision")
|
|
struct ArbitraryAnyDecisionTests {
|
|
@Test("Model values preserve diagnostics that dictionary-shaped projections erase")
|
|
func test_modelValuesPreserveDiagnosticsThatDictionaryShapedProjectionsErase() {
|
|
let value = PureYAML.Model.Value.mapping(.init([
|
|
.init(key: "title", value: .string("First")),
|
|
.init(key: "title", value: .string("Second")),
|
|
.init(key: "slug", value: .string("example")),
|
|
]))
|
|
|
|
guard case let .mapping(mapping) = value else {
|
|
recordIssue("expected mapping fixture")
|
|
return
|
|
}
|
|
|
|
let projectedDictionary = Dictionary(
|
|
mapping.pairs.map { ($0.key, $0.value) },
|
|
uniquingKeysWith: { _, second in second },
|
|
)
|
|
let validationResult = PureYAML.Validation.Validator<PureYAML.Model.Value, PureYAML.Model.Value>().collect(value)
|
|
|
|
#expect(mapping.pairs.map(\.key) == ["title", "title", "slug"])
|
|
#expect(projectedDictionary.keys.sorted() == ["slug", "title"])
|
|
#expect(projectedDictionary["title"] == .string("Second"))
|
|
#expect(validationResult.values == [
|
|
.init(
|
|
severity: .error,
|
|
reason: "Duplicate mapping key 'title'",
|
|
path: .init([.key("title")]),
|
|
),
|
|
])
|
|
}
|
|
}
|