diff options
| author | Anders Betts <anders.betts@gmail.com> | 2026-09-23 09:13:17 +0200 |
|---|---|---|
| committer | Anders Betts <anders.betts@gmail.com> | 2026-09-23 09:13:17 +0200 |
| commit | 53071bb69f5d21b35b8a61c2b1dd18832ce781d4 (patch) | |
| tree | fa76c13cef78925d1b9650e92f64d5115dcdb6e7 /tests | |
| parent | 2ca284619125af0d5c12e9210ff1bfc8f9122739 (diff) | |
| download | bokf-53071bb69f5d21b35b8a61c2b1dd18832ce781d4.tar.gz bokf-53071bb69f5d21b35b8a61c2b1dd18832ce781d4.zip | |
tui: aligned voucher detail, up/down between vouchers, list sorting
The detail pads every column by display width, blanks zero amounts and
shows row texts and a Summa line. Up/Down step to the previous/next
voucher in the list order; 's' cycles the list sort (number or date,
ascending or descending, saved in tui.conf). The list fetches all pages
of voucher.list instead of stopping at 200.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_tui.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test_tui.c b/tests/test_tui.c index b48544e..7ab969b 100644 --- a/tests/test_tui.c +++ b/tests/test_tui.c @@ -9,6 +9,7 @@ #include "drafts.h" #include "tui.h" +#include "vlist.h" #include "util.h" static int failures = 0; @@ -929,6 +930,60 @@ static void test_drafts(void) free(b); } +static void vl_set(struct vlist_item *it, int64_t id, const char *ser, + int64_t num, const char *date) +{ + memset(it, 0, sizeof *it); + it->id = id; + snprintf(it->series, sizeof it->series, "%s", ser); + it->number = num; + snprintf(it->date, sizeof it->date, "%s", date); +} + +static void test_vlist(void) +{ + struct vlist_item v[5]; + /* registered out of date order, two series, B10 after B9 */ + vl_set(&v[0], 1, "A", 1, "2026-03-01"); + vl_set(&v[1], 2, "B", 10, "2026-01-15"); + vl_set(&v[2], 3, "A", 2, "2026-01-15"); + vl_set(&v[3], 4, "B", 9, "2026-02-01"); + vl_set(&v[4], 5, "A", 3, "2026-01-15"); + + vlist_sort(v, 5, VSORT_NUMBER); + CHECK(v[0].id == 1 && v[1].id == 3 && v[2].id == 5 && v[3].id == 4 && + v[4].id == 2); /* A1 A2 A3 B9 B10: numeric, not text order */ + vlist_sort(v, 5, VSORT_NUMBER_DESC); + CHECK(v[0].id == 2 && v[4].id == 1); + /* same date: series and number decide */ + vlist_sort(v, 5, VSORT_DATE); + CHECK(v[0].id == 3 && v[1].id == 5 && v[2].id == 2 && v[3].id == 4 && + v[4].id == 1); + vlist_sort(v, 5, VSORT_DATE_DESC); + CHECK(v[0].id == 1 && v[1].id == 4 && v[2].id == 2 && v[3].id == 5 && + v[4].id == 3); + vlist_sort(v, 5, 99); /* unknown mode: by number */ + CHECK(v[0].id == 1 && v[4].id == 2); + vlist_sort(NULL, 0, VSORT_DATE); + + CHECK(vlist_index(v, 5, 4) == 3); + CHECK(vlist_index(v, 5, 42) == -1); + /* stepping stops at both ends and needs a position in the list */ + CHECK(vlist_step(5, 0, 1) == 1); + CHECK(vlist_step(5, 0, -1) == -1); + CHECK(vlist_step(5, 4, 1) == -1); + CHECK(vlist_step(5, 4, -1) == 3); + CHECK(vlist_step(5, -1, 1) == -1); + CHECK(vlist_step(0, 0, 1) == -1); + + /* config names round-trip; unknown falls back to number */ + for (int m = 0; m < VSORT_COUNT; m++) + CHECK(vlist_sort_parse(vlist_sort_name(m)) == m); + CHECK(vlist_sort_parse("bogus") == VSORT_NUMBER); + CHECK(vlist_sort_parse(NULL) == VSORT_NUMBER); + CHECK(strcmp(vlist_sort_label(VSORT_DATE_DESC), "datum, fallande") == 0); +} + int main(void) { test_disp_width(); @@ -955,6 +1010,7 @@ int main(void) test_rt_footer(); test_actions(); test_drafts(); + test_vlist(); printf("test_tui: %d checks, %d failures\n", checks, failures); return failures ? 1 : 0; } |
