summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-01 16:22:47 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2020-04-01 16:22:47 -0300
commit45e3065727032997b803ce92824054b99f17d763 (patch)
tree46494dc7bef695795b73b77db1efc22371deecf1 /test
parentc39423d5a45c9740b8ad0336c6e4eac4762bedf5 (diff)
downloadjet-45e3065727032997b803ce92824054b99f17d763.tar.gz
jet-45e3065727032997b803ce92824054b99f17d763.zip
Add visual testing for page.c
Diffstat (limited to 'test')
-rw-r--r--test/Makefile2
-rw-r--r--test/page.c47
2 files changed, 49 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..d9a8a69
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,2 @@
+page: Makefile page.c ../page.c
+ gcc -lcurses page.c -o 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 <curses.h>
+
+#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;
+}