-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic_test.go
60 lines (55 loc) · 1.18 KB
/
generic_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
//go:build go1.18
package pt_test
import (
"testing"
"time"
"github.com/gochore/pt"
)
func TestP(t *testing.T) {
t.Run("int", func(t *testing.T) {
if got := pt.P(1); *got != 1 {
t.Errorf("P() = %v, want %v", *got, 1)
}
})
t.Run("float64", func(t *testing.T) {
if got := pt.P(1.1); *got != 1.1 {
t.Errorf("P() = %v, want %v", *got, 1)
}
})
t.Run("time", func(t *testing.T) {
now := time.Now()
if got := pt.P(now); *got != now {
t.Errorf("P() = %v, want %v", *got, 1)
}
})
}
func TestV(t *testing.T) {
t.Run("int", func(t *testing.T) {
if got := pt.V(pt.P(1)); got != 1 {
t.Errorf("V() = %v, want %v", got, 1)
}
})
t.Run("float64", func(t *testing.T) {
if got := pt.V(pt.P(1.1)); got != 1.1 {
t.Errorf("V() = %v, want %v", got, 1)
}
})
t.Run("time", func(t *testing.T) {
now := time.Now()
if got := pt.V(pt.P(now)); got != now {
t.Errorf("V() = %v, want %v", got, 1)
}
})
t.Run("nil int", func(t *testing.T) {
var i *int
if got := pt.V(i); got != 0 {
t.Errorf("V() = %v, want %v", got, 0)
}
})
t.Run("nil string", func(t *testing.T) {
var s *string
if got := pt.V(s); got != "" {
t.Errorf("V() = %v, want %v", got, "")
}
})
}