diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 13:36:27 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-13 13:36:27 +0300 |
| commit | 4741f7a6dfa144ce65cf3bbdd4a1bc6bee6df2e5 (patch) | |
| tree | 97932e58eee98623b56a9d9181a3b4289b6ecfc1 /tests | |
| parent | a0fefd3856a4f03be0abbc51f7a9a0416db69eb5 (diff) | |
Optimize and simplify loops, table lookups, and branchless parsers
- Replace sequential colon-counting loop with branchless CTZ bitmask in src/pen.h
- Replace linear strchr with 256-bit ASCII punctuation bitmask in src/selection.c
- Flatten 3D color cube loop and precompute constants in src/palette.c
- Use static 256-byte LUT for hex decoding and bsearch for termcap in src/escape.c
- Replace capacity doubling while loops with branchless CLZ pow2 helpers across core
- Use direct memset/memcpy in src/snapshot.c
- Optimize input digit/byte formatting, alt-prefix path, and make keyboard state optional in src/input.c
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/input_test.c | 13 | ||||
| -rw-r--r-- | tests/osc_test.c | 48 |
2 files changed, 61 insertions, 0 deletions
diff --git a/tests/input_test.c b/tests/input_test.c index 6ee2caa..1a44f42 100644 --- a/tests/input_test.c +++ b/tests/input_test.c @@ -101,9 +101,22 @@ int main(void) typed('b', TERM_MOD_ALT | TERM_MOD_CTRL); expect("\033\002"); K(.key = TERM_KEY_BACKSPACE, .mods = TERM_MOD_ALT); expect("\033\177"); K(.key = TERM_KEY_RETURN, .mods = TERM_MOD_ALT); expect("\033\r"); + K(.key = TERM_KEY_TAB, .mods = TERM_MOD_ALT); expect("\033\t"); + K(.key = TERM_KEY_TAB, .mods = TERM_MOD_ALT | TERM_MOD_SHIFT); expect("\033[Z"); + K(.key = TERM_KEY_ESCAPE, .mods = TERM_MOD_ALT); expect("\033"); K(.key = TERM_KEY_LEFT, .mods = TERM_MOD_ALT); expect("\033[1;3D"); + { + char b_null[16]; + struct term_input_result r = term_input_encode_key( + NULL, + &(struct term_key_event){ .key = TERM_KEY_UP, .action = TERM_KEY_PRESS }, + &(struct term_modes){0}, + b_null, sizeof(b_null)); + assert(r.status == TERM_INPUT_BYTES && r.len == 3 && !memcmp(b_null, "\033[A", 3)); + } + K(.codepoint = 'b', .base = 'b', .text = 0x222B, .text_deferred = true); expect(""); diff --git a/tests/osc_test.c b/tests/osc_test.c index ea0ef08..4d0e32b 100644 --- a/tests/osc_test.c +++ b/tests/osc_test.c @@ -387,6 +387,53 @@ static void test_osc_legacy_titles(void) term_free(t); } +static void test_palette_and_theme(void) +{ + uint32_t c; + /* Hex formats */ + assert(term_color_parse("#f00", &c) && c == 0xFFFF0000u); + assert(term_color_parse("#00ff00", &c) && c == 0xFF00FF00u); + assert(term_color_parse(" #0000ff \t", &c) && c == 0xFF0000FFu); + assert(term_color_parse("123456", &c) && c == 0xFF123456u); + assert(term_color_parse("abc", &c) && c == 0xFFAABBCCu); + assert(term_color_parse("#123456789abc", &c) && c == 0xFF12569au); + + /* rgb: / rgbi: */ + assert(term_color_parse("rgb:ff/80/00", &c) && c == 0xFFFF8000u); + assert(term_color_parse("rgbi:1.0/0.0/0.5", &c) && c == 0xFFFF0080u); + assert(term_color_parse("rgbi:.25/.5/.75", &c)); + + /* Errors */ + assert(!term_color_parse(NULL, &c)); + assert(!term_color_parse("#ff", &c)); + assert(!term_color_parse("", &c)); + assert(!term_color_parse("rgb:ff/80", &c)); + assert(!term_color_parse("rgb:ff/80/00/11", &c)); + assert(!term_color_parse("rgbi:2.0/0/0", &c)); + assert(!term_color_parse("rgbi:./0/0", &c)); + + /* Theme APIs */ + struct term_theme theme; + term_theme_default(&theme); + assert(term_theme_set_key(&theme, "foreground", "#112233") && theme.fg == 0xFF112233u); + assert(term_theme_set_key(&theme, "foreground", "") && theme.fg == 0xFFFFFFFFu); + assert(term_theme_set_key(&theme, "background", "#445566") && theme.bg == 0xFF445566u); + assert(term_theme_set_key(&theme, "background", "") && theme.bg == 0xFF1E1E2Eu); + assert(term_theme_set_key(&theme, "color0", "#010203") && theme.ansi[0] == 0xFF010203u); + assert(term_theme_set_key(&theme, "color15", "#fafbfc") && theme.ansi[15] == 0xFFFAFBFCu); + assert(term_theme_set_key(&theme, "color0", "") && theme.ansi[0] == 0xFF585B70u); + assert(!term_theme_set_key(&theme, "color16", "#000000")); + assert(!term_theme_set_key(&theme, "color01", "#000000")); + assert(!term_theme_set_key(&theme, "invalid", "#000000")); + assert(!term_theme_set_key(NULL, "foreground", "#000000")); + assert(!term_theme_set_key(&theme, NULL, "#000000")); + assert(!term_theme_set_key(&theme, "foreground", NULL)); + + struct term_theme hc; + term_theme_high_contrast(&hc); + assert(hc.bg == 0xFF000000u && hc.fg == 0xFFFFFFFFu); +} + int main(void) { test_osc52(); @@ -395,6 +442,7 @@ int main(void) test_osc_misc(); test_osc_colors(); test_osc_legacy_titles(); + test_palette_and_theme(); puts("PASS: OSC tests"); return 0; } |
