Files

39 lines
594 B
Go
Raw Permalink Normal View History

2023-10-07 11:24:34 +01:00
package validate
import (
"errors"
2024-07-18 06:53:20 +01:00
"fmt"
2023-10-07 11:24:34 +01:00
"testing"
)
2024-07-18 06:53:20 +01:00
func ExampleIn() {
testIn := In("abc", "def", "xyz")
fmt.Println(testIn("123"))
// Output: not allowed
2023-10-08 16:20:21 +01:00
}
2024-07-18 06:53:20 +01:00
func TestIn(t *testing.T) {
testIn := In("abc", "def", "xyz")
2023-10-07 11:24:34 +01:00
2024-07-18 06:53:20 +01:00
testCases := map[string]error{
"abc": nil,
"def": nil,
"xyz": nil,
2023-10-07 11:24:34 +01:00
2024-07-18 06:53:20 +01:00
"abcd": ErrValueNotAllowed,
"123": ErrValueNotAllowed,
"": ErrValueNotAllowed,
}
2023-10-07 11:24:34 +01:00
2024-07-18 06:53:20 +01:00
for input, want := range testCases {
t.Run(input, func(t *testing.T) {
got := testIn(input)
2023-10-07 11:24:34 +01:00
2024-07-18 06:53:20 +01:00
if !errors.Is(got, want) {
t.Error("got", got)
t.Error("want", want)
}
})
2023-10-07 11:24:34 +01:00
}
}