-
Notifications
You must be signed in to change notification settings - Fork 1
/
nil_test.go
48 lines (44 loc) · 887 Bytes
/
nil_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
package refutil
import (
"testing"
"time"
"github.com/huttarichard/refutil/test"
)
func TestNil(t *testing.T) {
var header []string
var header2 = []string{"ok"}
nilString := test.Sample(test.SampleStringNil)
str := test.Sample(test.SampleStringPtr)
tests := []struct {
x interface{}
want bool
}{
{&header, true},
{nil, true},
{(*time.Time)(nil), true},
{header, true},
{header2, false},
{(*time.Time)(&time.Time{}), false},
{1, false},
{0, false},
{nilString, true},
{str, false},
}
for _, tt := range tests {
t.Run("test nil", func(t *testing.T) {
if got := IsNil(tt.x); got != tt.want {
t.Errorf("Nil() = %v, want %v", got, tt.want)
}
})
}
}
func TestUntyped(t *testing.T) {
v := NewValue(nil)
if !v.Untyped().IsNil() {
t.Fatalf("untyped is not nil")
}
v2 := NewValue(struct{}{})
if v2.Untyped() != v2 {
t.Fatal()
}
}