Introduce the core of the validation-rules idiom: a Check<Subject> with a positive description, a when predicate, and a Bool or multi-error check that fires only on values of its Subject type wherever they occur. AnyCheck erases the subject and dispatches by runtime type, guarding an optional or a wrong type from matching. The validator gains a checks list, a validating(_:) overload, and a traversal that offers each node the values it may specialise on. BuiltinCheck.mappingKeysAreUnique is the type-directed counterpart of the legacy rule. The machinery has its own negative tests (wrong type, optional, false predicate yield nothing; same type twice yields two errors) and the builtin ships a failing and a near-miss test. The coverage gate catches the five new public types, which are classified as validation machinery. The default validator is unchanged, so this is additive; retiring the legacy Rule, moving the default onto the check, the combinator algebra, the error rendering, and de-duplicating the Tagged validator are the remaining steps.
20 lines
660 B
Swift
20 lines
660 B
Swift
public extension PureYAML.Validation {
|
|
/// The read-only bundle a type-directed check receives: the whole `document` (for cross-cutting
|
|
/// checks), the current `subject` of the check's type, and the `path` to where it sits.
|
|
struct SubjectContext<Subject: Validatable>: Sendable {
|
|
public var document: PureYAML.Model.Value
|
|
public var subject: Subject
|
|
public var path: Path
|
|
|
|
public init(
|
|
document: PureYAML.Model.Value,
|
|
subject: Subject,
|
|
path: Path,
|
|
) {
|
|
self.document = document
|
|
self.subject = subject
|
|
self.path = path
|
|
}
|
|
}
|
|
}
|