make tests slightly easier to write
This commit is contained in:
+5
-5
@@ -13,15 +13,15 @@ func TestEmail(t *testing.T) {
|
|||||||
{Input: "testexample.com", Err: true},
|
{Input: "testexample.com", Err: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, tc := range testCases {
|
||||||
err := Email(testCase.Input)
|
err := Email(tc.Input)
|
||||||
if testCase.Err {
|
if tc.Err {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected %q to be an invalid email; got nil", testCase.Input)
|
t.Errorf("Expected %q to be an invalid email; got nil", tc.Input)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected %q to be a valid email; got %s", testCase.Input, err)
|
t.Errorf("Expected %q to be a valid email; got %s", tc.Input, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-10
@@ -16,12 +16,12 @@ func TestMaxLength(t *testing.T) {
|
|||||||
{L: 8, Input: "abcdefghi", Err: true},
|
{L: 8, Input: "abcdefghi", Err: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Logf("Max length %d for %q", testCase.L, testCase.Input)
|
t.Logf("Max length %d for %q", tc.L, tc.Input)
|
||||||
|
|
||||||
f := MaxLength(testCase.L)
|
f := MaxLength(tc.L)
|
||||||
err := f(testCase.Input)
|
err := f(tc.Input)
|
||||||
if testCase.Err {
|
if tc.Err {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Expected an error; got nil")
|
t.Error("Expected an error; got nil")
|
||||||
}
|
}
|
||||||
@@ -47,12 +47,12 @@ func TestMinLength(t *testing.T) {
|
|||||||
{L: 8, Input: "abcdefghi"},
|
{L: 8, Input: "abcdefghi"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Logf("Min length %d for %q", testCase.L, testCase.Input)
|
t.Logf("Min length %d for %q", tc.L, tc.Input)
|
||||||
|
|
||||||
f := MinLength(testCase.L)
|
f := MinLength(tc.L)
|
||||||
err := f(testCase.Input)
|
err := f(tc.Input)
|
||||||
if testCase.Err {
|
if tc.Err {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Expected an error; got nil")
|
t.Error("Expected an error; got nil")
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-5
@@ -18,15 +18,15 @@ func TestUUID(t *testing.T) {
|
|||||||
{Input: "01234567-89ab-cdef-ghij-klmnopqrstuv", Err: true},
|
{Input: "01234567-89ab-cdef-ghij-klmnopqrstuv", Err: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, tc := range testCases {
|
||||||
err := UUID(testCase.Input)
|
err := UUID(tc.Input)
|
||||||
if testCase.Err {
|
if tc.Err {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("Expected %q to be an invalid UUID; got nil", testCase.Input)
|
t.Errorf("Expected %q to be an invalid UUID; got nil", tc.Input)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Expected %q to be a valid UUID; got %s", testCase.Input, err)
|
t.Errorf("Expected %q to be a valid UUID; got %s", tc.Input, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user