summaryrefslogtreecommitdiff
path: root/tests/input_test.c
diff options
context:
space:
mode:
authorBerke Güzel <wenekar1@gmail.com>2026-10-14 17:17:43 +0300
committerBerke Güzel <wenekar1@gmail.com>2026-10-14 17:17:43 +0300
commit513bf031a589d9e2a1a2730adf56f95e5e316a06 (patch)
tree66ef6b095e6aa00c790ac37705fb9df3b099b92a /tests/input_test.c
parent234dd752dc2e15afab38cbbf78f8aa32be72ea5f (diff)
Remove unused private functions and inline trivial helpers
Diffstat (limited to 'tests/input_test.c')
-rw-r--r--tests/input_test.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/input_test.c b/tests/input_test.c
index 78dad07..e3a6b8b 100644
--- a/tests/input_test.c
+++ b/tests/input_test.c
@@ -372,6 +372,47 @@ int main(void)
r = term_input_encode_paste(&plain, "a\nb", 3, buf, 3);
assert(r.status == TERM_INPUT_BYTES && r.len == 3 && !memcmp(buf, "a\rb", 3));
}
+ {
+ mode(TERM_KEYBOARD_ALL_KEYS | TERM_KEYBOARD_EVENT_TYPES);
+ K(.key = TERM_KEY_NUM_LOCK); expect("\033[57360;129u");
+ K(.key = TERM_KEY_NUM_LOCK, .action = TERM_KEY_REPEAT,
+ .mods = TERM_MOD_NUM); expect("\033[57360;129:2u");
+ K(.key = TERM_KEY_NUM_LOCK, .action = TERM_KEY_RELEASE,
+ .mods = TERM_MOD_NUM); expect("\033[57360;129:3u");
+ K(.key = TERM_KEY_NUM_LOCK, .mods = TERM_MOD_NUM); expect("\033[57360;1u");
+ K(.key = TERM_KEY_SCROLL_LOCK); expect("\033[57359;1u");
+ }
+
+ {
+ /* UTF-8 writes must report overflow without crossing the capacity. */
+ struct term_key_event key = { .action = TERM_KEY_PRESS, .text = 0x4e2d };
+ struct term_mouse_event mouse = {
+ .kind = TERM_MOUSE_PRESS, .button = TERM_MOUSE_BUTTON_PRIMARY,
+ .pos = { .x = 190, .y = 95 },
+ };
+ struct term_modes modes = {
+ .mouse = TERM_MOUSE_ANY, .mouse_encoding = TERM_MOUSE_ENC_UTF8,
+ .grid = { .x = 256, .y = 128 },
+ };
+ static const char *const want[] = { "\xe4\xb8\xad", "\033[M \xc3\x9f\xc2\x80" };
+ char buf[16];
+ for (size_t which = 0; which < 2; which++) {
+ size_t len = strlen(want[which]);
+ for (size_t cap = 0; cap <= len + 1; cap++) {
+ memset(buf, '!', sizeof(buf));
+ struct term_input_result r = which == 0
+ ? term_input_encode_key(NULL, &key, &modes, buf, cap)
+ : term_input_encode_mouse(&mouse, &modes, buf, cap);
+ assert(buf[cap] == '!');
+ if (cap < len) {
+ assert(r.status == TERM_INPUT_BUFFER_FULL && r.len == 0);
+ } else {
+ assert(r.status == TERM_INPUT_BYTES && r.len == len);
+ assert(!memcmp(buf, want[which], len));
+ }
+ }
+ }
+ }
puts("PASS: terminal key, mouse, and paste encoding");
return 0;
}