-
Notifications
You must be signed in to change notification settings - Fork 0
/
reflect_test.go
40 lines (32 loc) · 1.18 KB
/
reflect_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
package csvlib
import (
"reflect"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_isKindOrPtrOf(t *testing.T) {
var v int
assert.True(t, isKindOrPtrOf(reflect.TypeOf(v), reflect.Int))
assert.True(t, isKindOrPtrOf(reflect.TypeOf(&v), reflect.Int))
assert.False(t, isKindOrPtrOf(reflect.TypeOf(&v), reflect.String))
}
func Test_indirectType(t *testing.T) {
var v string
assert.Equal(t, reflect.TypeOf(""), indirectType(reflect.TypeOf(v)))
assert.Equal(t, reflect.TypeOf(""), indirectType(reflect.TypeOf(&v)))
}
func Test_indirectValue(t *testing.T) {
v := "abc"
assert.Equal(t, "abc", indirectValue(reflect.ValueOf(v)).String())
assert.Equal(t, "abc", indirectValue(reflect.ValueOf(&v)).String())
}
func Test_initAndIndirectValue(t *testing.T) {
v := "abc"
assert.Equal(t, "abc", initAndIndirectValue(reflect.ValueOf(v)).String())
assert.Equal(t, "abc", initAndIndirectValue(reflect.ValueOf(&v)).String())
var v2 int
assert.Equal(t, int64(0), initAndIndirectValue(reflect.ValueOf(v2)).Int())
assert.Equal(t, int64(0), initAndIndirectValue(reflect.ValueOf(&v2)).Int())
s := []*string{nil}
assert.Equal(t, "", initAndIndirectValue(reflect.ValueOf(s).Index(0)).String())
}