diff options
Diffstat (limited to 'test/text.c')
| -rw-r--r-- | test/text.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/test/text.c b/test/text.c index 43decda..459bd13 100644 --- a/test/text.c +++ b/test/text.c @@ -14,7 +14,7 @@ void test_add_text() { uint32_t lines_added, cols_added; struct text *t = text_create(10); const char *txt = "This is line 1\n"; - text_append_at(t, 0, 0, (uint8_t *)txt, strlen(txt), &lines_added, + text_insert_at(t, 0, 0, (uint8_t *)txt, strlen(txt), &lines_added, &cols_added); ASSERT(text_num_lines(t) == 2, "Expected text to have two lines after insertion"); @@ -25,7 +25,7 @@ void test_add_text() { "Expected line 1 to be line 1"); const char *txt2 = "This is line 2\n"; - text_append_at(t, 1, 0, (uint8_t *)txt2, strlen(txt2), &lines_added, + text_insert_at(t, 1, 0, (uint8_t *)txt2, strlen(txt2), &lines_added, &cols_added); ASSERT(text_num_lines(t) == 3, "Expected text to have three lines after second insertion"); @@ -34,7 +34,7 @@ void test_add_text() { // simulate indentation const char *txt3 = " "; - text_append_at(t, 0, 0, (uint8_t *)txt3, strlen(txt3), &lines_added, + text_insert_at(t, 0, 0, (uint8_t *)txt3, strlen(txt3), &lines_added, &cols_added); ASSERT(text_num_lines(t) == 3, "Expected text to have three lines after second insertion"); @@ -50,7 +50,7 @@ void test_delete_text() { uint32_t lines_added, cols_added; struct text *t = text_create(10); const char *txt = "This is line 1"; - text_append_at(t, 0, 0, (uint8_t *)txt, strlen(txt), &lines_added, + text_insert_at(t, 0, 0, (uint8_t *)txt, strlen(txt), &lines_added, &cols_added); text_delete(t, 0, 12, 2); @@ -65,7 +65,7 @@ void test_delete_text() { "Expected line to be empty after many chars removed"); const char *txt2 = "This is line 1\nThis is line 2\nThis is line 3"; - text_append_at(t, 0, 0, (uint8_t *)txt2, strlen(txt2), &lines_added, + text_insert_at(t, 0, 0, (uint8_t *)txt2, strlen(txt2), &lines_added, &cols_added); ASSERT(text_num_lines(t) == 3, "Expected to have three lines after inserting as many"); @@ -86,7 +86,7 @@ void test_delete_text() { struct text *t3 = text_create(10); const char *delete_me = "This is line๐\nQ"; - text_append_at(t3, 0, 0, (uint8_t *)delete_me, strlen(delete_me), + text_insert_at(t3, 0, 0, (uint8_t *)delete_me, strlen(delete_me), &lines_added, &cols_added); text_delete(t3, 0, 13, 1); struct text_chunk top_line = text_get_line(t3, 0); @@ -97,10 +97,19 @@ void test_delete_text() { ASSERT(text_num_lines(t3) == 1, "Expected text to have one line after deleting newline"); + struct text *t4 = text_create(10); + const char *deletable_text = "Only one line kinda"; + text_append(t4, (uint8_t *)deletable_text, strlen(deletable_text), + &lines_added, &cols_added); + text_delete(t4, 0, 19, 1); + ASSERT(text_num_lines(t4) == 1, "Expected the line to still be there"); + ASSERT(text_line_length(t4, 0) == 19, + "Expected nothing to have happened to the line"); + // test utf-8 struct text *t2 = text_create(10); const char *txt3 = "Emojis: ๐ซ๐ฎ ๐ฎ\n"; - text_append_at(t2, 0, 0, (uint8_t *)txt3, strlen(txt3), &lines_added, + text_insert_at(t2, 0, 0, (uint8_t *)txt3, strlen(txt3), &lines_added, &cols_added); // TODO: Fix when graphemes are implemented, should be 11, right now it counts |
