LCOV - code coverage report
Current view: top level - tests/unit - test_input_line.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 29 29
Test Date: 2026-04-15 21:12:52 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #include "test_helpers.h"
       2              : #include "input_line.h"
       3              : #include <string.h>
       4              : #include <stddef.h>
       5              : 
       6            1 : void test_input_line(void) {
       7            1 :     char buf[64];
       8              : 
       9              :     /* 1. Init with NULL initial_text → empty buffer, cursor at 0 */
      10            1 :     InputLine il;
      11            1 :     input_line_init(&il, buf, sizeof(buf), NULL);
      12            1 :     ASSERT(il.buf   == buf,       "buf pointer set");
      13            1 :     ASSERT(il.bufsz == sizeof(buf), "bufsz set");
      14            1 :     ASSERT(il.len   == 0,         "len 0 for NULL initial");
      15            1 :     ASSERT(il.cur   == 0,         "cur 0 for NULL initial");
      16            1 :     ASSERT(buf[0]   == '\0',      "buf NUL-terminated");
      17              : 
      18              :     /* 2. Init with empty string → same as NULL */
      19            1 :     input_line_init(&il, buf, sizeof(buf), "");
      20            1 :     ASSERT(il.len == 0, "len 0 for empty initial");
      21            1 :     ASSERT(il.cur == 0, "cur 0 for empty initial");
      22              : 
      23              :     /* 3. Init with text → len and cur at end */
      24            1 :     input_line_init(&il, buf, sizeof(buf), "hello");
      25            1 :     ASSERT(il.len == 5,           "len 5 for 'hello'");
      26            1 :     ASSERT(il.cur == 5,           "cur at end after init");
      27            1 :     ASSERT(strcmp(buf, "hello") == 0, "buf contains 'hello'");
      28              : 
      29              :     /* 4. Init truncates when text >= bufsz */
      30            1 :     char small[4];
      31            1 :     input_line_init(&il, small, sizeof(small), "toolong");
      32            1 :     ASSERT(il.len == 3,         "len truncated to bufsz-1");
      33            1 :     ASSERT(small[3] == '\0',    "buf NUL-terminated after truncation");
      34              : 
      35              :     /* 5. All callbacks NULL after init */
      36            1 :     input_line_init(&il, buf, sizeof(buf), "x");
      37            1 :     ASSERT(il.tab_fn       == NULL, "tab_fn NULL after init");
      38            1 :     ASSERT(il.shift_tab_fn == NULL, "shift_tab_fn NULL after init");
      39            1 :     ASSERT(il.render_below == NULL, "render_below NULL after init");
      40              : 
      41              :     /* 6. trow is 0 after init */
      42            1 :     ASSERT(il.trow == 0, "trow 0 after init");
      43              : 
      44              :     /* 7. UTF-8 multi-byte initial text */
      45            1 :     input_line_init(&il, buf, sizeof(buf), "héllo");
      46              :     /* 'é' is 2 bytes (0xC3 0xA9) → len = 6, cur = 6 */
      47            1 :     ASSERT(il.len == 6, "len accounts for UTF-8 bytes");
      48            1 :     ASSERT(il.cur == 6, "cur at byte end for UTF-8 text");
      49            1 :     ASSERT(strcmp(buf, "héllo") == 0, "UTF-8 content preserved");
      50              : }
        

Generated by: LCOV version 2.0-1