-
Notifications
You must be signed in to change notification settings - Fork 5
/
location_test.go
53 lines (48 loc) · 908 Bytes
/
location_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 log
import (
"strings"
"testing"
)
func testCallerLocation() string {
return callerLocation(0)
}
func TestCallerLocation(t *testing.T) {
location := testCallerLocation()
switch {
case location == "log.testCallerLocation(github.com/chanxuehong/log/location_test.go:9)":
case strings.HasPrefix(location, "log.testCallerLocation(") && strings.HasSuffix(location, "/log/location_test.go:9)"):
default:
t.Errorf("not expected location: %s", location)
return
}
}
func TestTrimFileName(t *testing.T) {
tests := []struct {
str string
want string
}{
{
"/a/b/c.go",
"/a/b/c.go",
},
{
"/a/pkg/mod/b/c.go",
"b/c.go",
},
{
"/a/pkg/mod/d/vendor/b/c.go",
"b/c.go",
},
{
"/a/vendor/b/c.go",
"b/c.go",
},
}
for _, v := range tests {
have := trimFileName(v.str)
if have != v.want {
t.Errorf("have:%s, want:%s", have, v.want)
return
}
}
}