Files
validate/length_test.go
T

66 lines
1.1 KiB
Go
Raw Normal View History

package validate
import "testing"
func TestMaxLength(t *testing.T) {
type TestCase struct {
L int
Input string
Err bool
}
testCases := []TestCase{
{L: 8, Input: "abcd"},
{L: 8, Input: "abcdefgh"},
{L: 8, Input: "abcd efg"},
{L: 8, Input: "abcdefghi", Err: true},
}
2023-10-07 10:44:47 +01:00
for _, tc := range testCases {
t.Logf("Max length %d for %q", tc.L, tc.Input)
2023-10-07 10:44:47 +01:00
f := MaxLength(tc.L)
err := f(tc.Input)
if tc.Err {
if err == nil {
t.Error("Expected an error; got nil")
}
} else {
if err != nil {
t.Errorf("Expected nil; got %s", err)
}
}
}
}
func TestMinLength(t *testing.T) {
type TestCase struct {
L int
Input string
Err bool
}
testCases := []TestCase{
{L: 8, Input: "abcd", Err: true},
{L: 8, Input: "abcdefgh"},
{L: 8, Input: "abcd efg"},
{L: 8, Input: "abcdefghi"},
}
2023-10-07 10:44:47 +01:00
for _, tc := range testCases {
t.Logf("Min length %d for %q", tc.L, tc.Input)
2023-10-07 10:44:47 +01:00
f := MinLength(tc.L)
err := f(tc.Input)
if tc.Err {
if err == nil {
t.Error("Expected an error; got nil")
}
} else {
if err != nil {
t.Errorf("Expected nil; got %s", err)
}
}
}
}