chars_test.go 541 B

1234567891011121314151617181920212223242526272829303132
  1. package validate
  2. import (
  3. "errors"
  4. "testing"
  5. )
  6. func TestChars(t *testing.T) {
  7. type TestCase struct {
  8. Input string
  9. C string
  10. Err error
  11. }
  12. hexRange := "0123456789abcdef"
  13. testCases := []TestCase{
  14. {Input: "abcd1234", C: hexRange},
  15. {Input: "abcd 1234", C: hexRange, Err: ErrDisallowedChars},
  16. }
  17. for n, tc := range testCases {
  18. t.Logf("(%d) Testing %q against %q", n, tc.Input, tc.C)
  19. f := Chars(tc.C)
  20. err := f(tc.Input)
  21. if !errors.Is(err, tc.Err) {
  22. t.Errorf("Expected error %v, got %v", tc.Err, err)
  23. }
  24. }
  25. }