-
Notifications
You must be signed in to change notification settings - Fork 82
/
other_test.go
53 lines (46 loc) · 956 Bytes
/
other_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
package goutil
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func TestInitPointer(t *testing.T) {
type T struct {
A string
B int
*T
}
var i ****T
var i2 interface{} = &i
var i3 = &i2
var i4 = &i3
var i5 interface{} = &i4
var i6 = &i5
var i7 interface{} = &i6
v := reflect.ValueOf(&i7)
done := InitPointer(v)
assert.True(t, done)
assert.Equal(t, T{}, ****i)
}
func TestReferenceSlice(t *testing.T) {
v := reflect.ValueOf([]int{1, 2})
v = ReferenceSlice(v, 1)
ret := v.Interface().([]*int)
t.Logf("%#v", ret)
v = reflect.ValueOf([]int{})
v = ReferenceSlice(v, 1)
ret = v.Interface().([]*int)
t.Logf("%#v", ret)
}
func TestDereferenceSlice(t *testing.T) {
one := 1
two := 2
v := reflect.ValueOf([]*int{&one, &two})
v = DereferenceSlice(v)
ret := v.Interface().([]int)
t.Logf("%#v", ret)
v = reflect.ValueOf([]*int{})
v = DereferenceSlice(v)
ret = v.Interface().([]int)
t.Logf("%#v", ret)
}