summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/buffer.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/test/buffer.c b/test/buffer.c
index 19fca8c..f4aefc5 100644
--- a/test/buffer.c
+++ b/test/buffer.c
@@ -17,4 +17,35 @@ void test_add() {
"Expected buffer to have one line with characters");
}
-void run_buffer_tests() { run_test(test_add); }
+void test_word_at() {
+ struct buffer b = buffer_create("test-word-at-buffer");
+ const char *txt = "word1 (word2). Another";
+ buffer_add(&b, (struct location){.line = 0, .col = 0}, (uint8_t *)txt,
+ strlen(txt));
+
+ struct region word1 =
+ buffer_word_at(&b, (struct location){.line = 0, .col = 0});
+ ASSERT(region_has_size(word1), "expected 0,0 to be a word");
+ ASSERT(word1.begin.col == 0 && word1.end.col == 5,
+ "Expected word to end at col 5");
+
+ // test that dot can be in the middle of a word
+ // and that '(' and ')' works as a delimiter
+ struct region word2 =
+ buffer_word_at(&b, (struct location){.line = 0, .col = 8});
+ ASSERT(region_has_size(word2), "expected 0,8 to be in a word");
+ ASSERT(word2.begin.col == 7 && word2.end.col == 12,
+ "Expected word to span cols 7..12");
+
+ // test that clamping works correctly
+ struct region word3 =
+ buffer_word_at(&b, (struct location){.line = 0, .col = 100});
+ ASSERT(region_has_size(word3), "expected 0,100 to be in the last word");
+ ASSERT(word3.begin.col == 15 && word3.end.col == 22,
+ "Expected word to span cols 15..22");
+}
+
+void run_buffer_tests() {
+ run_test(test_add);
+ run_test(test_word_at);
+}