2023-10-07 10:52:11 +01:00
|
|
|
package validate
|
|
|
|
|
|
2023-11-19 20:27:33 +00:00
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
2023-10-07 10:52:11 +01:00
|
|
|
|
|
|
|
|
func TestChars(t *testing.T) {
|
|
|
|
|
type TestCase struct {
|
|
|
|
|
Input string
|
2023-10-08 15:21:02 +01:00
|
|
|
C string
|
|
|
|
|
Err error
|
2023-10-07 10:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hexRange := "0123456789abcdef"
|
|
|
|
|
|
|
|
|
|
testCases := []TestCase{
|
2023-10-08 15:21:02 +01:00
|
|
|
{Input: "abcd1234", C: hexRange},
|
|
|
|
|
{Input: "abcd 1234", C: hexRange, Err: ErrDisallowedChars},
|
2023-10-07 10:52:11 +01:00
|
|
|
}
|
|
|
|
|
|
2023-10-08 16:20:21 +01:00
|
|
|
for n, tc := range testCases {
|
|
|
|
|
t.Logf("(%d) Testing %q against %q", n, tc.Input, tc.C)
|
2023-10-07 10:52:11 +01:00
|
|
|
|
|
|
|
|
f := Chars(tc.C)
|
|
|
|
|
err := f(tc.Input)
|
|
|
|
|
|
2023-11-19 20:27:33 +00:00
|
|
|
if !errors.Is(err, tc.Err) {
|
2023-10-08 15:21:02 +01:00
|
|
|
t.Errorf("Expected error %v, got %v", tc.Err, err)
|
2023-10-07 10:52:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|