From 24f6987fe0cf989a48658201d6710a450f386ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tighearn=C3=A1n=20Carroll?= Date: Thu, 15 Feb 2024 11:48:45 +0000 Subject: [PATCH 1/2] remove in favour of --- functions.go | 4 ++-- functions_test.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/functions.go b/functions.go index fd37c0f..37a7ebf 100644 --- a/functions.go +++ b/functions.go @@ -280,8 +280,8 @@ func Email(val string) ValidationFunc { } } -// AnyString will check if the provided string is in a set of allowed values. -func AnyString(val string, vv ...string) ValidationFunc { +// Any will check if the provided value is in a set of allowed values. +func Any[T comparable](val T, vv ...T) ValidationFunc { return func() error { for _, v := range vv { if val == v { diff --git a/functions_test.go b/functions_test.go index 36562d1..7b07878 100644 --- a/functions_test.go +++ b/functions_test.go @@ -374,6 +374,7 @@ func TestMatchBytes(t *testing.T) { }) } } + func TestEqualBool(t *testing.T) { t.Parallel() is := is.New(t) @@ -969,7 +970,7 @@ func TestEmpty(t *testing.T) { } } -func TestAnyString(t *testing.T) { +func TestAny(t *testing.T) { t.Parallel() is := is.New(t) tt := map[string]struct { @@ -1000,7 +1001,7 @@ func TestAnyString(t *testing.T) { for name, test := range tt { t.Run(name, func(t *testing.T) { is = is.NewRelaxed(t) - is.Equal(test.expErr, AnyString(test.val, test.list...)()) + is.Equal(test.expErr, Any(test.val, test.list...)()) }) } } From 8ed7477a4e12b58eeef0c3ceb5f98dd7f152b742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tighearn=C3=A1n=20Carroll?= Date: Thu, 15 Feb 2024 11:51:15 +0000 Subject: [PATCH 2/2] add AnyString back, but deprecated --- functions.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/functions.go b/functions.go index 37a7ebf..39a5f06 100644 --- a/functions.go +++ b/functions.go @@ -292,3 +292,10 @@ func Any[T comparable](val T, vv ...T) ValidationFunc { return errors.New("value not found in allowed values") } } + +// AnyString will check if the provided string is in a set of allowed values. +// +// Deprecated: use Any instead. Will be removed in a future release. +func AnyString(val string, vv ...string) ValidationFunc { + return Any(val, vv...) +}