summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-19 23:05:44 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-19 23:05:44 +0200
commit8da6a7e849513e1cb63410d95b121df729260d0c (patch)
tree77de7f5b3952d153e072cda8cc7c4f4bcd5f0c87 /tests
parent730d7159e3b9b3adfba2c3779893fdb4e107647a (diff)
downloadbokf-8da6a7e849513e1cb63410d95b121df729260d0c.tar.gz
bokf-8da6a7e849513e1cb63410d95b121df729260d0c.zip
tui: themes, pager markup, menu sections; merge Bokslut and year infov0.1.40
Diffstat (limited to 'tests')
-rw-r--r--tests/test_tui.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/test_tui.c b/tests/test_tui.c
index 9c47c43..f4405b4 100644
--- a/tests/test_tui.c
+++ b/tests/test_tui.c
@@ -199,6 +199,88 @@ static void test_nav(void)
CHECK(v.top == 90);
}
+static void test_styles(void)
+{
+ /* without colour every style falls back to attributes */
+ CHECK(tui_style_attrs(TUI_TITLE, 0, 0) == (int)A_BOLD);
+ CHECK(tui_style_attrs(TUI_HEADING, 0, 0) == (int)A_BOLD);
+ CHECK(tui_style_attrs(TUI_SUBHEADING, 0, 0) == (int)A_BOLD);
+ CHECK(tui_style_attrs(TUI_DIM, 0, 0) == (int)A_DIM);
+ CHECK(tui_style_attrs(TUI_STATUS, 0, 0) == (int)A_DIM);
+ CHECK(tui_style_attrs(TUI_RULE, 0, 0) == (int)A_DIM);
+ CHECK(tui_style_attrs(TUI_POS, 0, 0) == 0);
+ CHECK(tui_style_attrs(TUI_NEG, 0, 0) == 0);
+ /* NO_COLOR forces the same fallback even when colours are available */
+ CHECK(tui_style_attrs(TUI_POS, 1, 1) == tui_style_attrs(TUI_POS, 0, 0));
+ CHECK(tui_style_attrs(TUI_RULE, 1, 1) == (int)A_DIM);
+ CHECK(tui_style_attrs(TUI_TITLE, 1, 1) == (int)A_BOLD);
+ /* with colour the amount styles get distinct colour pairs */
+ int pos = tui_style_attrs(TUI_POS, 1, 0);
+ int neg = tui_style_attrs(TUI_NEG, 1, 0);
+ CHECK((pos & (int)A_COLOR) != 0);
+ CHECK((neg & (int)A_COLOR) != 0);
+ CHECK((pos & (int)A_COLOR) != (neg & (int)A_COLOR));
+ CHECK((tui_style_attrs(TUI_HEADING, 1, 0) & (int)A_BOLD) != 0);
+ CHECK((tui_style_attrs(TUI_STATUS, 1, 0) & (int)A_DIM) != 0);
+}
+
+static void test_markup(void)
+{
+ int st = 123;
+ const char *s = tui_markup("vanlig text", &st);
+ CHECK(strcmp(s, "vanlig text") == 0 && st == -1);
+ s = tui_markup("\001Rubrik", &st);
+ CHECK(strcmp(s, "Rubrik") == 0 && st == TUI_HEADING);
+ s = tui_markup("\002dimmad rad", &st);
+ CHECK(strcmp(s, "dimmad rad") == 0 && st == TUI_DIM);
+ s = tui_markup("\003----------------", &st);
+ CHECK(strcmp(s, "----------------") == 0 && st == TUI_RULE);
+ s = tui_markup("", &st);
+ CHECK(s && *s == '\0' && st == -1);
+ s = tui_markup(NULL, &st);
+ CHECK(s && *s == '\0' && st == -1);
+ /* only a leading marker counts; the marker may be NULL-checked away */
+ 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);
+ s = tui_markup("\001x", NULL);
+ CHECK(strcmp(s, "x") == 0);
+}
+
+static const unsigned char SECTION_FLAGS[5] = { 0, 1, 1, 0, 1 };
+
+static void test_nav_sections(void)
+{
+ struct tui_list_nav v;
+ nav_init(&v, 5);
+ v.selectable = SECTION_FLAGS;
+ v.sel = 0; /* a header: snaps to the first selectable row */
+ CHECK(tui_nav_key(&v, KEY_DOWN, 0, 0, 0, 0) == TUI_NAV_NONE && v.sel == 2);
+ CHECK(tui_nav_key(&v, KEY_DOWN, 0, 0, 0, 0) == TUI_NAV_NONE && v.sel == 4);
+ CHECK(tui_nav_key(&v, KEY_DOWN, 0, 0, 0, 0) == TUI_NAV_NONE && v.sel == 4);
+ CHECK(tui_nav_key(&v, KEY_UP, 0, 0, 0, 0) == TUI_NAV_NONE && v.sel == 2);
+ CHECK(tui_nav_key(&v, KEY_HOME, 0, 0, 0, 0) == TUI_NAV_NONE && v.sel == 1);
+ CHECK(tui_nav_key(&v, KEY_END, 0, 0, 0, 0) == TUI_NAV_NONE && v.sel == 4);
+ /* digits and goto count selectable rows only */
+ CHECK(tui_nav_key(&v, '1', 0, 0, 0, 0) == TUI_NAV_NONE && v.sel == 1);
+ CHECK(tui_nav_key(&v, '2', 0, 0, 0, 1) == 2 && v.sel == 2);
+ CHECK(tui_nav_key(&v, '3', 0, 0, 0, 1) == 4 && v.sel == 4);
+ CHECK(tui_nav_key(&v, '9', 0, 0, 0, 1) == TUI_NAV_NONE && v.sel == 4);
+ v.sel = 1;
+ CHECK(tui_nav_key(&v, 'g', 0, 0, 0, 0) == TUI_NAV_NONE && v.goto_active);
+ CHECK(tui_nav_key(&v, '2', 0, 0, 0, 0) == TUI_NAV_NONE && v.sel == 2);
+ CHECK(tui_nav_key(&v, KEY_BACKSPACE, 0, 0, 0, 0) == TUI_NAV_NONE &&
+ v.sel == 2);
+ CHECK(tui_nav_key(&v, '\n', 0, 0, 0, 0) == TUI_NAV_NONE && !v.goto_active);
+ /* paging lands on selectable rows */
+ nav_init(&v, 5);
+ v.selectable = SECTION_FLAGS;
+ v.view = 2;
+ CHECK(tui_nav_key(&v, KEY_NPAGE, 0, 0, 0, 0) == TUI_NAV_NONE && v.sel == 4);
+ CHECK(tui_nav_key(&v, KEY_PPAGE, 0, 0, 0, 0) == TUI_NAV_NONE && v.sel == 2);
+}
+
static void test_form_nav(void)
{
CHECK(TUI_NAV_NONE != TUI_FORM_SUBMIT);
@@ -398,7 +480,10 @@ int main(void)
test_parse_kr();
test_ledit();
test_date_field();
+ test_styles();
+ test_markup();
test_nav();
+ test_nav_sections();
test_form_nav();
test_rowtable();
test_rt_fields();