-
Notifications
You must be signed in to change notification settings - Fork 191
/
gofunc_test.go
52 lines (41 loc) · 1.4 KB
/
gofunc_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
package goinfo_test
import (
"testing"
"github.com/gookit/goutil/dump"
"github.com/gookit/goutil/goinfo"
"github.com/gookit/goutil/testutil/assert"
)
func TestFuncName(t *testing.T) {
name := goinfo.FuncName(goinfo.PkgName)
assert.Eq(t, "github.com/gookit/goutil/goinfo.PkgName", name)
assert.True(t, goinfo.GoodFuncName("MyFunc"))
assert.False(t, goinfo.GoodFuncName(""))
assert.False(t, goinfo.GoodFuncName("+MyFunc"))
assert.False(t, goinfo.GoodFuncName("My+Func"))
}
func TestPkgName(t *testing.T) {
name := goinfo.PkgName(goinfo.FuncName(goinfo.GetCallerInfo))
assert.Eq(t, "github.com/gookit/goutil/goinfo", name)
}
func TestFullFcName_Parse(t *testing.T) {
fullName := goinfo.FuncName(goinfo.GetCallerInfo)
ffn := goinfo.FullFcName{FullName: fullName}
ffn.Parse()
assert.Eq(t, fullName, ffn.String())
assert.Eq(t, "goinfo", ffn.PkgName())
assert.Eq(t, "GetCallerInfo", ffn.FuncName())
assert.Eq(t, "github.com/gookit/goutil/goinfo", ffn.PkgPath())
dump.P(ffn)
st := goinfo.FullFcName{}
fullName = goinfo.FuncName(st.FuncName)
ffn = goinfo.FullFcName{FullName: fullName}
ffn.Parse()
assert.Eq(t, "(*FullFcName).FuncName-fm", ffn.FuncName())
dump.P(ffn)
}
func TestCutFuncName(t *testing.T) {
fullName := goinfo.FuncName(goinfo.GetCallerInfo)
pkgPath, funcName := goinfo.CutFuncName(fullName)
assert.Eq(t, "GetCallerInfo", funcName)
assert.Eq(t, "github.com/gookit/goutil/goinfo", pkgPath)
}