-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaller_test.go
More file actions
51 lines (48 loc) · 1.07 KB
/
caller_test.go
File metadata and controls
51 lines (48 loc) · 1.07 KB
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
package olog
import "testing"
func TestExtractPackageFromFuncName(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "simple function",
input: "package/path.Function",
expected: "package/path",
},
{
name: "method with receiver",
input: "package/path.(*Type).Method",
expected: "package/path",
},
{
name: "nested packages",
input: "github.com/user/project/internal/pkg.Function",
expected: "github.com/user/project/internal/pkg",
},
{
name: "no dot",
input: "nopackage",
expected: "",
},
{
name: "empty string",
input: "",
expected: "",
},
{
name: "complex method",
input: "github.com/pellared/olog.(*Logger).Info",
expected: "github.com/pellared/olog",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := extractPackageFromFuncName(tt.input)
if result != tt.expected {
t.Errorf("extractPackageFromFuncName(%q) = %q, expected %q", tt.input, result, tt.expected)
}
})
}
}