-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcolorizer_test.go
71 lines (53 loc) · 1.26 KB
/
colorizer_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
package main
import (
"bytes"
"strings"
"testing"
"github.com/ujiro99/logcatf/logcat"
)
func TestRun_ReplaceColorCode(t *testing.T) {
before := "%t [blue] %m"
expect := "%t [LOGCATF_blue] %m"
f := Colorizer{}
after := f.ReplaceColorCode(before)
if after != expect {
t.Errorf("\nexpect: %s\nresult: %s", expect, after)
}
}
func TestRun_Fprintln_enable(t *testing.T) {
format := "%t %p [_blue_]%m"
expect := "\033[31m%t %p \033[44m%m"
item := logcat.Entry{
"time": "12-28 19:01:14.073",
"priority": "F",
"message": "logcat_message",
}
w := new(bytes.Buffer)
f := Colorizer{}
cc := ColorConfig{}
f.Init(true, cc)
format = f.ReplaceColorCode(format)
f.Fprintln(w, format, item)
res := w.String()
if !strings.Contains(res, expect) {
t.Errorf("\nexpect: %s\nresult: %s", expect, res)
}
}
func TestRun_Fprintln_disable(t *testing.T) {
format := "%t %p [blue]%m"
expect := "%t %p %m"
item := logcat.Entry{
"time": "12-28 19:01:14.073",
"priority": "F",
"message": "logcat_message",
}
w := new(bytes.Buffer)
f := Colorizer{}
f.Init(false, nil)
format = f.ReplaceColorCode(format)
f.Fprintln(w, format, item)
res := w.String()
if !strings.Contains(res, expect) {
t.Errorf("\nexpect: %s\nresult: %s", expect, res)
}
}