-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_test.go
66 lines (60 loc) · 1.19 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
62
63
64
65
66
package truthy_test
import (
"fmt"
"testing"
"time"
"github.com/carlmjohnson/truthy"
)
type errT struct{}
func (*errT) Error() string { return "" }
func test[T any](t *testing.T, v T, ok bool) {
t.Run(fmt.Sprintf("%T-%v-%v", v, v, ok), func(t *testing.T) {
if got := truthy.ValueAny(v); got != ok {
t.Fatal()
}
})
}
func TestValueAny(t *testing.T) {
var err error
test(t, err, false)
err = (*errT)(nil)
test(t, err, true)
var errp *errT
test(t, errp, false)
test(t, "", false)
test(t, " ", true)
test(t, []byte{}, false)
test(t, []byte(" "), true)
var f func()
test(t, f, false)
f = func() {}
test(t, f, true)
var s struct{}
test(t, s, false)
test(t, &s, true)
test(t, (*struct{})(nil), false)
var i interface{}
test(t, i, false)
i = (*errT)(nil)
test(t, i, true)
test(t, 10, true)
test(t, 0, false)
test(t, 1.1, true)
test(t, 0.0, false)
var ch chan int
test(t, ch, false)
ch = make(chan int)
test(t, ch, true)
m := map[string]string{}
test(t, m, false)
m["one"] = "one"
test(t, m, true)
var a [2]int
test(t, a, false)
a = [2]int{0, 1}
test(t, a, true)
var cron time.Time
test(t, cron, false)
test(t, cron.In(time.Local), false)
test(t, time.Now(), true)
}