forked from zyedidia/terminal
-
Notifications
You must be signed in to change notification settings - Fork 13
/
str_test.go
172 lines (167 loc) · 2.38 KB
/
str_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
package vt10x
import (
"testing"
)
func TestSTRParse(t *testing.T) {
var str strEscape
str.reset()
str.buf = []rune("0;some text")
str.parse()
if str.arg(0, 17) != 0 || str.argString(1, "") != "some text" {
t.Fatal("STR parse mismatch")
}
}
func TestParseColor(t *testing.T) {
type testCase struct {
name string
input string
r, g, b int
}
for _, tc := range []testCase{
{
"rgb 4 bit zero",
"rgb:0/0/0",
0, 0, 0,
},
{
"rgb 4 bit max",
"rgb:f/f/f",
255, 255, 255,
},
{
"rgb 4 bit values",
"rgb:1/2/3",
17, 34, 51,
},
{
"rgb 8 bit zero",
"rgb:00/00/00",
0, 0, 0,
},
{
"rgb 8 bit max",
"rgb:ff/ff/ff",
255, 255, 255,
},
{
"rgb 8 bit values",
"rgb:11/22/33",
17, 34, 51,
},
{
"rgb 12 bit zero",
"rgb:000/000/000",
0, 0, 0,
},
{
"rgb 12 bit max",
"rgb:fff/fff/fff",
255, 255, 255,
},
{
"rgb 12 bit values",
"rgb:111/222/333",
17, 34, 51,
},
{
"rgb 16 bit zero",
"rgb:0000/0000/0000",
0, 0, 0,
},
{
"rgb 16 bit max",
"rgb:ffff/ffff/ffff",
255, 255, 255,
},
{
"rgb 16 bit values",
"rgb:1111/2222/3333",
17, 34, 51,
},
{
"rgb 16 bit values",
"rgb:1111/2222/3333",
17, 34, 51,
},
{
"hash 4 bit zero",
"#000",
0, 0, 0,
},
{
"hash 4 bit max",
"#fff",
240, 240, 240,
},
{
"hash 4 bit values",
"#123",
16, 32, 48,
},
{
"hash 8 bit zero",
"#000000",
0, 0, 0,
},
{
"hash 8 bit max",
"#ffffff",
255, 255, 255,
},
{
"hash 8 bit values",
"#112233",
17, 34, 51,
},
{
"hash 12 bit zero",
"#000000000",
0, 0, 0,
},
{
"hash 12 bit max",
"#fffffffff",
255, 255, 255,
},
{
"hash 12 bit values",
"#111222333",
17, 34, 51,
},
{
"hash 16 bit zero",
"#000000000000",
0, 0, 0,
},
{
"hash 16 bit max",
"#ffffffffffff",
255, 255, 255,
},
{
"hash 16 bit values",
"#111122223333",
17, 34, 51,
},
{
"rgb upper case",
"RGB:0/A/F",
0, 170, 255,
},
{
"hash upper case",
"#FFF",
240, 240, 240,
},
} {
t.Run(tc.name, func(t *testing.T) {
r, g, b, err := parseColor(tc.input)
if err != nil {
t.Fatalf("failed to parse color: %s", err)
}
if r != tc.r || g != tc.g || b != tc.b {
t.Fatalf("expected (%d, %d, %d), got (%d, %d, %d)", tc.r, tc.g, tc.b, r, g, b)
}
})
}
}