-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathescape_state_test.go
More file actions
46 lines (41 loc) · 848 Bytes
/
escape_state_test.go
File metadata and controls
46 lines (41 loc) · 848 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
package text
import "testing"
func TestEscapeState(t *testing.T) {
cases := []struct {
input string
output string
}{
{
"Format: ",
"",
},
{
"\x1b[1;2;3;4;5;7;8;9;33;43m",
"\x1b[1;2;3;4;5;7;8;9;33;43m",
},
{
"baaar\x1b[48;5;118mfoobar\x1b[38;5;100m",
"\x1b[38;5;100;48;5;118m",
},
{
"baaar\x1b[48;2;118;131;193mfoobar\x1b[38;2;255;255;250mfooooo",
"\x1b[38;2;255;255;250;48;2;118;131;193m",
},
{
// broken color
"\x1b[48m",
"",
},
}
for i, tc := range cases {
t.Run(tc.input, func(t *testing.T) {
es := &EscapeState{}
es.Witness(tc.input)
result := es.FormatString()
if result != tc.output {
t.Fatalf("Case %d Input:\n\n`%s`\n\nExpected Output:\n\n`%s`\n\nActual Output:\n\n`%s`",
i, tc.input, tc.output, result)
}
})
}
}