diff options
| author | Albert Cervin <albert@acervin.com> | 2022-11-02 22:20:04 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2022-11-16 23:33:49 +0100 |
| commit | 2f4cb88d5c60f725323739300bb49dfa8923e7d5 (patch) | |
| tree | 6ec22c2be92eff05f18e5919e747faab56e555ad /test/buffer.c | |
| download | dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.tar.gz dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.tar.xz dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.zip | |
🎉 And so it begins
Diffstat (limited to 'test/buffer.c')
| -rw-r--r-- | test/buffer.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/buffer.c b/test/buffer.c new file mode 100644 index 0000000..d7d9b0b --- /dev/null +++ b/test/buffer.c @@ -0,0 +1,46 @@ +#include "assert.h" +#include "test.h" + +#include "buffer.h" + +#include <string.h> + +void test_move() { + struct buffer b = buffer_create("test-buffer"); + ASSERT(b.dot_col == 0 && b.dot_line == 0, + "Expected dot to be at buffer start"); + + // make sure we cannot move now + buffer_backward_char(&b); + buffer_backward_line(&b); + ASSERT(b.dot_col == 0 && b.dot_line == 0, + "Expected to not be able to move backward in empty buffer"); + + buffer_forward_char(&b); + buffer_forward_line(&b); + ASSERT(b.dot_col == 0 && b.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(&b, (uint8_t *)txt, strlen(txt)); + ASSERT(lineindex + 1 == 1, "Expected buffer to have one line"); + + buffer_beginning_of_line(&b); + buffer_forward_char(&b); + ASSERT(b.dot_col == 1 && b.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(&b, (uint8_t *)txt2, strlen(txt2)); + ASSERT(lineindex2 + 1 == 2, "Expected buffer to have two lines"); + buffer_backward_line(&b); + buffer_beginning_of_line(&b); + buffer_backward_char(&b); + ASSERT( + b.dot_col == 0 && b.dot_line == 0, + "Expected to not be able to move backwards when at beginning of buffer"); +} + +void run_buffer_tests() { run_test(test_move); } |
