CHECK(TestBuf.status != MODIFIED);
}
+ /* Basic Operation
+ *************************************************************************/
+ TEST(buffer should grow to fit data)
+ {
+ size_t datasz = 2*1024*1024;
+ char* data = malloc(datasz);
+ memset(data, '.', datasz);
+ data[datasz - 1] = '\0';
+ buf_init(&TestBuf);
+ buf_puts(&TestBuf, data);
+ int result = buffer_equals(data);
+ free(data);
+ CHECK(result);
+ }
+
/* Movements
*************************************************************************/
- // Start of Line
TEST(buf_bol should return 0 if column 1 of first line)
{
set_buffer_text("ab\ncd");
// printf("%lu\n", TestBuf.selection.end);
// CHECK(8 == TestBuf.selection.end);
// }
+
+ /* Context-Sensitive Selection
+ *************************************************************************/
+ TEST(buf_selctx should select from ( to ))
+ {
+ set_buffer_text("(...)");
+ TestBuf.selection = (Sel){ .beg = 0, .end = 0 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(4 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 4, .end = 4 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(4 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should select from < to >)
+ {
+ set_buffer_text("<...>");
+ TestBuf.selection = (Sel){ .beg = 0, .end = 0 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(4 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 4, .end = 4 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(4 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should select from [ to ])
+ {
+ set_buffer_text("[...]");
+ TestBuf.selection = (Sel){ .beg = 0, .end = 0 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(4 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 4, .end = 4 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(4 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should select from { to })
+ {
+ set_buffer_text("{...}");
+ TestBuf.selection = (Sel){ .beg = 0, .end = 0 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(4 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 4, .end = 4 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(4 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should do nothing for unbalanced block)
+ {
+ set_buffer_text("...}{...");
+ TestBuf.selection = (Sel){ .beg = 3, .end = 3 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(3 == buf_selbeg(&TestBuf));
+ CHECK(3 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 4, .end = 4 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(4 == buf_selbeg(&TestBuf));
+ CHECK(4 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should select '"' quotes)
+ {
+ set_buffer_text(" \"...\" ");
+ TestBuf.selection = (Sel){ .beg = 1, .end = 1 }; // opening quote
+ buf_selctx(&TestBuf, risword);
+ CHECK(2 == buf_selbeg(&TestBuf));
+ CHECK(5 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 2, .end = 2 }; // first char of quote
+ buf_selctx(&TestBuf, risword);
+ CHECK(2 == buf_selbeg(&TestBuf));
+ CHECK(5 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 4, .end = 4 }; // last char of quote
+ buf_selctx(&TestBuf, risword);
+ CHECK(2 == buf_selbeg(&TestBuf));
+ CHECK(5 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should select '`' quotes)
+ {
+ set_buffer_text(" `...` ");
+ TestBuf.selection = (Sel){ .beg = 1, .end = 1 }; // opening quote
+ buf_selctx(&TestBuf, risword);
+ CHECK(2 == buf_selbeg(&TestBuf));
+ CHECK(5 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 2, .end = 2 }; // first char of quote
+ buf_selctx(&TestBuf, risword);
+ CHECK(2 == buf_selbeg(&TestBuf));
+ CHECK(5 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 4, .end = 4 }; // last char of quote
+ buf_selctx(&TestBuf, risword);
+ CHECK(2 == buf_selbeg(&TestBuf));
+ CHECK(5 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should select '\'' quotes)
+ {
+ set_buffer_text(" '...' ");
+ TestBuf.selection = (Sel){ .beg = 1, .end = 1 }; // opening quote
+ buf_selctx(&TestBuf, risword);
+ CHECK(2 == buf_selbeg(&TestBuf));
+ CHECK(5 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 2, .end = 2 }; // first char of quote
+ buf_selctx(&TestBuf, risword);
+ CHECK(2 == buf_selbeg(&TestBuf));
+ CHECK(5 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 4, .end = 4 }; // last char of quote
+ buf_selctx(&TestBuf, risword);
+ CHECK(2 == buf_selbeg(&TestBuf));
+ CHECK(5 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should select word using risword)
+ {
+ set_buffer_text(" abc/def ");
+ TestBuf.selection = (Sel){ .beg = 1, .end = 1 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(4 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 5, .end = 5 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(5 == buf_selbeg(&TestBuf));
+ CHECK(8 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should select word using risbigword)
+ {
+ set_buffer_text(" abc/def ");
+ TestBuf.selection = (Sel){ .beg = 1, .end = 1 };
+ buf_selctx(&TestBuf, risbigword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(8 == buf_selend(&TestBuf));
+ TestBuf.selection = (Sel){ .beg = 5, .end = 5 };
+ buf_selctx(&TestBuf, risbigword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(8 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should select big word on non word character)
+ {
+ set_buffer_text(" abc/def ");
+ TestBuf.selection = (Sel){ .beg = 4, .end = 4 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(1 == buf_selbeg(&TestBuf));
+ CHECK(8 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should select line on bol)
+ {
+ set_buffer_text("\n...\n");
+ TestBuf.selection = (Sel){ .beg = 2, .end = 2 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(2 == buf_selbeg(&TestBuf));
+ CHECK(7 == buf_selend(&TestBuf));
+ }
+
+ TEST(buf_selctx should select line on eol)
+ {
+ set_buffer_text("\n...\n");
+ TestBuf.selection = (Sel){ .beg = 4, .end = 4 };
+ buf_selctx(&TestBuf, risword);
+ CHECK(2 == buf_selbeg(&TestBuf));
+ CHECK(5 == buf_selend(&TestBuf));
+ }
+
+ /* String Retrieval
+ *************************************************************************/
+ TEST(buf_getsat should get string defined by range)
+ {
+ set_buffer_text(" abc/def ");
+ char* str = buf_getsat(&TestBuf, 1, 8);
+ int result = !strcmp(str, "abc/def");
+ free(str);
+ CHECK(result);
+ }
+
+ TEST(buf_fetch should get string defined by function)
+ {
+ set_buffer_text(" abc/def ");
+ TestBuf.selection = (Sel){ .beg = 0, .end = 1 };
+ char* str = buf_fetch(&TestBuf, risbigword, 4);
+ int result = !strcmp(str, "abc/def");
+ free(str);
+ CHECK(result);
+ TestBuf.selection = (Sel){ .beg = 1, .end = 8 };
+ str = buf_fetch(&TestBuf, risbigword, 4);
+ result = !strcmp(str, "abc/def");
+ free(str);
+ CHECK(result);
+ }
}