diff --git a/include/ft/test.h b/include/ft/test.h index 082ff44..e8ffc22 100644 --- a/include/ft/test.h +++ b/include/ft/test.h @@ -40,12 +40,21 @@ void ft_test_run(ft_test *test); /* ft_test_done(): Check whether a test is done */ bool ft_test_done(ft_test *test); -/* ft_assert(): Record an assertion in a test */ -void ft_assert(ft_test *test, int expression, +/* ft_assert(): Record an assertion in a test, return value */ +int ft_assert(ft_test *test, int expression, char const *file, int line, char const *expression_str); #define ft_assert(test, expression) \ ft_assert(test, expression, __FILE__, __LINE__, #expression) +/* ft_assert_eval(): Evaluate expression, log result and assert result */ +#define ft_assert_eval(test, expression, expected, resultfmt) { \ + if(ft_assert(test, (expression) == (expected))) \ + ft_log(test, #expression " = " #expected "\n"); \ + else \ + ft_log(test, #expression " = " resultfmt " [wanted " #expected "]\n", \ + (expression)); \ +} + /* ft_log(): Write some data in a test's log */ __attribute__((format(printf, 2, 3))) void ft_log(ft_test *test, char const *format, ...); diff --git a/src/main.c b/src/main.c index ff2cc5b..260d64b 100644 --- a/src/main.c +++ b/src/main.c @@ -70,7 +70,7 @@ int main(void) gscreen_set_tab_fkeys_visible(scr, 1, false); flog *testlog = flog_create(NULL); - flog_set_line_spacing(testlog, 2); + flog_set_line_spacing(testlog, 3); gscreen_add_tab(scr, testlog, testlog); gscreen_set_tab_fkeys_visible(scr, 2, false); diff --git a/src/test.c b/src/test.c index 82096d2..01f40c2 100644 --- a/src/test.c +++ b/src/test.c @@ -29,7 +29,7 @@ bool ft_test_done(ft_test *test) return test->passed + test->skipped + test->failed > 0; } -void ft_assert(ft_test *test, int expression, char const *file, int line, +int ft_assert(ft_test *test, int expression, char const *file, int line, char const *str) { if(expression) { @@ -39,6 +39,7 @@ void ft_assert(ft_test *test, int expression, char const *file, int line, test->failed++; ft_log(test, "%s:%d: assertion failed:\n %s\n", file, line, str); } + return expression; } void ft_log(ft_test *test, char const *format, ...) diff --git a/src/widgets/flog.c b/src/widgets/flog.c index 8ddff5a..676c972 100644 --- a/src/widgets/flog.c +++ b/src/widgets/flog.c @@ -34,6 +34,7 @@ void flog_set_log(flog *l, char const *log, int log_size) l->log = log; l->log_size = log_size; + l->top = 0; l->widget.dirty = 1; } @@ -105,8 +106,13 @@ static void flog_poly_render(void *l0, int x, int y) int current_line = 0; int current_y = y; + while(log < l->log + l->log_size) { + if(current_line >= l->top && current_line < l->top + l->visible) + dprint_opt(x+22, current_y, C_BLACK, C_NONE, + DTEXT_RIGHT, DTEXT_TOP, "%d", current_line+1); + if(log[0] == '\n') { log++; } @@ -115,19 +121,19 @@ static void flog_poly_render(void *l0, int x, int y) char const *endline = strchrnul(log, '\n'); int len = max(1, min(endscreen-log, endline-log)); - if(current_line >= l->top && current_line < l->top + l->visible) { - dprint_opt(x+22, current_y, C_RGB(21,21,21), C_NONE, - DTEXT_RIGHT, DTEXT_TOP, "%d", current_line+1); - dtext_opt(x+28, current_y, C_BLACK, C_NONE, DTEXT_LEFT, + if(current_line >= l->top && current_line < l->top + l->visible) + dtext_opt(x+30, current_y, C_BLACK, C_NONE, DTEXT_LEFT, DTEXT_TOP, log, len); - } log += len + (log[len] == '\n'); } - current_line++; - if(current_line > l->top) + if(current_line >= l->top && current_line < l->top + l->visible) { + int previous_y = current_y; current_y += l->font->line_height + l->line_spacing; + dline(x+26, previous_y, x+26, current_y-1, C_BLACK); + } + current_line++; } if(current_line > l->visible) { @@ -163,7 +169,7 @@ static bool flog_poly_event(void *l0, jevent e) return true; } if(key == KEY_DOWN) { - l->top = min(l->lines - l->visible, l->top + scroll_speed); + l->top = max(0, min(l->lines - l->visible, l->top + scroll_speed)); l->widget.update = 1; return true; }