chars_test.go 589 B

1234567891011121314151617181920212223242526272829303132333435
  1. package validate
  2. import "testing"
  3. func TestChars(t *testing.T) {
  4. type TestCase struct {
  5. C string
  6. Input string
  7. Err bool
  8. }
  9. hexRange := "0123456789abcdef"
  10. testCases := []TestCase{
  11. {C: hexRange, Input: "abcd1234"},
  12. {C: hexRange, Input: "abcd 1234", Err: true},
  13. }
  14. for _, tc := range testCases {
  15. t.Logf("%q contains only allowed characters %q", tc.Input, tc.C)
  16. f := Chars(tc.C)
  17. err := f(tc.Input)
  18. if tc.Err {
  19. if err == nil {
  20. t.Error("Expected error; got nil")
  21. }
  22. } else {
  23. if err != nil {
  24. t.Errorf("Expected nil; got %s", err)
  25. }
  26. }
  27. }
  28. }