]> git.mdlowis.com Git - projs/tide.git/commitdiff
started writing unit integration tests
authorMichael D. Lowis <mike@mdlowis.com>
Wed, 7 Dec 2016 03:21:49 +0000 (22:21 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Wed, 7 Dec 2016 03:21:49 +0000 (22:21 -0500)
Makefile
TODO.md
config.mk
libedit/view.c
tests/xedit.c
xedit.c

index 60e5f1ca8e109a3aa5c405efbdbd01c673f5d708..629cc9114f32e6b39545fde3122bc7f184092ff5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -24,11 +24,14 @@ all: xedit xpick
 
 clean:
        $(RM) *.o lib*/*.o tests/*.o *.a xpick xedit unittests
+       $(RM) *.gcno lib*/*.gcno tests/*.gcno
+       $(RM) *.gcda lib*/*.gcda tests/*.gcda
+       $(RM) *.gcov lib*/*.gcov tests/*.gcov
 
 install: all
        mkdir -p $(PREFIX)/bin
-       cp xedit $(PREFIX)/bin
-       cp xpick $(PREFIX)/bin
+       cp -f xedit $(PREFIX)/bin
+       cp -f xpick $(PREFIX)/bin
        cp xfilepick $(PREFIX)/bin
        cp xtagpick $(PREFIX)/bin
        cp xman $(PREFIX)/bin
diff --git a/TODO.md b/TODO.md
index f7b9bdf10402dd159a02a8e420e081b9532869af..ae3df7d37f899a466462578b4bea2ea04fbf62a4 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -13,6 +13,7 @@
 * Implement fuzzy file/buffer/tag picker
 * check for file changes when window regains focus
 * check for file changes on save
+* backspace should delete indent if preceded by whitespace
 
 # Auxillary Programs
 
index 33775f139c8a7fad53a1cc2df0e4bb512a4d9b0c..85d96ed61df1a821cf5273de7b4f7216e10852c3 100644 (file)
--- a/config.mk
+++ b/config.mk
@@ -22,3 +22,7 @@ LIBS += -L/usr/X11/lib
 
 # Linux Freetype2 Flags
 INCS += -I/usr/include/freetype2
+
+# Gcov Coverage
+#CFLAGS  += --coverage
+#LDFLAGS += --coverage
index fde73de8d6dcc0af11919bfe1f4c227f04022665..97b23240dd9697cc5a1bb0b7b6fe226b554b86d6 100644 (file)
@@ -183,6 +183,7 @@ void view_init(View* view, char* file) {
         free(view->rows);
     }
     buf_init(&(view->buffer));
+    view->selection = (Sel){ 0 };
     if (file) {
         view->selection.end = buf_load(&(view->buffer), file);
         view->selection.beg = view->selection.end;
@@ -596,4 +597,4 @@ void view_indent(View* view, int dir) {
         }
         off = buf_byline(buf, off, UP);
     }
-}
\ No newline at end of file
+}
index d9015a6447ffa241ace1e8086aef9b010d841275..8abfffe6ea6db492a93b5992b4723080c04b3eb1 100644 (file)
@@ -5,10 +5,13 @@ int Mods = 0;
 
 /* Helper Functions
  *****************************************************************************/
-void setup_view(enum RegionId id, char* text) {
+void setup_view(enum RegionId id, char* text, unsigned cursor) {
     Focused = id;
     view_init(getview(id), NULL);
     view_putstr(getview(id), text);
+    getsel(id)->beg = cursor;
+    getsel(id)->end = cursor;
+    getsel(id)->col = buf_getcol(getbuf(id), getsel(id)->end);
 }
 
 /* Stubbed Functions
@@ -32,53 +35,138 @@ static void redraw(int width, int height) {
 /* Unit Tests
  *****************************************************************************/
 TEST_SUITE(XeditTests) {
-    /* Key Handling - Cursor Movement
+    /* Key Handling - Cursor Movement - Basic
      *************************************************************************/
-    TEST(left arrow should do nothing for empty buffer) {
-        setup_view(EDIT, "");
+    TEST(left should do nothing for empty buffer) {
+        setup_view(EDIT, "", 0);
         key_handler(ModNone, KEY_LEFT);
         CHECK(getsel(EDIT)->beg == 0);
         CHECK(getsel(EDIT)->end == 0);
-        CHECK(getsel(EDIT)->col == 0);
     }
     
-    TEST(right arrow should do nothing for empty buffer) {
-        setup_view(EDIT, "");
+    TEST(left should do nothing at beginning of buffer) {
+        setup_view(EDIT, "AB", 0);
+        key_handler(ModNone, KEY_LEFT);
+        CHECK(getsel(EDIT)->beg == 0);
+        CHECK(getsel(EDIT)->end == 0);
+    }
+    
+    TEST(left should move left by one rune) {
+        setup_view(EDIT, "AB", 1);
+        key_handler(ModNone, KEY_LEFT);
+        CHECK(getsel(EDIT)->beg == 0);
+        CHECK(getsel(EDIT)->end == 0);
+    }
+    
+    TEST(right should do nothing for empty buffer) {
+        setup_view(EDIT, "", 0);
         key_handler(ModNone, KEY_RIGHT);
         CHECK(getsel(EDIT)->beg == 0);
         CHECK(getsel(EDIT)->end == 0);
-        CHECK(getsel(EDIT)->col == 0);
     }
     
-    TEST(up arrow should do nothing for empty buffer) {
-        setup_view(EDIT, "");
+    TEST(right should do nothing at end of buffer) {
+        setup_view(EDIT, "AB", 2);
+        key_handler(ModNone, KEY_RIGHT);
+        CHECK(getsel(EDIT)->beg == 2);
+        CHECK(getsel(EDIT)->end == 2);
+    }
+    
+    TEST(right should move right by one rune) {
+        setup_view(EDIT, "AB", 1);
+        key_handler(ModNone, KEY_RIGHT);
+        CHECK(getsel(EDIT)->beg == 2);
+        CHECK(getsel(EDIT)->end == 2);
+    }
+    
+    TEST(up should do nothing for empty buffer) {
+        setup_view(EDIT, "", 0);
         key_handler(ModNone, KEY_UP);
         CHECK(getsel(EDIT)->beg == 0);
         CHECK(getsel(EDIT)->end == 0);
-        CHECK(getsel(EDIT)->col == 0);
     }
     
-    TEST(down arrow should do nothing for empty buffer) {
-        setup_view(EDIT, "");
+    TEST(up should move cursor up one line) {
+        setup_view(EDIT, "AB\nCD", 4);
+        key_handler(ModNone, KEY_UP);
+        CHECK(getsel(EDIT)->beg == 1);
+        CHECK(getsel(EDIT)->end == 1);
+    }
+    
+    TEST(up should do nothing for first line) {
+        setup_view(EDIT, "AB\nCD", 1);
+        key_handler(ModNone, KEY_UP);
+        CHECK(getsel(EDIT)->beg == 1);
+        CHECK(getsel(EDIT)->end == 1);
+    }
+    
+    TEST(down should do nothing for empty buffer) {
+        setup_view(EDIT, "", 0);
         key_handler(ModNone, KEY_DOWN);
         CHECK(getsel(EDIT)->beg == 0);
         CHECK(getsel(EDIT)->end == 0);
-        CHECK(getsel(EDIT)->col == 0);
+    }    
+    
+    TEST(down should move down one line) {
+        setup_view(EDIT, "AB\nCD", 1);
+        key_handler(ModNone, KEY_DOWN);
+        CHECK(getsel(EDIT)->beg == 4);
+        CHECK(getsel(EDIT)->end == 4);
+    }
+    
+    TEST(down should do nothing on last line) {
+        setup_view(EDIT, "AB\nCD", 4);
+        key_handler(ModNone, KEY_DOWN);
+        CHECK(getsel(EDIT)->beg == 4);
+        CHECK(getsel(EDIT)->end == 4);
     }
     
     TEST(home should do nothing for empty buffer) {
-        setup_view(EDIT, "");
+        setup_view(EDIT, "", 0);
         key_handler(ModNone, KEY_HOME);
         CHECK(getsel(EDIT)->beg == 0);
         CHECK(getsel(EDIT)->end == 0);
-        CHECK(getsel(EDIT)->col == 0);
+    }
+    
+    TEST(home should move to beginning of indented content) {
+        setup_view(EDIT, "    ABCD", 7);
+        key_handler(ModNone, KEY_HOME);
+        CHECK(getsel(EDIT)->beg == 4);
+        CHECK(getsel(EDIT)->end == 4);
+    }
+    
+    TEST(home should move to beginning of line if at beginning of indented content) {
+        setup_view(EDIT, "    ABCD", 7);
+        key_handler(ModNone, KEY_HOME);
+        CHECK(getsel(EDIT)->beg == 4);
+        CHECK(getsel(EDIT)->end == 4);
+    }
+    
+    TEST(home should move to beginning of indented content when at beginning of line) {
+        setup_view(EDIT, "    ABCD", 0);
+        key_handler(ModNone, KEY_HOME);
+        CHECK(getsel(EDIT)->beg == 4);
+        CHECK(getsel(EDIT)->end == 4);
     }
     
     TEST(end should do nothing for empty buffer) {
-        setup_view(EDIT, "");
+        setup_view(EDIT, "", 0);
         key_handler(ModNone, KEY_END);
         CHECK(getsel(EDIT)->beg == 0);
         CHECK(getsel(EDIT)->end == 0);
-        CHECK(getsel(EDIT)->col == 0);
     }
-}
\ No newline at end of file
+    
+    TEST(end should do nothing at end of line) {
+        setup_view(EDIT, "AB\nCD", 2);
+        key_handler(ModNone, KEY_END);
+        CHECK(getsel(EDIT)->beg == 2);
+        CHECK(getsel(EDIT)->end == 2);
+    }
+    
+    TEST(end should move to end of line) {
+        setup_view(EDIT, "AB\nCD", 0);
+        key_handler(ModNone, KEY_END);
+        CHECK(getsel(EDIT)->beg == 2);
+        CHECK(getsel(EDIT)->end == 2);
+    }
+}
diff --git a/xedit.c b/xedit.c
index 2161177e9c97ae4d0ef15e7a4340dcf4aca60a2c..e7b76480d328e721333bff2f16f636302bde5874 100644 (file)
--- a/xedit.c
+++ b/xedit.c
@@ -142,10 +142,10 @@ static KeyBinding Bindings[] = {
     { ModCtrl, ']', add_indent },
 
     /* Common Special Keys */
-    { ModNone, KEY_PGUP,      page_up       },
-    { ModNone, KEY_PGDN,      page_dn       },
-    { ModAny,  KEY_DELETE,    delete        },
-    { ModAny,  KEY_BACKSPACE, backspace     },
+    { ModNone, KEY_PGUP,      page_up   },
+    { ModNone, KEY_PGDN,      page_dn   },
+    { ModAny,  KEY_DELETE,    delete    },
+    { ModAny,  KEY_BACKSPACE, backspace },
 
     /* Cursor Movements */
     { ModAny, KEY_HOME,  cursor_home  },