Skip to content

Commit 25bb856

Browse files
committed
Add colored examples to test descriptions
Signed-off-by: Thomas Lauf <[email protected]>
1 parent 5cb49e6 commit 25bb856

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

test/color.t.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ int main (int, char**)
118118
{
119119
snprintf (color, 24, "color%d", i);
120120
snprintf (codes, 64, "\033[38;5;%dmfoo\033[0m", i);
121-
snprintf (description, 64, "color%d -> ^[[38;5;%dm", i, i);
121+
snprintf (description, 64, "\033[38;5;%dmfoo\033[0m: color%d -> ^[[38;5;%dm", i, i, i);
122122

123123
t.is (Color::colorize ("foo", color), std::string (codes), description);
124124
}
@@ -127,7 +127,7 @@ int main (int, char**)
127127
{
128128
snprintf (color, 24, "on color%d", i);
129129
snprintf (codes, 64, "\033[48;5;%dmfoo\033[0m", i);
130-
snprintf (description, 64, "on color%d -> ^[[48;5;%dm", i, i);
130+
snprintf (description, 64, "\033[48;5;%dmfoo\033[0m: on color%d -> ^[[48;5;%dm", i, i, i);
131131

132132
t.is (Color::colorize ("foo", color), std::string (codes), description);
133133
}
@@ -140,7 +140,7 @@ int main (int, char**)
140140
int code = 16 + (r*36 + g*6 + b);
141141
snprintf (color, 24, "rgb%d%d%d", r, g, b);
142142
snprintf (codes, 64, "\033[38;5;%dmfoo\033[0m", code);
143-
snprintf (description, 64, "rgb%d%d%d -> ^[[38;5;%dm", r, g, b, code);
143+
snprintf (description, 64, "\033[38;5;%dmfoo\033[0m: rgb%d%d%d -> ^[[38;5;%dm", code, r, g, b, code);
144144

145145
t.is (Color::colorize ("foo", color), std::string (codes), description);
146146
}
@@ -152,20 +152,20 @@ int main (int, char**)
152152
int code = 16 + (r*36 + g*6 + b);
153153
snprintf (color, 24, "on rgb%d%d%d", r, g, b);
154154
snprintf (codes, 64, "\033[48;5;%dmfoo\033[0m", code);
155-
snprintf (description, 64, "on rgb%d%d%d -> ^[[48;5;%dm", r, g, b, code);
155+
snprintf (description, 64, "\033[48;5;%dmfoo\033[0m: on rgb%d%d%d -> ^[[48;5;%dm", code, r, g, b, code);
156156

157157
t.is (Color::colorize ("foo", color), std::string (codes), description);
158158
}
159159

160160
// 256-color, grays.
161161
// grey == gray.
162-
t.is (Color::colorize ("foo", "grey0"), std::string ("\033[38;5;232mfoo\033[0m"), "grey0 -> ^[[38;5;232m");
162+
t.is (Color::colorize ("foo", "grey0"), std::string ("\033[38;5;232mfoo\033[0m"), "\033[38;5;232mfoo\033[0m: grey0 -> ^[[38;5;232m");
163163

164164
for (int i = 0; i < 24; ++i)
165165
{
166166
snprintf (color, 24, "gray%d", i);
167167
snprintf (codes, 64, "\033[38;5;%dmfoo\033[0m", i + 232);
168-
snprintf (description, 64, "gray%d -> ^[[38;5;%dm", i + 232, i + 232);
168+
snprintf (description, 64, "\033[38;5;%dmfoo\033[0m: gray%d -> ^[[38;5;%dm", i + 232, i, i + 232);
169169

170170
t.is (Color::colorize ("foo", color), std::string (codes), description);
171171
}
@@ -174,19 +174,19 @@ int main (int, char**)
174174
{
175175
snprintf (color, 24, "on gray%d", i);
176176
snprintf (codes, 64, "\033[48;5;%dmfoo\033[0m", i + 232);
177-
snprintf (description, 64, "on gray%d -> ^[[48;5;%dm", i + 232, i + 232);
177+
snprintf (description, 64, "\033[48;5;%dmfoo\033[0m: on gray%d -> ^[[48;5;%dm", i + 232, i, i + 232);
178178

179179
t.is (Color::colorize ("foo", color), std::string (codes), description);
180180
}
181181

182182
// 24-bit color
183-
t.is (Color::colorize ("foo", "0x0a1b2c"), std::string ("\033[38;2;10;27;44mfoo\033[0m"), "0x0a1b2c -> ^[[38;2;10;27;44m");
184-
t.is (Color::colorize ("foo", "0x0a1b2c on color127"), std::string ("\033[38;2;10;27;44;48;2;126;0;126mfoo\033[0m"), "0x0a1b2c on color127 -> ^[[38;2;10;27;44;48;2;126;0;126m");
185-
t.is (Color::colorize ("foo", "red on 0x0a1b2c"), std::string ("\033[38;2;128;0;0;48;2;10;27;44mfoo\033[0m"), "red on 0x0a1b2c -> ^[[38;2;128;0;0;48;2;10;27;44m");
186-
t.is (Color::colorize ("foo", "bold red on 0x0a1b2c"), std::string ("\033[1;38;2;128;0;0;48;2;10;27;44mfoo\033[0m"), "bold on 0x0a1b2c -> ^[[1;38;2;255;0;0;48;2;10;27;44m");
187-
t.is (Color::colorize ("foo", "0x0a1b2c on bright red"), std::string ("\033[38;2;10;27;44;48;2;255;0;0mfoo\033[0m"), "0x0a1b2c on bright red -> ^[[38;2;10;27;44;48;2;255;0;0m");
188-
t.is (Color::colorize ("foo", "0x010101 on grey0"), std::string ("\033[38;2;1;1;1;48;2;10;10;10mfoo\033[0m"), "0x0101010 on grey0 -> ^[[38;2;1;1;1;48;2;10;10;10m");
189-
t.is (Color::colorize ("foo", "0x101010 on grey23"), std::string ("\033[38;2;16;16;16;48;2;240;240;240mfoo\033[0m"), "0x101010 on grey23 -> ^[[38;2;16;16;16;48;2;240;240;240m");
183+
t.is (Color::colorize ("foo", "0x0a1b2c"), std::string ("\033[38;2;10;27;44mfoo\033[0m"), std::string("\033[38;2;10;27;44mfoo\033[0m: ") + "0x0a1b2c -> ^[[38;2;10;27;44m");
184+
t.is (Color::colorize ("foo", "0x0a1b2c on color127"), std::string ("\033[38;2;10;27;44;48;2;126;0;126mfoo\033[0m"), std::string("\033[38;2;10;27;44;48;2;126;0;126mfoo\033[0m: ") + "0x0a1b2c on color127 -> ^[[38;2;10;27;44;48;2;126;0;126m");
185+
t.is (Color::colorize ("foo", "red on 0x0a1b2c"), std::string ("\033[38;2;128;0;0;48;2;10;27;44mfoo\033[0m"), std::string("\033[38;2;128;0;0;48;2;10;27;44mfoo\033[0m: ") + "red on 0x0a1b2c -> ^[[38;2;128;0;0;48;2;10;27;44m");
186+
t.is (Color::colorize ("foo", "bold red on 0x0a1b2c"), std::string ("\033[1;38;2;128;0;0;48;2;10;27;44mfoo\033[0m"), std::string("\033[1;38;2;128;0;0;48;2;10;27;44mfoo\033[0m: ") + "bold on 0x0a1b2c -> ^[[1;38;2;255;0;0;48;2;10;27;44m");
187+
t.is (Color::colorize ("foo", "0x0a1b2c on bright red"), std::string ("\033[38;2;10;27;44;48;2;255;0;0mfoo\033[0m"), std::string("\033[38;2;10;27;44;48;2;255;0;0mfoo\033[0m: ") + "0x0a1b2c on bright red -> ^[[38;2;10;27;44;48;2;255;0;0m");
188+
t.is (Color::colorize ("foo", "0x010101 on grey0"), std::string ("\033[38;2;1;1;1;48;2;10;10;10mfoo\033[0m"), std::string("\033[38;2;1;1;1;48;2;10;10;10mfoo\033[0m: ") + "0x010101 on grey0 -> ^[[38;2;1;1;1;48;2;10;10;10m");
189+
t.is (Color::colorize ("foo", "0x101010 on grey23"), std::string ("\033[38;2;16;16;16;48;2;240;240;240mfoo\033[0m"), std::string("\033[38;2;16;16;16;48;2;240;240;240mfoo\033[0m: ") + "0x101010 on grey23 -> ^[[38;2;16;16;16;48;2;240;240;240m");
190190

191191
// std::string Color::strip (const std::string&);
192192
t.is (Color::strip (""), "", "Color::strip '' -> ''");

0 commit comments

Comments
 (0)