]> git.mdlowis.com Git - projs/tide.git/commitdiff
reorganized tests for buf.c
authorMichael D. Lowis <mike@mdlowis.com>
Mon, 31 Oct 2016 22:08:01 +0000 (18:08 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Mon, 31 Oct 2016 22:08:01 +0000 (18:08 -0400)
buf.c
tests/buf.c

diff --git a/buf.c b/buf.c
index 754d24f0f89e046dc7e8abc3fe4eb90f8b4af4d3..9cd099c46b4e7d92f17ebdc6c3a67dec16d3b977 100644 (file)
--- a/buf.c
+++ b/buf.c
@@ -96,9 +96,6 @@ void buf_init(Buf* buf) {
 static void log_insert(Log** list, unsigned beg, unsigned end) {
     Log* log = *list;
     if (!log || log->locked || !log->insert || (log->data.ins.beg && beg < log->data.ins.beg-1) || end > log->data.ins.end+1) {
-        //if (log) printf("%d %d %d %d\n", log->locked, !log->insert, beg < log->data.ins.beg-1, end > log->data.ins.end+1);
-        //if (log) printf("%u < %u\n", beg, log->data.ins.beg-1);
-        //printf("new %u-%u\n", beg, end);
         Log* newlog  = (Log*)calloc(sizeof(Log), 1);
         newlog->insert = true;
         newlog->data.ins.beg = beg;
@@ -106,10 +103,8 @@ static void log_insert(Log** list, unsigned beg, unsigned end) {
         newlog->next = *list;
         *list = newlog;
     } else if (beg <= log->data.ins.beg) {
-        //puts("coalesce 1");
         log->data.ins.beg--;
     } else {
-        //puts("coalesce 2");
         log->data.ins.end++;
     }
 }
index 4619e8fe0ec180da6b0f8a2bba34d22e74572292..73f688b64c1aaeda864b6f6664d5c048d035ac3e 100644 (file)
@@ -4,6 +4,13 @@
 static Buf TestBuf;
 
 static void buf_clr(Buf* buf) {
+    //while (buf->undo) {
+    //    Log* deadite = buf->undo;
+    //    buf->undo = deadite->next;
+    //    if (!deadite->insert)
+    //        free(deadite->data.del.runes);
+    //    free(deadite);
+    //}
     free(buf->bufstart);
     buf_init(buf);
 }
@@ -36,6 +43,51 @@ TEST_SUITE(BufferTests) {
      *************************************************************************/
     /* Resizing
      *************************************************************************/
+    /* Insertions
+     *************************************************************************/
+    TEST(buf_ins should insert at 0 in empty buf) {
+        buf_clr(&TestBuf);
+        buf_ins(&TestBuf, 0, 'a');
+        CHECK(buf_text_eq("a"));
+    }
+
+    TEST(buf_ins should insert at 0) {
+        buf_clr(&TestBuf);
+        buf_ins(&TestBuf, 0, 'b');
+        buf_ins(&TestBuf, 0, 'a');
+        CHECK(buf_text_eq("ab"));
+    }
+
+    TEST(buf_ins should insert at 1) {
+        buf_clr(&TestBuf);
+        buf_ins(&TestBuf, 0, 'a');
+        buf_ins(&TestBuf, 1, 'b');
+        CHECK(buf_text_eq("ab"));
+    }
+
+    TEST(buf_ins should insert at 1) {
+        buf_clr(&TestBuf);
+        buf_ins(&TestBuf, 0, 'a');
+        buf_ins(&TestBuf, 1, 'c');
+        buf_ins(&TestBuf, 1, 'b');
+        CHECK(buf_text_eq("abc"));
+    }
+
+    TEST(buf_ins should sentence in larger text) {
+        set_buffer_text(
+            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam elementum eros quis venenatis. "
+        );
+
+        buf_ins(&TestBuf, 5, ' ');
+        buf_ins(&TestBuf, 6, 'a');
+
+        CHECK(buf_text_eq(
+            "Lorem a ipsum dolor sit amet, consectetur adipiscing elit. Aliquam elementum eros quis venenatis. "
+        ));
+    }
+
+    /* Deletions
+     *************************************************************************/
     /* Undo/Redo
      *************************************************************************/
     /* Locking
@@ -365,50 +417,8 @@ TEST_SUITE(BufferTests) {
         CHECK(5 == buf_setcol(&TestBuf, 4, 4));
     }
 
-    /* Insertions
-     *************************************************************************/
-    TEST(buf_ins should insert at 0 in empty buf) {
-        buf_clr(&TestBuf);
-        buf_ins(&TestBuf, 0, 'a');
-        CHECK(buf_text_eq("a"));
-    }
-
-    TEST(buf_ins should insert at 0) {
-        buf_clr(&TestBuf);
-        buf_ins(&TestBuf, 0, 'b');
-        buf_ins(&TestBuf, 0, 'a');
-        CHECK(buf_text_eq("ab"));
-    }
-
-    TEST(buf_ins should insert at 1) {
-        buf_clr(&TestBuf);
-        buf_ins(&TestBuf, 0, 'a');
-        buf_ins(&TestBuf, 1, 'b');
-        CHECK(buf_text_eq("ab"));
-    }
-
-    TEST(buf_ins should insert at 1) {
-        buf_clr(&TestBuf);
-        buf_ins(&TestBuf, 0, 'a');
-        buf_ins(&TestBuf, 1, 'c');
-        buf_ins(&TestBuf, 1, 'b');
-        CHECK(buf_text_eq("abc"));
-    }
-
-    TEST(buf_ins should sentence in larger text) {
-        set_buffer_text(
-            "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam elementum eros quis venenatis. "
-        );
-
-        buf_ins(&TestBuf, 5, ' ');
-        buf_ins(&TestBuf, 6, 'a');
-
-        CHECK(buf_text_eq(
-            "Lorem a ipsum dolor sit amet, consectetur adipiscing elit. Aliquam elementum eros quis venenatis. "
-        ));
+    TEST(buf_setcol should not set column past the last rune) {
+        set_buffer_text("abc\n\tdef");
+        CHECK(8 == buf_setcol(&TestBuf, 4, 100));
     }
-
-    /* Deletions
-     *************************************************************************/
-
 }