From f3f1931ab05bcf220af4f2fe11252f585d07ab51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Wed, 1 Apr 2020 16:22:47 -0300 Subject: Add visual testing for page.c --- .gitignore | 1 + test/page.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/page.c diff --git a/.gitignore b/.gitignore index 2edc120..1555962 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ jet +page diff --git a/test/page.c b/test/page.c new file mode 100644 index 0000000..322adf2 --- /dev/null +++ b/test/page.c @@ -0,0 +1,47 @@ +#include + +#include "../page.c" + +int main() { + int exit = 0; + struct page *p = new_page(); + + initscr(); + cbreak(); + noecho(); + nonl(); + intrflush(stdscr, FALSE); + keypad(stdscr, TRUE); + + while (!exit) { + int input = getch(); + clear(); + switch (input) { + case KEY_LEFT: + move_gap(p, -1); + break; + case KEY_RIGHT: + move_gap(p, 1); + break; + case KEY_BACKSPACE: + delete_from_page(p); + break; + default: + insert_into_page(p, input); + } + int gap_start = p->gap_start - p->buffer; + int gap_end = p->gap_end - p->buffer; + for (int i = 0; i < gap_start; i++) { + addch(p->buffer[i]); + } + for (int i = gap_start; i < gap_end; i++) { + addch('_'); + } + for (int i = gap_end; i < PAGE_SIZE; i++) { + addch(p->buffer[i]); + } + } + + endwin(); + return 0; +} -- cgit v1.2.3