|
@@ -4,23 +4,23 @@ import (
|
|
|
"testing"
|
|
|
)
|
|
|
|
|
|
-func TestIn(t *testing.T) {
|
|
|
- type TestCase[T comparable] struct {
|
|
|
- Input T
|
|
|
- A []T
|
|
|
+func TestInString(t *testing.T) {
|
|
|
+ type TestCase struct {
|
|
|
+ Input string
|
|
|
+ A []string
|
|
|
Err error
|
|
|
}
|
|
|
|
|
|
- strIn := []string{"abcd", "ef", "1234"}
|
|
|
- strTestCases := []TestCase[string]{
|
|
|
- {Input: "abcd", A: strIn},
|
|
|
- {Input: "ef", A: strIn},
|
|
|
- {Input: "1234", A: strIn},
|
|
|
- {Input: "5678", A: strIn, Err: ErrValueNotAllowed},
|
|
|
+ allow := []string{"abcd", "ef", "1234"}
|
|
|
+ testCases := []TestCase{
|
|
|
+ {Input: "abcd", A: allow},
|
|
|
+ {Input: "ef", A: allow},
|
|
|
+ {Input: "1234", A: allow},
|
|
|
+ {Input: "5678", A: allow, Err: ErrValueNotAllowed},
|
|
|
}
|
|
|
|
|
|
- for _, tc := range strTestCases {
|
|
|
- t.Logf("Testing %q against %v", tc.Input, tc.A)
|
|
|
+ for n, tc := range testCases {
|
|
|
+ t.Logf("(%d) Testing %q against %v", n, tc.Input, tc.A)
|
|
|
|
|
|
f := In(tc.A...)
|
|
|
err := f(tc.Input)
|
|
@@ -29,17 +29,25 @@ func TestIn(t *testing.T) {
|
|
|
t.Errorf("Expected error %v, got %v", tc.Err, err)
|
|
|
}
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+func TestInInt(t *testing.T) {
|
|
|
+ type TestCase struct {
|
|
|
+ Input int
|
|
|
+ A []int
|
|
|
+ Err error
|
|
|
+ }
|
|
|
|
|
|
- intIn := []int{1, 23, 456}
|
|
|
- intTestCases := []TestCase[int]{
|
|
|
- {Input: 1, A: intIn},
|
|
|
- {Input: 23, A: intIn},
|
|
|
- {Input: 456, A: intIn},
|
|
|
- {Input: 789, A: intIn, Err: ErrValueNotAllowed},
|
|
|
+ allow := []int{1, 23, 456}
|
|
|
+ testCases := []TestCase{
|
|
|
+ {Input: 1, A: allow},
|
|
|
+ {Input: 23, A: allow},
|
|
|
+ {Input: 456, A: allow},
|
|
|
+ {Input: 789, A: allow, Err: ErrValueNotAllowed},
|
|
|
}
|
|
|
|
|
|
- for _, tc := range intTestCases {
|
|
|
- t.Logf("Testing %d against %v", tc.Input, tc.A)
|
|
|
+ for n, tc := range testCases {
|
|
|
+ t.Logf("(%d) Testing %d against %v", n, tc.Input, tc.A)
|
|
|
|
|
|
f := In(tc.A...)
|
|
|
err := f(tc.Input)
|