-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathptr_test.go
More file actions
67 lines (49 loc) · 1.02 KB
/
ptr_test.go
File metadata and controls
67 lines (49 loc) · 1.02 KB
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
package books_test
import (
"testing"
"github.com/vimond/books"
)
func TestPtr(t *testing.T) {
str := "string test"
ps := books.Ptr(str)
if ps == nil || *ps != str {
t.Fatalf("string pointers did not match")
}
i := 2
pi := books.Ptr(i)
if pi == nil || *pi != i {
t.Fatalf("int pointers did not match")
}
b := true
pb := books.Ptr(b)
if pb == nil || *pb != b {
t.Fatalf("bool pointers did not match")
}
}
func TestDeref(t *testing.T) {
var nilStrPtr *string
emptyStr := books.Deref(nilStrPtr)
if emptyStr != "" {
t.Fatalf("unexpected output for nil string")
}
var nilIntPtr *int
zeroInt := books.Deref(nilIntPtr)
if zeroInt != 0 {
t.Fatalf("unexpected output for nil int")
}
str := "string test"
derefString := books.Deref(&str)
if str != derefString {
t.Fatalf("unexpected string output")
}
i := 42
derefInt := books.Deref(&i)
if i != derefInt {
t.Fatalf("unexpected int output")
}
b := true
derefBool := books.Deref(&b)
if b != derefBool {
t.Fatalf("unexpected bool output")
}
}