From 1a3c213dc1f93ef297a5c87319f1c70d663e1189 Mon Sep 17 00:00:00 2001 From: Aneurin Barker Snook Date: Sat, 7 Oct 2023 10:44:47 +0100 Subject: [PATCH] make tests slightly easier to write --- email_test.go | 10 +++++----- length_test.go | 20 ++++++++++---------- uuid_test.go | 10 +++++----- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/email_test.go b/email_test.go index 2843a9e..040fcdb 100644 --- a/email_test.go +++ b/email_test.go @@ -13,15 +13,15 @@ func TestEmail(t *testing.T) { {Input: "testexample.com", Err: true}, } - for _, testCase := range testCases { - err := Email(testCase.Input) - if testCase.Err { + for _, tc := range testCases { + err := Email(tc.Input) + if tc.Err { 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 { 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) } } } diff --git a/length_test.go b/length_test.go index b91d269..7b274b6 100644 --- a/length_test.go +++ b/length_test.go @@ -16,12 +16,12 @@ func TestMaxLength(t *testing.T) { {L: 8, Input: "abcdefghi", Err: true}, } - for _, testCase := range testCases { - t.Logf("Max length %d for %q", testCase.L, testCase.Input) + for _, tc := range testCases { + t.Logf("Max length %d for %q", tc.L, tc.Input) - f := MaxLength(testCase.L) - err := f(testCase.Input) - if testCase.Err { + f := MaxLength(tc.L) + err := f(tc.Input) + if tc.Err { if err == nil { t.Error("Expected an error; got nil") } @@ -47,12 +47,12 @@ func TestMinLength(t *testing.T) { {L: 8, Input: "abcdefghi"}, } - for _, testCase := range testCases { - t.Logf("Min length %d for %q", testCase.L, testCase.Input) + for _, tc := range testCases { + t.Logf("Min length %d for %q", tc.L, tc.Input) - f := MinLength(testCase.L) - err := f(testCase.Input) - if testCase.Err { + f := MinLength(tc.L) + err := f(tc.Input) + if tc.Err { if err == nil { t.Error("Expected an error; got nil") } diff --git a/uuid_test.go b/uuid_test.go index 1326e3f..74aa736 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -18,15 +18,15 @@ func TestUUID(t *testing.T) { {Input: "01234567-89ab-cdef-ghij-klmnopqrstuv", Err: true}, } - for _, testCase := range testCases { - err := UUID(testCase.Input) - if testCase.Err { + for _, tc := range testCases { + err := UUID(tc.Input) + if tc.Err { 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 { 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) } } }