diff --git a/validator_test.go b/validator_test.go index 85284ecc..f93240a0 100644 --- a/validator_test.go +++ b/validator_test.go @@ -10991,6 +10991,32 @@ func TestStartsWithValidation(t *testing.T) { } } } +func TestStartsNotWithValidation(t *testing.T) { + tests := []struct { + Value string `validate:"startsnotwith=(/^ヮ^)/*:・゚✧"` + Tag string + ExpectedNil bool + }{ + {Value: "(/^ヮ^)/*:・゚✧ glitter", Tag: "startsnotwith=(/^ヮ^)/*:・゚✧", ExpectedNil: false}, + {Value: "abcd", Tag: "startsnotwith=(/^ヮ^)/*:・゚✧", ExpectedNil: true}, + } + + validate := New() + + for i, s := range tests { + errs := validate.Var(s.Value, s.Tag) + + if (s.ExpectedNil && errs != nil) || (!s.ExpectedNil && errs == nil) { + t.Fatalf("Index: %d failed Error: %s", i, errs) + } + + errs = validate.Struct(s) + + if (s.ExpectedNil && errs != nil) || (!s.ExpectedNil && errs == nil) { + t.Fatalf("Index: %d failed Error: %s", i, errs) + } + } +} func TestEndsWithValidation(t *testing.T) { tests := []struct { @@ -11019,6 +11045,33 @@ func TestEndsWithValidation(t *testing.T) { } } +func TestEndsNotWithValidation(t *testing.T) { + tests := []struct { + Value string `validate:"endsnotwith=(/^ヮ^)/*:・゚✧"` + Tag string + ExpectedNil bool + }{ + {Value: "glitter (/^ヮ^)/*:・゚✧", Tag: "endsnotwith=(/^ヮ^)/*:・゚✧", ExpectedNil: false}, + {Value: "(/^ヮ^)/*:・゚✧ glitter", Tag: "endsnotwith=(/^ヮ^)/*:・゚✧", ExpectedNil: true}, + } + + validate := New() + + for i, s := range tests { + errs := validate.Var(s.Value, s.Tag) + + if (s.ExpectedNil && errs != nil) || (!s.ExpectedNil && errs == nil) { + t.Fatalf("Index: %d failed Error: %s", i, errs) + } + + errs = validate.Struct(s) + + if (s.ExpectedNil && errs != nil) || (!s.ExpectedNil && errs == nil) { + t.Fatalf("Index: %d failed Error: %s", i, errs) + } + } +} + func TestRequiredIf(t *testing.T) { type Inner struct { Field *string @@ -12886,7 +12939,7 @@ func TestIsIso4217Validation(t *testing.T) { } func TestIsIso4217NumericValidation(t *testing.T) { - tests := []struct { + testsInt := []struct { value int `validate:"iso4217_numeric"` expected bool }{ @@ -12897,7 +12950,30 @@ func TestIsIso4217NumericValidation(t *testing.T) { validate := New() - for i, test := range tests { + for i, test := range testsInt { + errs := validate.Var(test.value, "iso4217_numeric") + + if test.expected { + if !IsEqual(errs, nil) { + t.Fatalf("Index: %d iso4217 failed Error: %s", i, errs) + } + } else { + if IsEqual(errs, nil) { + t.Fatalf("Index: %d iso4217 failed Error: %s", i, errs) + } + } + } + + testsUInt := []struct { + value uint `validate:"iso4217_numeric"` + expected bool + }{ + {8, true}, + {12, true}, + {13, false}, + } + + for i, test := range testsUInt { errs := validate.Var(test.value, "iso4217_numeric") if test.expected { @@ -12910,6 +12986,8 @@ func TestIsIso4217NumericValidation(t *testing.T) { } } } + + PanicMatches(t, func() { _ = validate.Var(2.0, "iso4217_numeric") }, "Bad field type float64") } func TestTimeZoneValidation(t *testing.T) {