summaryrefslogtreecommitdiff
path: root/test/buffer.c
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2024-02-12 16:28:37 +0100
committerAlbert Cervin <albert@acervin.com>2024-02-14 13:08:51 +0100
commit0b524a94a5e34148716832f1b6cada02e35369b0 (patch)
treec0b31aab359c2bac7300a3c95a2f50ee62572048 /test/buffer.c
parent7baa6f58d4fe8b00ec5ee7dd72a8cb32ef52c079 (diff)
downloaddged-0b524a94a5e34148716832f1b6cada02e35369b0.tar.gz
dged-0b524a94a5e34148716832f1b6cada02e35369b0.tar.xz
dged-0b524a94a5e34148716832f1b6cada02e35369b0.zip
Improve word deletion
Now it only deletes the word under dot.
Diffstat (limited to 'test/buffer.c')
-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);
+}