summaryrefslogtreecommitdiff
path: root/tests/test_tui.c
diff options
context:
space:
mode:
authorAnders Betts <anders.betts@gmail.com>2026-09-19 23:17:45 +0200
committerAnders Betts <anders.betts@gmail.com>2026-09-19 23:17:45 +0200
commit985ae80d7f82cef7c273fae953c73f8bd909ebef (patch)
tree18d4305e2bdd6f0069f431f2dce04a446ef216f2 /tests/test_tui.c
parent8da6a7e849513e1cb63410d95b121df729260d0c (diff)
downloadbokf-985ae80d7f82cef7c273fae953c73f8bd909ebef.tar.gz
bokf-985ae80d7f82cef7c273fae953c73f8bd909ebef.zip
tui: backspace deletes backwards while editing; esc restores the valuev0.1.41
Diffstat (limited to 'tests/test_tui.c')
-rw-r--r--tests/test_tui.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test_tui.c b/tests/test_tui.c
index f4405b4..93aece0 100644
--- a/tests/test_tui.c
+++ b/tests/test_tui.c
@@ -104,6 +104,42 @@ static void test_ledit(void)
CHECK(tui_le_key(&e, KEY_UP) == 0); /* not an editing key */
}
+static void test_field_fresh(void)
+{
+ char buf[16];
+ size_t pos = (size_t)-1;
+ int fresh = 1;
+
+ /* fresh + backspace deletes the last character, it does not clear */
+ snprintf(buf, sizeof buf, "abc");
+ CHECK(tui_field_edit(buf, sizeof buf, &pos, KEY_BACKSPACE, &fresh));
+ CHECK(strcmp(buf, "ab") == 0);
+
+ /* the first printable still replaces the whole prefilled value */
+ snprintf(buf, sizeof buf, "abc");
+ pos = (size_t)-1;
+ fresh = 1;
+ CHECK(tui_field_edit(buf, sizeof buf, &pos, 'x', &fresh));
+ CHECK(strcmp(buf, "x") == 0);
+
+ /* movement keeps the content, clears fresh; the next printable is
+ inserted at the caret */
+ snprintf(buf, sizeof buf, "abc");
+ pos = (size_t)-1;
+ fresh = 1;
+ CHECK(tui_field_edit(buf, sizeof buf, &pos, KEY_LEFT, &fresh));
+ CHECK(strcmp(buf, "abc") == 0 && pos == 2 && fresh == 0);
+ CHECK(tui_field_edit(buf, sizeof buf, &pos, 'x', &fresh));
+ CHECK(strcmp(buf, "abxc") == 0);
+
+ /* fresh + delete removes the character at the caret, no clear */
+ snprintf(buf, sizeof buf, "abc");
+ pos = 0;
+ fresh = 1;
+ CHECK(tui_field_edit(buf, sizeof buf, &pos, KEY_DC, &fresh));
+ CHECK(strcmp(buf, "bc") == 0);
+}
+
static void date_feed(char *buf, size_t cap, const char *digits)
{
size_t pos = (size_t)-1;
@@ -139,6 +175,18 @@ static void test_date_field(void)
fresh = 0;
tui_date_field_edit(buf, sizeof buf, &pos, '9', &fresh);
CHECK(strcmp(buf, "2026-06-09") == 0);
+
+ /* fresh + backspace deletes the last digit; fresh + ^U clears */
+ snprintf(buf, sizeof buf, "2026-06-04");
+ pos = (size_t)-1;
+ fresh = 1;
+ CHECK(tui_date_field_edit(buf, sizeof buf, &pos, KEY_BACKSPACE, &fresh));
+ CHECK(strcmp(buf, "2026-06-0") == 0);
+ snprintf(buf, sizeof buf, "2026-06-04");
+ pos = (size_t)-1;
+ fresh = 1;
+ CHECK(tui_date_field_edit(buf, sizeof buf, &pos, 21, &fresh));
+ CHECK(strcmp(buf, "") == 0);
}
static void nav_init(struct tui_list_nav *v, int n)
@@ -479,6 +527,7 @@ int main(void)
test_formats();
test_parse_kr();
test_ledit();
+ test_field_fresh();
test_date_field();
test_styles();
test_markup();