diff options
| author | Albert Cervin <albert@acervin.com> | 2022-12-21 15:29:21 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2022-12-21 15:29:21 +0100 |
| commit | 690786504fce73edea78c7ec13b34771771e4caf (patch) | |
| tree | 0a8927e6ab88bb5118eca569fdc4ae3593d7f178 /test | |
| parent | a817e01bfe2356fdd860010d46db4e4361f343a6 (diff) | |
| download | dged-690786504fce73edea78c7ec13b34771771e4caf.tar.gz dged-690786504fce73edea78c7ec13b34771771e4caf.tar.xz dged-690786504fce73edea78c7ec13b34771771e4caf.zip | |
wip render rework
Diffstat (limited to 'test')
| -rw-r--r-- | test/text.c | 23 | ||||
| -rw-r--r-- | test/utf8.c | 6 |
2 files changed, 20 insertions, 9 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 diff --git a/test/utf8.c b/test/utf8.c index 5b020c3..88e6a8c 100644 --- a/test/utf8.c +++ b/test/utf8.c @@ -3,10 +3,12 @@ #include "test.h" #include "wchar.h" +#include <string.h> + void test_nchars_nbytes() { - ASSERT(utf8_nchars((uint8_t *)"๐ด", 2) == 1, + ASSERT(utf8_nchars((uint8_t *)"๐ด", strlen("๐ด")) == 1, "Expected old man emoji to be 1 char"); - ASSERT(utf8_nbytes((uint8_t *)"๐ด", 1) == 4, + ASSERT(utf8_nbytes((uint8_t *)"๐ด", strlen("๐ด"), 1) == 4, "Expected old man emoji to be 4 bytes"); } |
