diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/buffer.c | 45 | ||||
| -rw-r--r-- | test/minibuffer.c | 18 |
2 files changed, 22 insertions, 41 deletions
diff --git a/test/buffer.c b/test/buffer.c index a4ac754..19fca8c 100644 --- a/test/buffer.c +++ b/test/buffer.c @@ -5,45 +5,16 @@ #include "assert.h" #include "test.h" -void test_move() { +void test_add() { struct buffer b = buffer_create("test-buffer"); - struct buffer_view v = buffer_view_create(&b, false, false); - ASSERT(v.dot.col == 0 && v.dot.line == 0, - "Expected dot to be at buffer start"); + ASSERT(buffer_num_lines(&b) == 0, "Expected buffer to have zero lines"); - // make sure we cannot move now - buffer_backward_char(&v); - buffer_backward_line(&v); - ASSERT(v.dot.col == 0 && v.dot.line == 0, - "Expected to not be able to move backward in empty buffer"); + const char *txt = "we are adding some text"; + struct location loc = buffer_add(&b, (struct location){.line = 1, .col = 0}, + (uint8_t *)txt, strlen(txt)); - buffer_forward_char(&v); - buffer_forward_line(&v); - ASSERT(v.dot.col == 0 && v.dot.line == 0, - "Expected to not be able to move forward in empty buffer"); - - // add some text and try again - const char *txt = "testing movement"; - int lineindex = buffer_add_text(&v, (uint8_t *)txt, strlen(txt)); - ASSERT(lineindex + 1 == 1, "Expected buffer to have one line"); - - buffer_beginning_of_line(&v); - buffer_forward_char(&v); - ASSERT(v.dot.col == 1 && v.dot.line == 0, - "Expected to be able to move forward by one char"); - - // now we have two lines - const char *txt2 = "\n"; - int lineindex2 = buffer_add_text(&v, (uint8_t *)txt2, strlen(txt2)); - ASSERT(lineindex2 + 1 == 2, "Expected buffer to have two lines"); - buffer_backward_line(&v); - buffer_beginning_of_line(&v); - buffer_backward_char(&v); - ASSERT( - v.dot.col == 0 && v.dot.line == 0, - "Expected to not be able to move backwards when at beginning of buffer"); - - buffer_destroy(&b); + ASSERT(loc.line == 1 && loc.col == strlen(txt), + "Expected buffer to have one line with characters"); } -void run_buffer_tests() { run_test(test_move); } +void run_buffer_tests() { run_test(test_add); } diff --git a/test/minibuffer.c b/test/minibuffer.c index 5c5ae63..7ac6c9b 100644 --- a/test/minibuffer.c +++ b/test/minibuffer.c @@ -4,6 +4,7 @@ #include "dged/allocator.h" #include "dged/buffer.h" +#include "dged/buffer_view.h" #include "dged/command.h" #include "dged/display.h" #include "dged/minibuffer.h" @@ -32,11 +33,10 @@ void destroy() { } void test_minibuffer_echo() { - uint32_t relline, relcol; struct buffer_view view = buffer_view_create(&b, false, false); // TODO: how to clear this? - struct frame_allocator alloc = frame_allocator_create(1024); + struct frame_allocator alloc = frame_allocator_create(1024 * 1024); g_alloc = &alloc; struct command_list *list = @@ -50,13 +50,23 @@ void test_minibuffer_echo() { ASSERT(minibuffer_displaying(), "Minibuffer should now have text to display"); minibuffer_clear(); - buffer_update(&view, -1, 100, 1, list, 0, &relline, &relcol); + struct buffer_view_update_params p = { + .commands = list, + .frame_alloc = alloc_fn, + .window_id = -1, + .frame_time = 0, + .width = 100, + .height = 1, + .window_x = 0, + .window_y = 25, + }; + buffer_view_update(&view, &p); ASSERT(!minibuffer_displaying(), "Minibuffer should have nothing to display after clearing"); minibuffer_echo_timeout(0, "You will not see me"); - buffer_update(&view, -1, 100, 1, list, 0, &relline, &relcol); + buffer_view_update(&view, &p); ASSERT(!minibuffer_displaying(), "A zero timeout echo should be cleared after first update"); |
