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).
40 lines
1.8 KiB
Swift
40 lines
1.8 KiB
Swift
@testable import PureYAML
|
|
import Testing
|
|
|
|
@Suite("Validator configuration")
|
|
struct ValidationConfigurationTests {
|
|
private var duplicateKeys: PureYAML.Model.Value {
|
|
.mapping(.init([
|
|
.init(key: "a", value: .int(1)),
|
|
.init(key: "a", value: .int(2)),
|
|
]))
|
|
}
|
|
|
|
@Test("The blank validator has no rules; the default set is pinned by description")
|
|
func test_configurationDescriptionsArePinned() {
|
|
#expect(PureYAML.Validation.Validator<PureYAML.Model.Value, PureYAML.Model.Value>.blank.validationDescriptions == [])
|
|
#expect(PureYAML.Validation.Validator<PureYAML.Model.Value, PureYAML.Model.Value>().validationDescriptions == ["Mapping keys are unique"])
|
|
}
|
|
|
|
@Test("Default rule descriptions are unique, the identity withoutValidating removes by")
|
|
func test_defaultDescriptionsAreUnique() {
|
|
let descriptions = PureYAML.Validation.Validator<PureYAML.Model.Value, PureYAML.Model.Value>().validationDescriptions
|
|
#expect(Set(descriptions).count == descriptions.count)
|
|
}
|
|
|
|
@Test("withoutValidating removes a rule by its description")
|
|
func test_withoutValidatingRemovesByDescription() throws {
|
|
let validator = PureYAML.Validation.Validator<PureYAML.Model.Value, PureYAML.Model.Value>().withoutValidating("Mapping keys are unique")
|
|
#expect(validator.validationDescriptions == [])
|
|
// With the rule removed, a document with duplicate keys validates clean.
|
|
_ = try validator.validate(duplicateKeys)
|
|
}
|
|
|
|
@Test("The default validator still catches what its removable rule guards")
|
|
func test_defaultStillValidates() {
|
|
#expect(throws: PureYAML.Validation.ValidationErrorCollection.self) {
|
|
try PureYAML.Validation.Validator<PureYAML.Model.Value, PureYAML.Model.Value>().validate(duplicateKeys)
|
|
}
|
|
}
|
|
}
|