equal_test.go 903 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package validate
  2. import "testing"
  3. func TestEqualInt(t *testing.T) {
  4. type TestCase struct {
  5. I int
  6. C int
  7. Err error
  8. }
  9. testCases := []TestCase{
  10. {I: 1, C: 1},
  11. {I: 5 ^ 3, C: 5 ^ 3},
  12. {I: 10, C: 15, Err: ErrValueNotAllowed},
  13. }
  14. for i, tc := range testCases {
  15. t.Logf("(%d) Testing %d against %d", i, tc.I, tc.C)
  16. f := Equal(tc.C)
  17. err := f(tc.I)
  18. if err != tc.Err {
  19. t.Errorf("Expected error %v, got %v", tc.Err, err)
  20. }
  21. }
  22. }
  23. func TestEqualStr(t *testing.T) {
  24. type TestCase struct {
  25. I string
  26. C string
  27. Err error
  28. }
  29. testCases := []TestCase{
  30. {I: "abc", C: "abc"},
  31. {I: "def ghi 123", C: "def ghi 123"},
  32. {I: "jkl", C: "mno", Err: ErrValueNotAllowed},
  33. }
  34. for i, tc := range testCases {
  35. t.Logf("(%d) Testing %s against %s", i, tc.I, tc.C)
  36. f := Equal(tc.C)
  37. err := f(tc.I)
  38. if err != tc.Err {
  39. t.Errorf("Expected error %v, got %v", tc.Err, err)
  40. }
  41. }
  42. }