goref/type_test.go

35 lines
722 B
Go

package goref_test
import (
"github.com/stretchr/testify/assert"
"gitter.top/common/goref"
"reflect"
"testing"
)
func TestIsBaseStruct(t *testing.T) {
type T struct{}
var a T
t.Log(goref.IsBaseStruct(a))
var list any = []T{}
t.Log(reflect.TypeOf(list))
}
func TestToInterfaces(t *testing.T) {
type T string
var list any = []T{
"hello",
"world",
}
t.Log(goref.ToInterfaces(list))
}
func TestGetBaseType(t *testing.T) {
var ch = make(chan int, 5)
assert.EqualValues(t, reflect.Int, goref.GetBaseType(ch).Kind())
var slice []string
assert.EqualValues(t, reflect.String, goref.GetBaseType(slice).Kind())
var m map[string]struct{}
assert.EqualValues(t, reflect.Struct, goref.GetBaseType(m).Kind())
}