-
Notifications
You must be signed in to change notification settings - Fork 0
/
source_test.go
72 lines (51 loc) · 1.39 KB
/
source_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-FileCopyrightText: 2020-2024 caixw
//
// SPDX-License-Identifier: MIT
package source
import (
"path/filepath"
"strings"
"testing"
"github.com/issue9/assert/v4"
)
func TestCurrentPath(t *testing.T) {
a := assert.New(t, false)
dir, err := filepath.Abs("./file.go")
a.NotError(err).NotEmpty(dir)
d, err := filepath.Abs(CurrentPath("./file.go"))
a.NotError(err).NotEmpty(d)
a.Equal(d, dir)
}
func TestCurrentDir(t *testing.T) {
a := assert.New(t, false)
dir, err := filepath.Abs("./")
a.NotError(err).NotEmpty(dir)
a.Equal(CurrentDir(), dir)
}
func TestCurrentFile(t *testing.T) {
a := assert.New(t, false)
filename, err := filepath.Abs("./source_test.go")
a.NotError(err).NotEmpty(filename)
a.Equal(CurrentFile(), filepath.ToSlash(filename))
}
func TestCurrentFunction(t *testing.T) {
a := assert.New(t, false)
a.Equal(CurrentFunction(), "TestCurrentFunction")
}
func TestCurrentLine(t *testing.T) {
a := assert.New(t, false)
a.Equal(CurrentLine(), 54)
}
func TestCurrentLocation(t *testing.T) {
a := assert.New(t, false)
path, line := CurrentLocation()
a.True(strings.HasSuffix(path, "source_test.go")).
Equal(line, 60)
}
func TestStack(t *testing.T) {
a := assert.New(t, false)
str := Stack(1, true, "message", 12)
t.Log(str)
a.True(strings.HasPrefix(str, "message 12"))
a.True(strings.Contains(str, "source_test.go:68"), str) // 依赖调用 Stack 的行号
}