-
Notifications
You must be signed in to change notification settings - Fork 0
/
typecheck_test.go
100 lines (76 loc) · 1.7 KB
/
typecheck_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package geko
import (
"testing"
)
type stringWrapper string
type stringStruct struct {
string
}
type stringFieldStruct struct {
s string
}
type realStruct struct {
s string
i int
}
//nolint:revive
type emptyInterface interface {
}
type publicInterface interface {
Good()
}
type privateInterface interface {
good()
}
func TestIsAny(t *testing.T) {
if !isEmptyInterface[interface{}]() { //nolint:revive
t.Fatalf("isAny failed in type interface{}")
}
if !isEmptyInterface[any]() {
t.Fatalf("isAny failed in type any")
}
if !isEmptyInterface[emptyInterface]() {
t.Fatalf("isAny failed in type emptyInterface")
}
if isEmptyInterface[string]() {
t.Fatalf("isAny failed in type string")
}
if isEmptyInterface[int]() {
t.Fatalf("isAny failed in type int")
}
if isEmptyInterface[publicInterface]() {
t.Fatalf("isAny failed in type publicInterface")
}
if isEmptyInterface[privateInterface]() {
t.Fatalf("isAny failed in type publicInterface")
}
}
func TestIsString(t *testing.T) {
if !isString[string]() {
t.Fatalf("isString failed in type string")
}
if isString[*string]() {
t.Fatalf("isString failed in type *string")
}
if isString[int]() {
t.Fatalf("isString failed in type int")
}
if isString[float64]() {
t.Fatalf("isString failed in type float64")
}
if isString[bool]() {
t.Fatalf("isString failed in type bool")
}
if isString[stringWrapper]() {
t.Fatalf("isString failed in type stringWrapper")
}
if isString[stringStruct]() {
t.Fatalf("isString failed in type stringStruct")
}
if isString[stringFieldStruct]() {
t.Fatalf("isString failed in type stringFieldStruct")
}
if isString[realStruct]() {
t.Fatalf("isString failed in type realStruct")
}
}