-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointer_test.go
57 lines (47 loc) · 907 Bytes
/
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
package just_test
import (
"github.com/kazhuravlev/just"
"github.com/stretchr/testify/assert"
"testing"
)
func TestPointer(t *testing.T) {
t.Parallel()
a := just.Pointer(10)
assert.Equal(t, 10, *a)
}
func TestPointerUnwrap(t *testing.T) {
t.Parallel()
n := 10
a := just.PointerUnwrap(&n)
assert.Equal(t, n, a)
}
func TestPointerUnwrapDefault(t *testing.T) {
t.Parallel()
table := []struct {
in *int
defaultVal int
exp int
}{
{
in: nil,
defaultVal: 10,
exp: 10,
},
{
in: just.Pointer(6),
defaultVal: 10,
exp: 6,
},
}
for _, row := range table {
t.Run("", func(t *testing.T) {
res := just.PointerUnwrapDefault(row.in, row.defaultVal)
assert.Equal(t, row.exp, res)
})
}
type Data struct {
Value int
}
res := just.PointerUnwrapDefault((*Data)(nil), Data{42})
assert.Equal(t, Data{42}, res)
}