equal_test.go 701 B

123456789101112131415161718192021222324252627282930
  1. package validate
  2. import (
  3. "errors"
  4. "fmt"
  5. "testing"
  6. )
  7. func TestEqual(t *testing.T) {
  8. testCases := map[string]map[string]error{
  9. "abc": {"abc": nil, "def": ErrNotEqual.With("abc"), "xyz": ErrNotEqual.With("abc")},
  10. "def": {"abc": ErrNotEqual.With("def"), "def": nil, "xyz": ErrNotEqual.With("def")},
  11. "xyz": {"abc": ErrNotEqual.With("xyz"), "def": ErrNotEqual.With("xyz"), "xyz": nil},
  12. }
  13. for setup, values := range testCases {
  14. testEqual := Equal(setup)
  15. for input, want := range values {
  16. t.Run(fmt.Sprintf("%s/%s", setup, input), func(t *testing.T) {
  17. got := testEqual(input)
  18. if !errors.Is(got, want) {
  19. t.Error("got", got)
  20. t.Error("want", want)
  21. }
  22. })
  23. }
  24. }
  25. }