standardise all validate tests

This commit is contained in:
Aneurin Barker Snook
2023-10-08 15:21:02 +01:00
parent c74486d122
commit 7cb1900ec1
6 changed files with 65 additions and 113 deletions
+7 -13
View File
@@ -4,32 +4,26 @@ import "testing"
func TestChars(t *testing.T) {
type TestCase struct {
C string
Input string
Err bool
C string
Err error
}
hexRange := "0123456789abcdef"
testCases := []TestCase{
{C: hexRange, Input: "abcd1234"},
{C: hexRange, Input: "abcd 1234", Err: true},
{Input: "abcd1234", C: hexRange},
{Input: "abcd 1234", C: hexRange, Err: ErrDisallowedChars},
}
for _, tc := range testCases {
t.Logf("%q contains only allowed characters %q", tc.Input, tc.C)
t.Logf("Testing %q against %q", tc.Input, tc.C)
f := Chars(tc.C)
err := f(tc.Input)
if tc.Err {
if err == nil {
t.Error("Expected error; got nil")
}
} else {
if err != nil {
t.Errorf("Expected nil; got %s", err)
}
if err != tc.Err {
t.Errorf("Expected error %v, got %v", tc.Err, err)
}
}
}