-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpointer_test.go
72 lines (56 loc) · 1.82 KB
/
pointer_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
package pointer
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
// ------------------------------------------------- --------------------------------------------------------------------
func TestFalsePointer(t *testing.T) {
pointer := FalsePointer()
assert.NotNil(t, pointer)
assert.False(t, *pointer)
}
func ExampleFalsePointer() {
pointer := FalsePointer()
fmt.Printf("%T %v", pointer, *pointer)
// Output:
// *bool false
}
// ------------------------------------------------- --------------------------------------------------------------------
func TestFromPointer(t *testing.T) {
v1 := true
v2 := &v1
pointer := FromPointer(v2)
assert.Equal(t, true, pointer)
}
// ------------------------------------------------- --------------------------------------------------------------------
func TestFromPointerOrDefault(t *testing.T) {
v1 := true
v2 := &v1
pointer := FromPointer(v2)
assert.Equal(t, true, pointer)
}
// ------------------------------------------------- --------------------------------------------------------------------
func TestToPointer(t *testing.T) {
v := 1
pointer := ToPointer(v)
t.Log(pointer)
}
// ------------------------------------------------- --------------------------------------------------------------------
func TestToPointerOrNil(t *testing.T) {
orNil := ToPointerOrNil(0)
t.Log(orNil)
}
// ------------------------------------------------- --------------------------------------------------------------------
func TestTruePointer(t *testing.T) {
pointer := TruePointer()
assert.NotNil(t, pointer)
assert.True(t, *pointer)
}
func ExampleTruePointer() {
pointer := TruePointer()
fmt.Printf("%T %v", pointer, *pointer)
// Output:
// *bool true
}
// ------------------------------------------------- --------------------------------------------------------------------