bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/name/length_test.go (about) 1 package name 2 3 import "testing" 4 5 func TestLengthValidation(t *testing.T) { 6 testCases := []struct { 7 testString string 8 expectPass bool 9 }{ 10 {"123", true}, 11 {"123abc", true}, 12 {"!@£$%^&", true}, 13 {"0123456789", true}, 14 {"", false}, 15 {"1", false}, 16 {"ab", false}, 17 {"01234567890", false}, 18 } 19 20 validator := NewLengthValidator(3, 10) 21 22 for _, testCase := range testCases { 23 if validator.IsValid(testCase.testString) != testCase.expectPass { 24 t.Errorf("Expected IsValid test for '%s' to yeild '%t' not '%t'", 25 testCase.testString, testCase.expectPass, !testCase.expectPass) 26 } 27 } 28 }