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.
11 lines
548 B
Swift
11 lines
548 B
Swift
public extension PureYAML.Validation {
|
|
/// Marker for a value a type-directed validation can be applied to. A `Check<Subject>` fires on
|
|
/// `Subject` values wherever they appear in the traversed tree; this protocol constrains the
|
|
/// subjects so the erased dispatch can filter by runtime type.
|
|
protocol Validatable: Sendable {}
|
|
}
|
|
|
|
extension PureYAML.Model.Value: PureYAML.Validation.Validatable {}
|
|
extension PureYAML.Model.Mapping: PureYAML.Validation.Validatable {}
|
|
extension PureYAML.Model.Key: PureYAML.Validation.Validatable {}
|