aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authoruser <user@clank>2026-08-17 14:22:38 +0200
committeruser <user@clank>2026-08-17 14:22:38 +0200
commitec91ccffe631ae34b111bf6161fd0e3c487f684c (patch)
tree4a9fdbb720d9bf03edd5f538d1d87afd2bf51bfb /tests
parentsl0ppty: clang-format, and a hook that runs it on what you staged (diff)
downloadslosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.tar.gz
slosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.tar.xz
slosh-ec91ccffe631ae34b111bf6161fd0e3c487f684c.zip
sl0ppty: clang-format the tree
The bumpy one. `make fmt` over every `.c` and `.h` outside `vendor/`: 32 files, 1,843 lines rewritten, no behaviour changed. Nothing here is worth reading -- the next commit adds it to `.git-blame-ignore-revs` so `git blame` walks past it. Two thirds of it is alignment the formatter now owns: trailing comments in a struct, continuation lines under a signature. The rest is the hand-packed tables opening up to one entry per line -- `ACTIONS`, `NAMED_KEYS`, `ACTION_HELP`. That is a real loss of density and a real gain in diffs: adding an action was a reflow of the block and is now one line. Anything worth keeping packed can be fenced with `// clang-format off`; nothing was, on the grounds that a table is the thing a formatter is for. **One change is not formatting.** `src/config.h` had three trailing comments glued onto one field: uint16_t hover_delay_ms; /* how long the pointer must rest to arm a guide */ /* how long an announcement stays up */ /* rows per wheel notch */ -- `toast_ms`'s and `scroll_lines`' comments, landed on their neighbour by an earlier edit, documenting the wrong things ever since. It is in this commit because it is what caught it: clang-format could not settle on that line, wrapping it one way and then re-indenting the wrap on a second pass, so `make fmt` was not idempotent. The comments are back where they belong and it is. Verified after the reformat, not before: `make clean && make all` is warning-free, `make retest` is 1801 checks green, and `make fmt` twice in a row changes nothing the second time. A formatter that alters behaviour would be worse than none, so the gate was the whole suite rather than a reading of the diff.
Diffstat (limited to 'tests')
-rw-r--r--tests/expr_test.c27
-rw-r--r--tests/input_test.c13
-rw-r--r--tests/kdl_test.c43
-rw-r--r--tests/shader_test.c63
4 files changed, 90 insertions, 56 deletions
diff --git a/tests/expr_test.c b/tests/expr_test.c
index f775065..19968d1 100644
--- a/tests/expr_test.c
+++ b/tests/expr_test.c
@@ -21,9 +21,16 @@ static int at(const char *src, int x, int y) {
snprintf(detail, sizeof detail, "%s: %s", src, err);
return -99999;
}
- expr_env_t env = {.x = x, .y = y, .cols = 80, .rows = 24,
- .curx = 10, .cury = 5, .cursor = 1, .focused = 1,
- .t = 1000, .since = 250};
+ expr_env_t env = {.x = x,
+ .y = y,
+ .cols = 80,
+ .rows = 24,
+ .curx = 10,
+ .cury = 5,
+ .cursor = 1,
+ .focused = 1,
+ .t = 1000,
+ .since = 250};
int v = expr_eval(p, &env);
expr_free(p);
return v;
@@ -31,7 +38,8 @@ static int at(const char *src, int x, int y) {
static void eq(const char *src, int want) {
int got = at(src, 3, 4);
- if (got != want) snprintf(detail, sizeof detail, "%s -> %d, wanted %d", src, got, want);
+ if (got != want)
+ snprintf(detail, sizeof detail, "%s -> %d, wanted %d", src, got, want);
ok(src, got == want, detail);
}
@@ -196,11 +204,15 @@ int main(void) {
printf("\n-- dependencies are derived from the source, not declared\n");
{
- struct { const char *src; unsigned want; } cases[] = {
+ struct {
+ const char *src;
+ unsigned want;
+ } cases[] = {
{"128", 0},
{"x * 2", EXPR_DEP_POS},
{"y", EXPR_DEP_POS},
- {"cols / 2", EXPR_DEP_SIZE}, /* not constant: the rect is not known yet */
+ {"cols / 2",
+ EXPR_DEP_SIZE}, /* not constant: the rect is not known yet */
{"dist(x, y, curx, cury)", EXPR_DEP_POS | EXPR_DEP_CURSOR},
{"focused * 90", EXPR_DEP_FOCUS},
{"t % 1000", EXPR_DEP_TIME},
@@ -282,7 +294,8 @@ int main(void) {
* than accepted and run forever. */
char big[4096];
size_t n = 0;
- for (int i = 0; i < 200; i++) n += (size_t)snprintf(big + n, sizeof big - n, "1+");
+ for (int i = 0; i < 200; i++)
+ n += (size_t)snprintf(big + n, sizeof big - n, "1+");
snprintf(big + n, sizeof big - n, "1");
char err[128] = {0};
expr_prog_t *p = expr_compile(big, err, sizeof err);
diff --git a/tests/input_test.c b/tests/input_test.c
index 7863c21..dec460e 100644
--- a/tests/input_test.c
+++ b/tests/input_test.c
@@ -71,7 +71,10 @@ int main(void) {
/* escape and alt */
T("bare esc resolves on timeout", "\x1b", "key ESCAPE mods=- press");
- T("alt-a", "\x1b" "a", "key a mods=A press text=a");
+ T("alt-a",
+ "\x1b"
+ "a",
+ "key a mods=A press text=a");
T("alt-ctrl-a", "\x1b\x01", "key a mods=CA press");
/* legacy CSI */
@@ -116,8 +119,12 @@ int main(void) {
expect_split("split CSI", "\x1b[1;5A", 6, 3, "key ARROW_UP mods=C press");
expect_split("split utf8", "\xf0\x9f\x92\x80", 4, 2,
"key UNIDENTIFIED mods=- press text=\xf0\x9f\x92\x80");
- expect_split("split paste", "\x1b[200~hi\x1b[201~", 14, 8, "paste len=2 text=hi");
- expect_split("esc then key is alt", "\x1b" "b", 2, 1, "key b mods=A press text=b");
+ expect_split("split paste", "\x1b[200~hi\x1b[201~", 14, 8,
+ "paste len=2 text=hi");
+ expect_split("esc then key is alt",
+ "\x1b"
+ "b",
+ 2, 1, "key b mods=A press text=b");
printf("\n%s (%d failures)\n", fails ? "FAILED" : "all green", fails);
return fails ? 1 : 0;
diff --git a/tests/kdl_test.c b/tests/kdl_test.c
index 425af8f..ca3ed0e 100644
--- a/tests/kdl_test.c
+++ b/tests/kdl_test.c
@@ -19,18 +19,17 @@ int main(void) {
char err[256];
{
- const char *doc =
- "// a comment\n"
- "gap 1\n"
- "rounded true\n"
- "title \"hello world\"\n"
- "min_pane cols=24 rows=6\n"
- "/* block\n comment */\n"
- "theme {\n"
- " frame_focus \"#ff5fd7\"\n"
- " nested { deep \"value\" }\n"
- "}\n"
- "oneline { a \"1\"; b \"2\" }\n";
+ const char *doc = "// a comment\n"
+ "gap 1\n"
+ "rounded true\n"
+ "title \"hello world\"\n"
+ "min_pane cols=24 rows=6\n"
+ "/* block\n comment */\n"
+ "theme {\n"
+ " frame_focus \"#ff5fd7\"\n"
+ " nested { deep \"value\" }\n"
+ "}\n"
+ "oneline { a \"1\"; b \"2\" }\n";
kdl_node_t *root = kdl_parse(doc, err, sizeof err);
ok("a document parses", root != NULL, err);
if (!root) return 1;
@@ -39,17 +38,21 @@ int main(void) {
ok("boolean argument", kdl_arg_bool(top(root, "rounded"), 0, false), "");
ok("quoted string with a space",
strcmp(kdl_arg(top(root, "title"), 0, ""), "hello world") == 0, "");
- ok("properties", kdl_prop_int(top(root, "min_pane"), "cols", 0) == 24 &&
- kdl_prop_int(top(root, "min_pane"), "rows", 0) == 6, "");
+ ok("properties",
+ kdl_prop_int(top(root, "min_pane"), "cols", 0) == 24 &&
+ kdl_prop_int(top(root, "min_pane"), "rows", 0) == 6,
+ "");
ok("comments are skipped", top(root, "gap") && top(root, "theme"), "");
const kdl_node_t *theme = top(root, "theme");
ok("children", theme && theme->nkids == 2, "");
ok("child values",
- strcmp(kdl_arg(kdl_child(theme, "frame_focus"), 0, ""), "#ff5fd7") == 0, "");
+ strcmp(kdl_arg(kdl_child(theme, "frame_focus"), 0, ""), "#ff5fd7") == 0,
+ "");
ok("nesting",
strcmp(kdl_arg(kdl_child(kdl_child(theme, "nested"), "deep"), 0, ""),
- "value") == 0, "");
+ "value") == 0,
+ "");
const kdl_node_t *one = top(root, "oneline");
ok("semicolons separate single-line children", one && one->nkids == 2,
@@ -61,14 +64,14 @@ int main(void) {
/* Escapes, and the fork's hard-won lesson that a single-line node without
* a terminator is a parse error rather than a silent surprise. */
kdl_node_t *root = kdl_parse("a \"x\\ty\\nz\\\"q\"\n", err, sizeof err);
- ok("string escapes", root && strcmp(kdl_arg(top(root, "a"), 0, ""),
- "x\ty\nz\"q") == 0, err);
+ ok("string escapes",
+ root && strcmp(kdl_arg(top(root, "a"), 0, ""), "x\ty\nz\"q") == 0, err);
kdl_free(root);
}
{
- kdl_node_t *root = kdl_parse("keys {\n bind \"ctrl+a\" \"quit\"\n", err,
- sizeof err);
+ kdl_node_t *root =
+ kdl_parse("keys {\n bind \"ctrl+a\" \"quit\"\n", err, sizeof err);
ok("an unclosed block is an error, with a line number",
root == NULL && strstr(err, "line") != NULL, err);
kdl_free(root);
diff --git a/tests/shader_test.c b/tests/shader_test.c
index 872ff99..6a31187 100644
--- a/tests/shader_test.c
+++ b/tests/shader_test.c
@@ -22,8 +22,10 @@ static bool ceq(color_t c, uint8_t r, uint8_t g, uint8_t b) {
static char detail[256];
static const char *shown(color_t c) {
- if (!c.set) snprintf(detail, sizeof detail, "(unset)");
- else snprintf(detail, sizeof detail, "#%02x%02x%02x", c.r, c.g, c.b);
+ if (!c.set)
+ snprintf(detail, sizeof detail, "(unset)");
+ else
+ snprintf(detail, sizeof detail, "#%02x%02x%02x", c.r, c.g, c.b);
return detail;
}
@@ -108,10 +110,10 @@ int main(void) {
!shader_make(&sh, "bloom", (color_t){0}, 0), "");
ok("a NULL kind is refused", !shader_make(&sh, NULL, (color_t){0}, 0), "");
- ok("vignette is a built-in",
- shader_make(&sh, "vignette", (color_t){0}, 0), "");
- ok("gradient is a built-in",
- shader_make(&sh, "gradient", (color_t){0}, 0), "");
+ ok("vignette is a built-in", shader_make(&sh, "vignette", (color_t){0}, 0),
+ "");
+ ok("gradient is a built-in", shader_make(&sh, "gradient", (color_t){0}, 0),
+ "");
ok("zebra is a built-in", shader_make(&sh, "zebra", (color_t){0}, 0), "");
ok("ruler is a built-in", shader_make(&sh, "ruler", (color_t){0}, 0), "");
ok("margin is a built-in", shader_make(&sh, "margin", (color_t){0}, 0), "");
@@ -128,7 +130,8 @@ int main(void) {
screen_init(&s, 4, 2);
put(&s, 0, 0, rgb(0x80, 0x80, 0x80), rgb(0x40, 0x40, 0x40));
run1(&s, "dim", (color_t){0}, 0);
- ok("amount 0 is the identity", ceq(screen_at(&s, 0, 0)->fg, 0x80, 0x80, 0x80),
+ ok("amount 0 is the identity",
+ ceq(screen_at(&s, 0, 0)->fg, 0x80, 0x80, 0x80),
shown(screen_at(&s, 0, 0)->fg));
screen_free(&s);
@@ -178,7 +181,8 @@ int main(void) {
put(&s, 0, 0, rgb(0x00, 0x00, 0x00), rgb(0x00, 0x00, 0x00));
run1(&s, "tint", rgb(0xff, 0x00, 0x00), 255);
ok("a full tint reaches the target colour",
- ceq(screen_at(&s, 0, 0)->fg, 0xff, 0, 0), shown(screen_at(&s, 0, 0)->fg));
+ ceq(screen_at(&s, 0, 0)->fg, 0xff, 0, 0),
+ shown(screen_at(&s, 0, 0)->fg));
screen_free(&s);
screen_init(&s, 4, 2);
@@ -255,7 +259,8 @@ int main(void) {
shader_t sh;
shader_make(&sh, "dim", (color_t){0}, 255);
shade_ctx_t base = base_ctx();
- shade_apply(&s, &sh, 1, (rect_t){2, 1, 4, 2}, NULL, &base); /* an inset rect */
+ shade_apply(&s, &sh, 1, (rect_t){2, 1, 4, 2}, NULL,
+ &base); /* an inset rect */
ok("a cell inside the rect is shaded",
ceq(screen_at(&s, 2, 1)->fg, 0, 0, 0), shown(screen_at(&s, 2, 1)->fg));
@@ -311,8 +316,8 @@ int main(void) {
shader_make(&twice[0], "dim", (color_t){0}, 128);
shader_make(&twice[1], "dim", (color_t){0}, 128);
shade_apply(&s, twice, 2, (rect_t){0, 0, 2, 1}, NULL, &base);
- ok("two half-dims are darker than one",
- screen_at(&s, 0, 0)->fg.r < 0x70, shown(screen_at(&s, 0, 0)->fg));
+ ok("two half-dims are darker than one", screen_at(&s, 0, 0)->fg.r < 0x70,
+ shown(screen_at(&s, 0, 0)->fg));
screen_free(&s);
}
@@ -365,7 +370,8 @@ int main(void) {
* default colours before honouring that -- so a chain like `focused * 200`
* repainted the frame of the pane it was leaving alone. */
ok("and a default-coloured cell is left saying so",
- screen_at(&s, 0, 0)->fg.set == false && screen_at(&s, 0, 0)->bg.set == false,
+ screen_at(&s, 0, 0)->fg.set == false &&
+ screen_at(&s, 0, 0)->bg.set == false,
"an identity pass materialised the terminal's default into ours");
screen_free(&s);
}
@@ -383,8 +389,8 @@ int main(void) {
rect_t hole = {1, 1, 4, 3};
shade_apply(&s, &sh, 1, (rect_t){0, 0, 6, 5}, &hole, &base);
- ok("a hole leaves the ring, and only the ring", probe.calls == 6 * 5 - 4 * 3,
- "");
+ ok("a hole leaves the ring, and only the ring",
+ probe.calls == 6 * 5 - 4 * 3, "");
ok("a cell inside the hole is not visited at all",
ceq(screen_at(&s, 2, 2)->bg, 0xff, 0xff, 0xff),
shown(screen_at(&s, 2, 2)->bg));
@@ -422,7 +428,8 @@ int main(void) {
memset(&probe, 0, sizeof probe);
rect_t over = {2, 0, 10, 10};
shade_apply(&s, &sh, 1, (rect_t){0, 0, 4, 2}, &over, &base);
- ok("a hole larger than the rect is clipped to it", probe.calls == 2 * 2, "");
+ ok("a hole larger than the rect is clipped to it", probe.calls == 2 * 2,
+ "");
screen_free(&s);
}
@@ -438,7 +445,8 @@ int main(void) {
sh.channels = SHADE_FG;
shade_apply(&s, &sh, 1, (rect_t){0, 0, 2, 1}, NULL, &base);
ok("channel fg tints the foreground",
- ceq(screen_at(&s, 0, 0)->fg, 0xff, 0, 0), shown(screen_at(&s, 0, 0)->fg));
+ ceq(screen_at(&s, 0, 0)->fg, 0xff, 0, 0),
+ shown(screen_at(&s, 0, 0)->fg));
ok("...and puts the background back",
ceq(screen_at(&s, 0, 0)->bg, 0x20, 0x20, 0x20),
shown(screen_at(&s, 0, 0)->bg));
@@ -447,7 +455,8 @@ int main(void) {
sh.channels = SHADE_BG;
shade_apply(&s, &sh, 1, (rect_t){0, 0, 2, 1}, NULL, &base);
ok("channel bg tints the background",
- ceq(screen_at(&s, 0, 0)->bg, 0xff, 0, 0), shown(screen_at(&s, 0, 0)->bg));
+ ceq(screen_at(&s, 0, 0)->bg, 0xff, 0, 0),
+ shown(screen_at(&s, 0, 0)->bg));
ok("...and leaves the foreground",
ceq(screen_at(&s, 0, 0)->fg, 0x40, 0x40, 0x40),
shown(screen_at(&s, 0, 0)->fg));
@@ -486,7 +495,8 @@ int main(void) {
ok("the centre is untouched", fg_at(&s, 20, 10) == 0xff,
shown(screen_at(&s, 20, 10)->fg));
ok("a corner is the darkest point",
- fg_at(&s, 0, 0) < fg_at(&s, 10, 5) && fg_at(&s, 10, 5) < fg_at(&s, 20, 10),
+ fg_at(&s, 0, 0) < fg_at(&s, 10, 5) &&
+ fg_at(&s, 10, 5) < fg_at(&s, 20, 10),
shown(screen_at(&s, 0, 0)->fg));
ok("it is symmetric left to right", fg_at(&s, 0, 10) == fg_at(&s, 40, 10),
"");
@@ -498,8 +508,7 @@ int main(void) {
* times further by the maths and much darker — so this equality is the
* whole proof that the falloff is round in cells rather than in columns. */
ok("a row counts double, so the falloff is round on screen",
- fg_at(&s, 20, 0) == fg_at(&s, 0, 10),
- shown(screen_at(&s, 20, 0)->fg));
+ fg_at(&s, 20, 0) == fg_at(&s, 0, 10), shown(screen_at(&s, 20, 0)->fg));
screen_free(&s);
}
@@ -590,8 +599,8 @@ int main(void) {
ok("and so is everything inside the radius", fg_at(&s, 24, 10) == 0xff, "");
ok("just past the radius the light has begun to fall away",
fg_at(&s, 26, 10) < 0xff, shown(screen_at(&s, 26, 10)->fg));
- ok("and keeps falling with distance",
- fg_at(&s, 26, 10) > fg_at(&s, 28, 10), "");
+ ok("and keeps falling with distance", fg_at(&s, 26, 10) > fg_at(&s, 28, 10),
+ "");
ok("the falloff is a ramp, not an edge",
fg_at(&s, 25, 10) > fg_at(&s, 27, 10) &&
fg_at(&s, 27, 10) > fg_at(&s, 29, 10),
@@ -617,10 +626,12 @@ int main(void) {
shader_t sh;
shader_make(&sh, "dim", (color_t){0}, 255);
shade_ctx_t base = base_ctx();
- shade_apply(&s, &sh, 1, (rect_t){0, 0, 0, 0}, NULL, &base); /* empty rect */
- shade_apply(&s, &sh, 0, (rect_t){0, 0, 4, 2}, NULL, &base); /* no shaders */
- shade_apply(NULL, &sh, 1, (rect_t){0, 0, 4, 2}, NULL, &base); /* no screen */
- shade_apply(&s, &sh, 1, (rect_t){100, 100, 4, 2}, NULL, &base); /* rect off-screen */
+ shade_apply(&s, &sh, 1, (rect_t){0, 0, 0, 0}, NULL, &base); /* empty rect */
+ shade_apply(&s, &sh, 0, (rect_t){0, 0, 4, 2}, NULL, &base); /* no shaders */
+ shade_apply(NULL, &sh, 1, (rect_t){0, 0, 4, 2}, NULL,
+ &base); /* no screen */
+ shade_apply(&s, &sh, 1, (rect_t){100, 100, 4, 2}, NULL,
+ &base); /* rect off-screen */
ok("a degenerate pass changes nothing and does not crash",
ceq(screen_at(&s, 0, 0)->fg, 0x80, 0x80, 0x80),
shown(screen_at(&s, 0, 0)->fg));