-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_extractor_numeric_test.go
52 lines (48 loc) · 2.43 KB
/
value_extractor_numeric_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package justest_test
import (
"testing"
"github.com/google/go-cmp/cmp"
. "github.com/arikkfir/justest"
. "github.com/arikkfir/justest/internal"
)
func TestNumericValueExtractor(t *testing.T) {
t.Parallel()
type testCase struct {
actual any
verifier TestOutcomeVerifier
expected any
}
testCases := map[string]testCase{
"string fails": {actual: "1", verifier: FailureVerifier(`Unsupported actual value: 1`)},
"chan int": {actual: ChanOf(1), verifier: SuccessVerifier(), expected: 1},
"chan string fails": {actual: ChanOf("1"), verifier: FailureVerifier(`Unsupported actual value: 1`)},
"float32": {actual: float32(1.1), verifier: SuccessVerifier(), expected: float32(1.1)},
"float64": {actual: 1.1, verifier: SuccessVerifier(), expected: 1.1},
"func int": {actual: func(t T) any { return 1 }, verifier: SuccessVerifier(), expected: 1},
"func string fails": {actual: func(t T) any { return "1" }, verifier: FailureVerifier(`Unsupported actual value: 1`)},
"int": {actual: 1, verifier: SuccessVerifier(), expected: 1},
"int8": {actual: int8(1), verifier: SuccessVerifier(), expected: int8(1)},
"int16": {actual: int16(1), verifier: SuccessVerifier(), expected: int16(1)},
"int32": {actual: int32(1), verifier: SuccessVerifier(), expected: int32(1)},
"int64": {actual: int64(1), verifier: SuccessVerifier(), expected: int64(1)},
"pointer int": {actual: Ptr(1), verifier: SuccessVerifier(), expected: 1},
"pointer string fails": {actual: Ptr("1"), verifier: FailureVerifier(`Unsupported actual value: 1`)},
"uint": {actual: 1, verifier: SuccessVerifier(), expected: 1},
"uint8": {actual: uint8(1), verifier: SuccessVerifier(), expected: uint8(1)},
"uint16": {actual: uint16(1), verifier: SuccessVerifier(), expected: uint16(1)},
"uint32": {actual: uint32(1), verifier: SuccessVerifier(), expected: uint32(1)},
"uint64": {actual: uint64(1), verifier: SuccessVerifier(), expected: uint64(1)},
}
for name, tc := range testCases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
mt := NewMockT(t)
defer mt.Verify(tc.verifier)
v := NewNumericValueExtractor().MustExtractValue(mt, tc.actual)
if !cmp.Equal(tc.expected, v) {
t.Fatalf("Expected '%v', got '%v'", tc.expected, v)
}
})
}
}