-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansi_test.go
177 lines (174 loc) · 10 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package brimtext
import (
"testing"
)
func TestClosestANSIForeground(t *testing.T) {
for in, exp := range map[string][]byte{
"": []byte{},
"garbage": []byte{},
"#000000": ANSIEscape.FBlack,
"#5f0000": ANSIEscape.FBlack,
"#5F0000": ANSIEscape.FBlack,
"#600000": ANSIEscape.FRed,
"#ae0000": ANSIEscape.FRed,
"#Ae0000": ANSIEscape.FRed,
"#af0000": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#ff0000": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#5f5f00": ANSIEscape.FBlack,
"#605f00": ANSIEscape.FRed,
"#ae5f00": ANSIEscape.FRed,
"#af5f00": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#ff5f00": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#5f6000": ANSIEscape.FGreen,
"#606000": ANSIEscape.FYellow,
"#ae6000": ANSIEscape.FYellow,
"#af6000": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#ff6000": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#5fae00": ANSIEscape.FGreen,
"#60ae00": ANSIEscape.FYellow,
"#aeae00": ANSIEscape.FYellow,
"#afae00": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#ffae00": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#5faf00": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FGreen...),
"#60af00": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#afaf00": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#ffaf00": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#5f005f": ANSIEscape.FBlack,
"#60005f": ANSIEscape.FRed,
"#ae005f": ANSIEscape.FRed,
"#af005f": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#ff005f": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#5f0060": ANSIEscape.FBlue,
"#600060": ANSIEscape.FMagenta,
"#ae0060": ANSIEscape.FMagenta,
"#af0060": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#ff0060": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#5f00ae": ANSIEscape.FBlue,
"#6000ae": ANSIEscape.FMagenta,
"#ae00ae": ANSIEscape.FMagenta,
"#af00ae": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#ff00ae": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#5f00af": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FBlue...),
"#6000af": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#af00af": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#ff00af": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#5f6060": ANSIEscape.FCyan,
"#606060": ANSIEscape.FWhite,
"#ae6060": ANSIEscape.FWhite,
"#af6060": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#ff6060": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#5f60ae": ANSIEscape.FCyan,
"#6060ae": ANSIEscape.FWhite,
"#ae60ae": ANSIEscape.FWhite,
"#af60ae": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#ff60ae": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#5f60af": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FCyan...),
"#6060af": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#af60af": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#ff60af": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#5faf60": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FCyan...),
"#60af60": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#aeaf60": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#afaf60": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#ffaf60": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#5fafae": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FCyan...),
"#60afae": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#aeafae": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#afafae": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#ffafae": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#5fafaf": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FCyan...),
"#60afaf": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#afafaf": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#ffafaf": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#000": ANSIEscape.FBlack,
"#500": ANSIEscape.FBlack,
"#600": ANSIEscape.FRed,
"#a00": ANSIEscape.FRed,
"#A00": ANSIEscape.FRed,
"#b00": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#f00": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#550": ANSIEscape.FBlack,
"#650": ANSIEscape.FRed,
"#a50": ANSIEscape.FRed,
"#b50": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#f50": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#560": ANSIEscape.FGreen,
"#660": ANSIEscape.FYellow,
"#a60": ANSIEscape.FYellow,
"#b60": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#f60": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#5a0": ANSIEscape.FGreen,
"#6a0": ANSIEscape.FYellow,
"#aa0": ANSIEscape.FYellow,
"#ba0": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#fa0": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#5b0": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FGreen...),
"#6b0": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#bb0": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#fb0": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FYellow...),
"#505": ANSIEscape.FBlack,
"#605": ANSIEscape.FRed,
"#a05": ANSIEscape.FRed,
"#b05": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#f05": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FRed...),
"#506": ANSIEscape.FBlue,
"#606": ANSIEscape.FMagenta,
"#a06": ANSIEscape.FMagenta,
"#b06": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#f06": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#50a": ANSIEscape.FBlue,
"#60a": ANSIEscape.FMagenta,
"#a0a": ANSIEscape.FMagenta,
"#b0a": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#f0a": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#50b": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FBlue...),
"#60b": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#b0b": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#f0b": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FMagenta...),
"#566": ANSIEscape.FCyan,
"#666": ANSIEscape.FWhite,
"#a66": ANSIEscape.FWhite,
"#b66": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#f66": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#56a": ANSIEscape.FCyan,
"#66a": ANSIEscape.FWhite,
"#a6a": ANSIEscape.FWhite,
"#b6a": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#f6a": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#56b": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FCyan...),
"#66b": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#b6b": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#f6b": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#5b6": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FCyan...),
"#6b6": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#ab6": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#bb6": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#fb6": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#5ba": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FCyan...),
"#6ba": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#aba": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#bba": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#fba": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#5bb": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FCyan...),
"#6bb": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#bbb": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
"#fbb": append(append(make([]byte, 0), ANSIEscape.Bold...), ANSIEscape.FWhite...),
} {
out := ClosestANSIForegroundString(in)
if string(out) != string(exp) {
t.Errorf("ClosestANSIForeground(%#v) %#v != %#v", in, out, exp)
}
}
}
func TestStripANSIEscapes(t *testing.T) {
for in, exp := range map[string]string{
"link": "link",
"link\x1bstuffm": "link",
"link\x1bstuffmandmore": "linkandmore",
} {
out := StripANSIEscapes(in)
if out != exp {
t.Errorf("StripANSIEscapes(%q) %q != %q", in, out, exp)
}
}
}