Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
Replace CountValidator messages as suggested in review
Browse files Browse the repository at this point in the history
  • Loading branch information
baarde committed Oct 25, 2018
1 parent c5a34b3 commit 870fe99
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Sources/Validation/Validators/CountValidator.swift
Expand Up @@ -68,13 +68,13 @@ fileprivate struct CountValidator<T>: ValidatorType where T: Collection {
func validate(_ data: T) throws {
if let min = self.min {
guard data.count >= min else {
throw BasicValidationError("is shorter than \(elementDescription(count: min))")
throw BasicValidationError("is less than required minimum of \(elementDescription(count: min))")
}
}

if let max = self.max {
guard data.count <= max else {
throw BasicValidationError("is longer than \(elementDescription(count: max))")
throw BasicValidationError("is greater than required maximum of \(elementDescription(count: max))")
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/ValidationTests/ValidationTests.swift
Expand Up @@ -72,10 +72,10 @@ class ValidationTests: XCTestCase {
try validator.validate("123")
try validator.validate("123456")
XCTAssertThrowsError(try validator.validate("")) { error in
XCTAssertEqual((error as? ValidationError)?.reason, "data is shorter than 1 character")
XCTAssertEqual((error as? ValidationError)?.reason, "data is less than required minimum of 1 character")
}
XCTAssertThrowsError(try validator.validate("1234567")) { error in
XCTAssertEqual((error as? ValidationError)?.reason, "data is longer than 6 characters")
XCTAssertEqual((error as? ValidationError)?.reason, "data is greater than required maximum of 6 characters")
}
}

Expand All @@ -85,10 +85,10 @@ class ValidationTests: XCTestCase {
try validator.validate([1, 2, 3])
try validator.validate([1, 2, 3, 4, 5, 6])
XCTAssertThrowsError(try validator.validate([])) { error in
XCTAssertEqual((error as? ValidationError)?.reason, "data is shorter than 1 item")
XCTAssertEqual((error as? ValidationError)?.reason, "data is less than required minimum of 1 item")
}
XCTAssertThrowsError(try validator.validate([1, 2, 3, 4, 5, 6, 7])) { error in
XCTAssertEqual((error as? ValidationError)?.reason, "data is longer than 6 items")
XCTAssertEqual((error as? ValidationError)?.reason, "data is greater than required maximum of 6 items")
}
}

Expand Down

0 comments on commit 870fe99

Please sign in to comment.