-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvalue_test.go
61 lines (55 loc) · 1.37 KB
/
value_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
53
54
55
56
57
58
59
60
61
package opt
import (
"fmt"
"reflect"
"testing"
)
type (
customInt int
customInt8 int8
customInt16 int16
customInt32 int32
customInt64 int64
customUint uint
customUint8 uint8
customUint16 uint16
customUint32 uint32
customUint64 uint64
customFloat32 float32
customFloat64 float64
customBool bool
customByteSlice []byte
customString string
customStruct struct{}
)
func TestToDriverValue(t *testing.T) {
doTest[int64](t, customInt(0))
doTest[int64](t, customInt8(0))
doTest[int64](t, customInt16(0))
doTest[int64](t, customInt32(0))
doTest[int64](t, customInt64(0))
doTest[int64](t, customUint(0))
doTest[int64](t, customUint8(0))
doTest[int64](t, customUint16(0))
doTest[int64](t, customUint32(0))
doTest[int64](t, customUint64(0))
doTest[float64](t, customFloat32(0))
doTest[float64](t, customFloat64(0))
doTest[bool](t, customBool(false))
doTest[[]byte](t, customByteSlice(""))
doTest[string](t, customString(""))
doTest[customStruct](t, customStruct{})
}
func doTest[E any, T any](t *testing.T, v T) {
t.Helper()
t.Run(fmt.Sprintf("%T", v), func(t *testing.T) {
drVal, err := ToDriverValue(v)
if err != nil {
t.Fatalf("error getting driver.Value: %v", err)
}
var zero E
if reflect.TypeOf(drVal) != reflect.TypeOf(zero) {
t.Fatalf("Expected value type %T but got %T", zero, drVal)
}
})
}