-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileWithLineNum_test.go
55 lines (43 loc) · 1.19 KB
/
fileWithLineNum_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
package timber
import (
"strings"
"testing"
)
func TestGetCaller(t *testing.T) {
file, line := getCaller()
exemplarFile := "fileWithLineNum_test.go"
exemplarLine := 9
if !strings.HasSuffix(file, exemplarFile) {
t.Errorf("should end with %s, got: %s", exemplarFile, file)
}
if line != exemplarLine {
t.Errorf("should be %d, got: %d", exemplarLine, line)
}
}
func TestFileAbsoluteFlag(t *testing.T) {
exemplar := "timber/fileWithLineNum_test.go"
result := fileWithLineNum(FlagFileAbsolute)
if !strings.Contains(result, exemplar) {
t.Errorf("should include %s, got: %s", exemplar, result)
}
}
func TestFileNameFlag(t *testing.T) {
exemplar := "fileWithLineNum_test.go"
result := fileWithLineNum(FlagFileName)
if !strings.HasPrefix(result, exemplar) {
t.Errorf("should start with %s, got: %s", exemplar, result)
}
}
func TestFileProjectFlag(t *testing.T) {
exemplar := "fileWithLineNum_test.go"
result := fileWithLineNum(FlagFileProject)
if !strings.HasPrefix(result, exemplar) {
t.Errorf("should start with %s, got: %s", exemplar, result)
}
}
func TestMissingFlags(t *testing.T) {
result := fileWithLineNum(0)
if result != "" {
t.Errorf("should be empty, got: %s", result)
}
}