1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package validate
- import "testing"
- func TestMaxLength(t *testing.T) {
- type TestCase struct {
- L int
- Input string
- Err bool
- }
- testCases := []TestCase{
- {L: 8, Input: "abcd"},
- {L: 8, Input: "abcdefgh"},
- {L: 8, Input: "abcd efg"},
- {L: 8, Input: "abcdefghi", Err: true},
- }
- for _, tc := range testCases {
- t.Logf("Max length %d for %q", tc.L, tc.Input)
- f := MaxLength(tc.L)
- err := f(tc.Input)
- if tc.Err {
- if err == nil {
- t.Error("Expected an error; got nil")
- }
- } else {
- if err != nil {
- t.Errorf("Expected nil; got %s", err)
- }
- }
- }
- }
- func TestMinLength(t *testing.T) {
- type TestCase struct {
- L int
- Input string
- Err bool
- }
- testCases := []TestCase{
- {L: 8, Input: "abcd", Err: true},
- {L: 8, Input: "abcdefgh"},
- {L: 8, Input: "abcd efg"},
- {L: 8, Input: "abcdefghi"},
- }
- for _, tc := range testCases {
- t.Logf("Min length %d for %q", tc.L, tc.Input)
- f := MinLength(tc.L)
- err := f(tc.Input)
- if tc.Err {
- if err == nil {
- t.Error("Expected an error; got nil")
- }
- } else {
- if err != nil {
- t.Errorf("Expected nil; got %s", err)
- }
- }
- }
- }
|