123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package validate
- import (
- "errors"
- "testing"
- )
- func TestChars(t *testing.T) {
- type TestCase struct {
- Input string
- C string
- Err error
- }
- hexRange := "0123456789abcdef"
- testCases := []TestCase{
- {Input: "abcd1234", C: hexRange},
- {Input: "abcd 1234", C: hexRange, Err: ErrDisallowedChars},
- {Input: "ghijklmno", C: hexRange, Err: ErrDisallowedChars},
- }
- for n, tc := range testCases {
- t.Logf("(%d) Testing %q against %q", n, tc.Input, tc.C)
- f := Chars(tc.C)
- err := f(tc.Input)
- if !errors.Is(err, tc.Err) {
- t.Errorf("Expected error %v, got %v", tc.Err, err)
- }
- }
- }
- func TestExceptChars(t *testing.T) {
- type TestCase struct {
- Input string
- C string
- Err error
- }
- hexRange := "0123456789abcdef"
- testCases := []TestCase{
- {Input: "abcd1234", C: hexRange, Err: ErrDisallowedChars},
- {Input: "abcd 1234", C: hexRange, Err: ErrDisallowedChars},
- {Input: "ghijklmno", C: hexRange},
- }
- for n, tc := range testCases {
- t.Logf("(%d) Testing %q against %q", n, tc.Input, tc.C)
- f := ExceptChars(tc.C)
- err := f(tc.Input)
- if !errors.Is(err, tc.Err) {
- t.Errorf("Expected error %v, got %v", tc.Err, err)
- }
- }
- }
|