forked from hound-search/hound
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathansi_test.go
88 lines (77 loc) · 1.94 KB
/
ansi_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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package ansi
import (
"fmt"
"os"
"strings"
"testing"
)
var (
printTests = false
)
func makeReal(s string) string {
return strings.Replace(s, "~", "\x1b", -1)
}
func makeFake(s string) string {
return strings.Replace(s, "\x1b", "~", -1)
}
func assertEqual(t *testing.T, got string, exp string) {
if printTests {
fmt.Println(got)
}
exp = strings.Replace(exp, "~", "\x1b", -1)
if got != exp {
t.Errorf("mismatch: %s & %s", makeFake(got), makeFake(exp))
}
}
func TestEnabled(t *testing.T) {
a := Colorer{true}
assertEqual(t,
a.FgBg("x", Black, Normal, Colorless, Normal),
"~[30mx~[0m")
assertEqual(t,
a.FgBg("x", Red, Normal, Colorless, Normal),
"~[31mx~[0m")
assertEqual(t,
a.FgBg("x", Red, Intense, Colorless, Normal),
"~[91mx~[0m")
assertEqual(t,
a.FgBg("x", Green, Bold|Blink|Underline|Invert, Colorless, Normal),
"~[1;5;4;7;32mx~[0m")
assertEqual(t,
a.FgBg("x", Green, Bold|Blink|Underline|Invert|Intense, Colorless, Normal),
"~[1;5;4;7;92mx~[0m")
assertEqual(t,
a.FgBg("x", Green, Bold|Blink|Underline|Intense, Magenta, Normal),
"~[1;5;4;92;45mx~[0m")
assertEqual(t,
a.FgBg("x", Yellow, Bold|Blink|Underline|Intense, Cyan, Intense),
"~[1;5;4;93;106mx~[0m")
}
func TestDisabled(t *testing.T) {
a := Colorer{false}
assertEqual(t,
a.FgBg("x", Black, Normal, Colorless, Normal),
"x")
assertEqual(t,
a.FgBg("foo", Red, Normal, Colorless, Normal),
"foo")
assertEqual(t,
a.FgBg("butter", Red, Intense, Colorless, Normal),
"butter")
assertEqual(t,
a.FgBg("x", Green, Bold|Blink|Underline|Invert, Colorless, Normal),
"x")
assertEqual(t,
a.FgBg("x", Green, Bold|Blink|Underline|Invert|Intense, Colorless, Normal),
"x")
assertEqual(t,
a.FgBg("x", Green, Bold|Blink|Underline|Intense, Magenta, Normal),
"x")
assertEqual(t,
a.FgBg("x", Yellow, Bold|Blink|Underline|Intense, Cyan, Intense),
"x")
}
func TestIsTerminal(t *testing.T) {
// just make sure we can call this thing.
isTTY(os.Stdout.Fd())
}