summaryrefslogtreecommitdiff
path: root/tests/test_tui.c
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-19 22:33:33 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-19 22:33:33 +0200
commite352cd34d30acc1955c62027c779ac98004ac201 (patch)
tree8a94163b837fdc16e334c159d91a9f622d42763d /tests/test_tui.c
parent84c4fdcf138ad6ef4f7edfea76f2318b7a7a5e3e (diff)
downloadbokf-e352cd34d30acc1955c62027c779ac98004ac201.tar.gz
bokf-e352cd34d30acc1955c62027c779ac98004ac201.zip
tui: migrate the remaining screens to the widget layerv0.1.38
Diffstat (limited to 'tests/test_tui.c')
-rw-r--r--tests/test_tui.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/test_tui.c b/tests/test_tui.c
index b2462e8..98a1ac2 100644
--- a/tests/test_tui.c
+++ b/tests/test_tui.c
@@ -154,6 +154,11 @@ static void test_nav(void)
nav_init(&v, 0);
CHECK(tui_nav_key(&v, KEY_DOWN, 0, 0, 0, 0) == TUI_NAV_NONE);
+ CHECK(tui_nav_key(&v, KEY_F(5), 0, 0, 0, 0) == -2);
+ CHECK(tui_nav_key(&v, TUI_KEY_CTRL_N, 1, 0, 0, 0) == -4);
+ CHECK(tui_nav_key(&v, TUI_KEY_CTRL_N, 0, 0, 0, 0) == TUI_NAV_NONE);
+ CHECK(tui_nav_key(&v, 'q', 0, 0, 0, 0) == -1);
+ CHECK(tui_nav_key(&v, 27, 0, 0, 0, 0) == -1);
nav_init(&v, 5);
CHECK(tui_nav_key(&v, KEY_UP, 0, 0, 0, 0) == TUI_NAV_NONE && v.sel == 0);
@@ -196,6 +201,8 @@ static void test_nav(void)
static void test_form_nav(void)
{
+ CHECK(TUI_NAV_NONE != TUI_FORM_SUBMIT);
+ CHECK(tui_form_next(1, 3, 'x') == TUI_NAV_NONE);
CHECK(tui_form_next(0, 3, KEY_UP) == TUI_NAV_NONE);
CHECK(tui_form_next(0, 3, KEY_DOWN) == 1);
CHECK(tui_form_next(2, 3, KEY_DOWN) == TUI_NAV_NONE);
@@ -226,19 +233,56 @@ static const struct tui_rt_col RT_COLS[3] = {
{ "B", 22, 8, TUI_RT_EDIT },
};
+static int rt_key_cb(void *ud, int ch)
+{
+ (void)ud;
+ (void)ch;
+ return TUI_HOOK_NONE;
+}
+static void rt_footer_cb(void *ud, char *buf, size_t n)
+{
+ (void)ud;
+ snprintf(buf, n, "footer");
+}
+
static void test_rowtable(void)
{
struct tui_rt t;
memset(rt_cells, 0, sizeof rt_cells);
tui_rt_init(&t, 1, 8, 3, RT_COLS, 6, rt_cb, rt_info_cb, NULL);
CHECK(t.nrows == 1 && t.neditable == 2 && t.row == 0 && t.col == 0);
+ CHECK(t.key == NULL && t.footer == NULL);
+ tui_rt_set_key(&t, rt_key_cb);
+ tui_rt_set_footer(&t, rt_footer_cb);
+ CHECK(t.key == rt_key_cb && t.footer == rt_footer_cb);
+ /* editable index -> actual column index (INFO columns are skipped) */
+ CHECK(tui_rt_col_of(&t, 0) == 0);
+ CHECK(tui_rt_col_of(&t, 1) == 2);
CHECK(tui_rt_blank_row(&t, 0));
CHECK(tui_rt_move(&t, 0, 1) && t.col == 1);
CHECK(tui_rt_move(&t, 0, 1) && t.col == 0);
CHECK(tui_rt_move(&t, -1, 0) == 0);
CHECK(tui_rt_move(&t, 1, 0) == 0);
+ /* Tab walks the row and wraps to the next row */
+ t.nrows = 3;
+ t.row = 0;
+ t.col = 0;
+ CHECK(tui_rt_tab(&t, 1) && t.row == 0 && t.col == 1);
+ CHECK(tui_rt_tab(&t, 1) && t.row == 1 && t.col == 0);
+ CHECK(tui_rt_tab(&t, -1) && t.row == 0 && t.col == 1);
+ CHECK(tui_rt_tab(&t, -1) && t.row == 0 && t.col == 0);
+ /* with a single editable column every Tab is a row move */
+ struct tui_rt one;
+ tui_rt_init(&one, 3, 8, 1, RT_COLS, 6, rt_cb, rt_info_cb, NULL);
+ CHECK(one.neditable == 1);
+ CHECK(tui_rt_tab(&one, 1) && one.row == 1 && one.col == 0);
+ CHECK(tui_rt_tab(&one, -1) && one.row == 0 && one.col == 0);
+
/* data in the blank row appends a new blank row */
+ tui_rt_normalize(&t);
+ t.row = 0;
+ t.col = 0;
snprintf(rt_cells[0][0], 64, "1930");
CHECK(tui_rt_normalize(&t) == 2);
snprintf(rt_cells[1][0], 64, "x");