number tests
This commit is contained in:
+2
-2
@@ -26,8 +26,8 @@ func TestAll(t *testing.T) {
|
|||||||
{Input: "01abcd", F: f, Err: ErrValueNotAllowed},
|
{Input: "01abcd", F: f, Err: ErrValueNotAllowed},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for n, tc := range testCases {
|
||||||
t.Logf("Testing %q", tc.Input)
|
t.Logf("(%d) Testing %q", n, tc.Input)
|
||||||
|
|
||||||
err := tc.F(tc.Input)
|
err := tc.F(tc.Input)
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -16,8 +16,8 @@ func TestChars(t *testing.T) {
|
|||||||
{Input: "abcd 1234", C: hexRange, Err: ErrDisallowedChars},
|
{Input: "abcd 1234", C: hexRange, Err: ErrDisallowedChars},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for n, tc := range testCases {
|
||||||
t.Logf("Testing %q against %q", tc.Input, tc.C)
|
t.Logf("(%d) Testing %q against %q", n, tc.Input, tc.C)
|
||||||
|
|
||||||
f := Chars(tc.C)
|
f := Chars(tc.C)
|
||||||
err := f(tc.Input)
|
err := f(tc.Input)
|
||||||
|
|||||||
+2
-2
@@ -13,8 +13,8 @@ func TestEmail(t *testing.T) {
|
|||||||
{Input: "testexample.com", Err: ErrInvalidEmail},
|
{Input: "testexample.com", Err: ErrInvalidEmail},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for n, tc := range testCases {
|
||||||
t.Logf("Testing %q", tc.Input)
|
t.Logf("(%d) Testing %q", n, tc.Input)
|
||||||
|
|
||||||
err := Email(tc.Input)
|
err := Email(tc.Input)
|
||||||
|
|
||||||
|
|||||||
+39
-31
@@ -4,42 +4,50 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestIn(t *testing.T) {
|
func TestInString(t *testing.T) {
|
||||||
type TestCase[T comparable] struct {
|
type TestCase struct {
|
||||||
Input T
|
Input string
|
||||||
A []T
|
A []string
|
||||||
Err error
|
Err error
|
||||||
}
|
}
|
||||||
|
|
||||||
strIn := []string{"abcd", "ef", "1234"}
|
allow := []string{"abcd", "ef", "1234"}
|
||||||
strTestCases := []TestCase[string]{
|
testCases := []TestCase{
|
||||||
{Input: "abcd", A: strIn},
|
{Input: "abcd", A: allow},
|
||||||
{Input: "ef", A: strIn},
|
{Input: "ef", A: allow},
|
||||||
{Input: "1234", A: strIn},
|
{Input: "1234", A: allow},
|
||||||
{Input: "5678", A: strIn, Err: ErrValueNotAllowed},
|
{Input: "5678", A: allow, Err: ErrValueNotAllowed},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range strTestCases {
|
for n, tc := range testCases {
|
||||||
t.Logf("Testing %q against %v", tc.Input, tc.A)
|
t.Logf("(%d) Testing %q against %v", n, tc.Input, tc.A)
|
||||||
|
|
||||||
f := In(tc.A...)
|
f := In(tc.A...)
|
||||||
err := f(tc.Input)
|
err := f(tc.Input)
|
||||||
|
|
||||||
if err != tc.Err {
|
if err != tc.Err {
|
||||||
t.Errorf("Expected error %v, got %v", tc.Err, err)
|
t.Errorf("Expected error %v, got %v", tc.Err, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
intIn := []int{1, 23, 456}
|
|
||||||
intTestCases := []TestCase[int]{
|
func TestInInt(t *testing.T) {
|
||||||
{Input: 1, A: intIn},
|
type TestCase struct {
|
||||||
{Input: 23, A: intIn},
|
Input int
|
||||||
{Input: 456, A: intIn},
|
A []int
|
||||||
{Input: 789, A: intIn, Err: ErrValueNotAllowed},
|
Err error
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range intTestCases {
|
allow := []int{1, 23, 456}
|
||||||
t.Logf("Testing %d against %v", tc.Input, tc.A)
|
testCases := []TestCase{
|
||||||
|
{Input: 1, A: allow},
|
||||||
|
{Input: 23, A: allow},
|
||||||
|
{Input: 456, A: allow},
|
||||||
|
{Input: 789, A: allow, Err: ErrValueNotAllowed},
|
||||||
|
}
|
||||||
|
|
||||||
|
for n, tc := range testCases {
|
||||||
|
t.Logf("(%d) Testing %d against %v", n, tc.Input, tc.A)
|
||||||
|
|
||||||
f := In(tc.A...)
|
f := In(tc.A...)
|
||||||
err := f(tc.Input)
|
err := f(tc.Input)
|
||||||
|
|||||||
+4
-4
@@ -16,8 +16,8 @@ func TestMaxLength(t *testing.T) {
|
|||||||
{Input: "abcdefghi", L: 8, Err: ErrTooManyChars},
|
{Input: "abcdefghi", L: 8, Err: ErrTooManyChars},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for n, tc := range testCases {
|
||||||
t.Logf("Testing %q against maximum length of %d", tc.Input, tc.L)
|
t.Logf("(%d) Testing %q against maximum length of %d", n, tc.Input, tc.L)
|
||||||
|
|
||||||
f := MaxLength(tc.L)
|
f := MaxLength(tc.L)
|
||||||
err := f(tc.Input)
|
err := f(tc.Input)
|
||||||
@@ -42,8 +42,8 @@ func TestMinLength(t *testing.T) {
|
|||||||
{Input: "abcdefghi", L: 8},
|
{Input: "abcdefghi", L: 8},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for n, tc := range testCases {
|
||||||
t.Logf("Testing %q against minimum length of %d", tc.Input, tc.L)
|
t.Logf("(%d) Testing %q against minimum length of %d", n, tc.Input, tc.L)
|
||||||
|
|
||||||
f := MinLength(tc.L)
|
f := MinLength(tc.L)
|
||||||
err := f(tc.Input)
|
err := f(tc.Input)
|
||||||
|
|||||||
+2
-2
@@ -18,8 +18,8 @@ func TestUUID(t *testing.T) {
|
|||||||
{Input: "01234567-89ab-cdef-ghij-klmnopqrstuv", Err: ErrInvalidUUID},
|
{Input: "01234567-89ab-cdef-ghij-klmnopqrstuv", Err: ErrInvalidUUID},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for n, tc := range testCases {
|
||||||
t.Logf("Testing %q", tc.Input)
|
t.Logf("(%d) Testing %q", n, tc.Input)
|
||||||
|
|
||||||
err := UUID(tc.Input)
|
err := UUID(tc.Input)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user