-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencode_source_test.go
More file actions
52 lines (47 loc) · 903 Bytes
/
encode_source_test.go
File metadata and controls
52 lines (47 loc) · 903 Bytes
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 zlog
import (
"log/slog"
"testing"
"github.com/icefed/zlog/buffer"
)
func TestFormatSourceValue(t *testing.T) {
tests := []struct {
name string
source slog.Source
want string
}{
{
name: "multi level path",
source: slog.Source{
File: "logtest/source/value/test.go",
Line: 12,
},
want: "value/test.go:12",
}, {
name: "two level path",
source: slog.Source{
File: "value/test2.go",
Line: 15,
},
want: "value/test2.go:15",
}, {
name: "single file",
source: slog.Source{
File: "test3.go",
Line: 20,
},
want: "test3.go:20",
},
}
buf := buffer.New()
defer buf.Free()
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
formatSourceValue(buf, &test.source)
if string(buf.Bytes()) != test.want {
t.Errorf("got %v, want %v", string(buf.Bytes()), test.want)
}
buf.Reset()
})
}
}