mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
test: config: test colors.{jump-labels,scrollback-indicator}
This commit is contained in:
parent
801970aa33
commit
4873004c37
1 changed files with 52 additions and 2 deletions
|
|
@ -401,6 +401,52 @@ test_color(struct context *ctx, bool (*parse_fun)(struct context *ctx),
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_two_colors(struct context *ctx, bool (*parse_fun)(struct context *ctx),
|
||||
const char *key, bool alpha_allowed,
|
||||
uint32_t *ptr1, uint32_t *ptr2)
|
||||
{
|
||||
ctx->key = key;
|
||||
|
||||
const struct {
|
||||
const char *option_string;
|
||||
uint32_t color1;
|
||||
uint32_t color2;
|
||||
bool invalid;
|
||||
} input[] = {
|
||||
{"000000 000000", 0, 0},
|
||||
|
||||
/* No alpha */
|
||||
{"999999 888888", 0x999999, 0x888888},
|
||||
{"ffffff aaaaaa", 0xffffff, 0xaaaaaa},
|
||||
|
||||
/* Both colors have alpha component */
|
||||
{"ffffffff 00000000", 0xffffffff, 0x00000000, !alpha_allowed},
|
||||
{"aabbccdd, ee112233", 0xaabbccdd, 0xee112233, !alpha_allowed},
|
||||
|
||||
/* Only one color has alpha component */
|
||||
{"ffffffff 112233", 0xffffffff, 0x112233, !alpha_allowed},
|
||||
{"ffffff ff112233", 0x00ffffff, 0xff112233, !alpha_allowed},
|
||||
|
||||
{"unittest-invalid-color", 0, 0, true},
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < ALEN(input); i++) {
|
||||
ctx->value = input[i].option_string;
|
||||
if (input[i].invalid) {
|
||||
if (parse_fun(ctx)) {
|
||||
BUG("[%s].%s=%s: did not fail to parse as expected",
|
||||
ctx->section, ctx->key, ctx->value);
|
||||
}
|
||||
} else {
|
||||
if (!parse_fun(ctx)) {
|
||||
BUG("[%s].%s=%s: failed to parse",
|
||||
ctx->section, ctx->key, ctx->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_section_main(void)
|
||||
{
|
||||
|
|
@ -616,6 +662,12 @@ test_section_colors(void)
|
|||
test_color(&ctx, &parse_section_colors, "selection-foreground", false, &conf.colors.selection_fg);
|
||||
test_color(&ctx, &parse_section_colors, "selection-background", false, &conf.colors.selection_bg);
|
||||
test_color(&ctx, &parse_section_colors, "urls", false, &conf.colors.url);
|
||||
test_two_colors(&ctx, &parse_section_colors, "jump-labels", false,
|
||||
&conf.colors.jump_label.fg,
|
||||
&conf.colors.jump_label.bg);
|
||||
test_two_colors(&ctx, &parse_section_colors, "scrollback-indicator", false,
|
||||
&conf.colors.scrollback_indicator.fg,
|
||||
&conf.colors.scrollback_indicator.bg);
|
||||
|
||||
for (size_t i = 0; i < 255; i++) {
|
||||
char key_name[4];
|
||||
|
|
@ -627,8 +679,6 @@ test_section_colors(void)
|
|||
test_invalid_key(&ctx, &parse_section_colors, "256");
|
||||
|
||||
/* TODO: alpha (float in range 0-1, converted to uint16_t) */
|
||||
/* TODO: jump-labels (two colors) */
|
||||
/* TODO: scrollback-indicator (two colors) */
|
||||
|
||||
config_free(&conf);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue