aboutsummaryrefslogtreecommitdiff
path: root/tests/test_tui.c
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-20 10:24:18 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-20 10:24:18 +0200
commitae60b7d2c87cc9ed6878faa57cd4233f77f6f7c3 (patch)
tree918e717a5d226dcd54890901682a980c41d7e1d0 /tests/test_tui.c
parent5097941fa96ce0c309e5f1af034993781a70fc66 (diff)
downloadbokf-ae60b7d2c87cc9ed6878faa57cd4233f77f6f7c3.tar.gz
bokf-ae60b7d2c87cc9ed6878faa57cd4233f77f6f7c3.zip
tui: pinned report headers, voucher detail headers, clamped pagingv0.1.48
Diffstat (limited to 'tests/test_tui.c')
-rw-r--r--tests/test_tui.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/tests/test_tui.c b/tests/test_tui.c
index 56880fa..84e610e 100644
--- a/tests/test_tui.c
+++ b/tests/test_tui.c
@@ -303,11 +303,39 @@ static void test_markup(void)
s = tui_markup("a\001b", &st);
CHECK(strcmp(s, "a\001b") == 0 && st == -1);
s = tui_markup("\004text", &st);
- CHECK(strcmp(s, "\004text") == 0 && st == -1);
+ CHECK(strcmp(s, "text") == 0 && st == -1);
+ s = tui_markup("\004\001Rubrik", &st);
+ CHECK(strcmp(s, "Rubrik") == 0 && st == TUI_HEADING);
s = tui_markup("\001x", NULL);
CHECK(strcmp(s, "x") == 0);
}
+static void test_sticky(void)
+{
+ char a[] = "alfa";
+ char h1[] = "\004RUBRIK 1";
+ char b[] = "beta";
+ char h2[] = "\004RUBRIK 2";
+ char c[] = "gamma";
+ char *lines[] = { a, h1, b, h2, c };
+ char *head[5];
+ int nh = 0;
+ int nb = tui_sticky_split(lines, 5, head, &nh);
+ CHECK(nb == 3 && nh == 2);
+ CHECK(strcmp(lines[0], "alfa") == 0);
+ CHECK(strcmp(lines[1], "beta") == 0);
+ CHECK(strcmp(lines[2], "gamma") == 0);
+ CHECK(strcmp(head[0], "\004RUBRIK 1") == 0);
+ CHECK(strcmp(head[1], "\004RUBRIK 2") == 0);
+ char *one[] = { a };
+ nb = tui_sticky_split(one, 1, head, &nh);
+ CHECK(nb == 1 && nh == 0);
+ char *none[] = { h1, h2 };
+ nb = tui_sticky_split(none, 2, head, &nh);
+ CHECK(nb == 0 && nh == 2);
+ CHECK(head[0] == h1 && head[1] == h2);
+}
+
static const unsigned char SECTION_FLAGS[5] = { 0, 1, 1, 0, 1 };
static void test_nav_sections(void)
@@ -417,8 +445,16 @@ static void test_form_actions(void)
CHECK(tui_form_act_key(8, nf, ACTS, 6, KEY_DOWN) == 0);
CHECK(tui_form_act_key(4, nf, ACTS, 6, KEY_HOME) == 0);
CHECK(tui_form_act_key(0, nf, ACTS, 6, KEY_END) == 8);
- CHECK(tui_form_act_key(0, nf, ACTS, 6, KEY_NPAGE) == 4);
- CHECK(tui_form_act_key(8, nf, ACTS, 6, KEY_PPAGE) == 4);
+ /* paging stops at the ends instead of wrapping */
+ CHECK(tui_form_act_key(0, nf, ACTS, 6, KEY_NPAGE) == 8);
+ CHECK(tui_form_act_key(8, nf, ACTS, 6, KEY_PPAGE) == 0);
+ CHECK(tui_form_act_key(8, nf, ACTS, 6, KEY_NPAGE) == 8);
+ CHECK(tui_form_act_key(0, nf, ACTS, 6, KEY_PPAGE) == 0);
+ CHECK(tui_form_act_page(0, nf, ACTS, 6, 1) == 8);
+ CHECK(tui_form_act_page(8, nf, ACTS, 6, -1) == 0);
+ CHECK(tui_form_act_page(4, nf, ACTS, 6, 1) == 8);
+ CHECK(tui_form_act_page(4, nf, ACTS, 6, -1) == 0);
+ CHECK(tui_form_act_page(0, 0, NULL, 0, 1) == -1);
CHECK(tui_form_act_key(0, nf, ACTS, 6, KEY_F(5)) == TUI_FORM_REFRESH);
CHECK(tui_form_act_key(5, nf, ACTS, 6, TUI_KEY_CTRL_ENTER) ==
TUI_FORM_SUBMIT);
@@ -687,6 +723,7 @@ int main(void)
test_date_field();
test_styles();
test_markup();
+ test_sticky();
test_nav();
test_nav_sections();
test_form_nav();