update all validation tests

This commit is contained in:
Aneurin Barker Snook
2023-11-19 20:42:48 +00:00
parent db902e3c1c
commit 40482060ac
10 changed files with 24 additions and 32 deletions
+4 -8
View File
@@ -1,20 +1,16 @@
package validate
import (
"errors"
)
// Validation error.
var (
ErrTooFewItems = errors.New("too few items")
ErrTooManyItems = errors.New("too many items")
ErrMustHaveMoreItems = NewError("must have at least %d items")
ErrMustHaveFewerItems = NewError("must have no more than %d items")
)
// MaxSize validates the length of a slice as being less than or equal to a given maximum.
func MaxSize[T any](l int) func([]T) error {
return func(value []T) error {
if len(value) > l {
return ErrTooManyItems
return ErrMustHaveFewerItems
}
return nil
}
@@ -24,7 +20,7 @@ func MaxSize[T any](l int) func([]T) error {
func MinSize[T any](l int) func([]T) error {
return func(value []T) error {
if len(value) < l {
return ErrTooFewItems
return ErrMustHaveMoreItems
}
return nil
}