aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2022-07-27 17:13:39 +0000
committerDaniel Eklöf <daniel@ekloef.se>2022-07-28 17:02:55 +0000
commit4873004c379f9f06babd65ffc65ba4f99fa62906 (patch)
tree9bb839ce24ee50059a9c3a0bf72686465a54df7d
parentinput: kitty: always treat composed characters as ‘printable’ (diff)
test: config: test colors.{jump-labels,scrollback-indicator}
-rw-r--r--tests/test-config.c54
1 files changed, 52 insertions, 2 deletions
diff --git a/tests/test-config.c b/tests/test-config.c
index 874f5b05..5a7cda63 100644
--- a/tests/test-config.c
+++ b/tests/test-config.c
@@ -402,6 +402,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)
{
struct config conf = {0};
@@ -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);
}