-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
94 lines (74 loc) · 1.4 KB
/
utils_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
package jsql_test
import (
"github.com/joernlenoch/go-jsql"
"testing"
)
func TestIsNil(t *testing.T) {
if !jsql.IsNil(nil) {
t.Errorf("nil must be nil")
t.Fail()
}
// Check nil slices.
var x []byte
x = nil
if !jsql.IsNil(x) {
t.Errorf("nil slice must be nil")
t.Fail()
}
x = []byte("")
if jsql.IsNil(x) {
t.Errorf("empty slice must not be nil")
t.Fail()
}
x = []byte("null")
if jsql.IsNil(x) {
t.Errorf("slice with text null must not be nil")
t.Fail()
}
// Check basic pointers on base types.
var y *string
y = nil
if !jsql.IsNil(y) {
t.Errorf("nil pointer must be nil")
t.Fail()
}
yt := ""
y = &yt
if jsql.IsNil(y) {
t.Errorf("filled pointer must not be nil")
t.Fail()
}
yt2 := "null"
y = &yt2
if jsql.IsNil(y) {
t.Errorf("pointer with value 'null' must not be nil")
t.Fail()
}
// Check structs
type simpleStruct struct {
someValue int
}
if jsql.IsNil(simpleStruct{}) {
t.Errorf("zero struct must not be nil")
t.Fail()
}
if jsql.IsNil(&simpleStruct{}) {
t.Errorf("pointer to zero struct must not be nil")
t.Fail()
}
var nst simpleStruct
if jsql.IsNil(nst) {
t.Errorf("zero struct must not be nil")
t.Fail()
}
var st *simpleStruct
if !jsql.IsNil(st) {
t.Errorf("nil pointer to struct must be nil")
t.Fail()
}
st = &simpleStruct{}
if jsql.IsNil(st) {
t.Errorf("pointer to zero struct must not be nil")
t.Fail()
}
}