-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
color_test.go
64 lines (59 loc) · 1.03 KB
/
color_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
package termenv
import "testing"
func TestXTermColor(t *testing.T) {
var tests = []struct {
input string
color RGBColor
valid bool
}{
{
"\033]11;rgb:fafa/fafa/fafa\033",
RGBColor("#fafafa"),
true,
},
{
"\033]11;rgb:fafa/fafa/fafa\033\\",
RGBColor("#fafafa"),
true,
},
{
"\033]11;rgb:1212/3434/5656\a",
RGBColor("#123456"),
true,
},
{
"\033]11;foo:fafa/fafa/fafaZZ",
"",
false,
},
{
"\033]11;rgb:fafa/fafa",
"",
false,
},
{
"\033]11;rgb:fafa/fafa/fafaY",
"",
false,
},
{
"\033]11;rgb:fafa/fafa/fafaZZ",
"",
false,
},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
color, err := xTermColor(test.input)
if err != nil && test.valid {
t.Fatalf("unexpected error for input %q: %v", test.input, err)
}
if err == nil && !test.valid {
t.Fatalf("expected error for input %v not found", test.input)
}
if color != test.color {
t.Fatalf("wrong color returned, want %v, got %v", test.color, color)
}
})
}
}