From 3deb7c91056779d1f1b2be112e727bc9999ac21d Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Fri, 16 Dec 2022 16:53:18 +0100 Subject: Some text fixes --- test/text.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'test') diff --git a/test/text.c b/test/text.c index 9073553..43decda 100644 --- a/test/text.c +++ b/test/text.c @@ -14,7 +14,8 @@ 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(t, 0, 0, (uint8_t *)txt, strlen(txt), &lines_added, &cols_added); + text_append_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"); @@ -24,13 +25,24 @@ void test_add_text() { "Expected line 1 to be line 1"); const char *txt2 = "This is line 2\n"; - text_append(t, 1, 0, (uint8_t *)txt2, strlen(txt2), &lines_added, - &cols_added); + text_append_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"); ASSERT_STR_EQ((const char *)text_get_line(t, 1).text, "This is line 2", "Expected line 2 to be line 2"); + // simulate indentation + const char *txt3 = " "; + text_append_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"); + ASSERT_STR_EQ((const char *)text_get_line(t, 0).text, " This is line 1", + "Expected line 1 to be indented"); + ASSERT_STR_EQ((const char *)text_get_line(t, 1).text, "This is line 2", + "Expected line 2 to be line 2 still"); + text_destroy(t); } @@ -38,7 +50,8 @@ 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(t, 0, 0, (uint8_t *)txt, strlen(txt), &lines_added, &cols_added); + text_append_at(t, 0, 0, (uint8_t *)txt, strlen(txt), &lines_added, + &cols_added); text_delete(t, 0, 12, 2); ASSERT(text_line_length(t, 0) == 12, @@ -52,8 +65,8 @@ 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(t, 0, 0, (uint8_t *)txt2, strlen(txt2), &lines_added, - &cols_added); + text_append_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"); @@ -73,8 +86,8 @@ void test_delete_text() { struct text *t3 = text_create(10); const char *delete_me = "This is line๐ŸŽ™\nQ"; - text_append(t3, 0, 0, (uint8_t *)delete_me, strlen(delete_me), &lines_added, - &cols_added); + text_append_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); ASSERT(strncmp((const char *)top_line.text, "This is line๐ŸŽ™Q", @@ -87,8 +100,8 @@ void test_delete_text() { // test utf-8 struct text *t2 = text_create(10); const char *txt3 = "Emojis: ๐Ÿ‡ซ๐Ÿ‡ฎ ๐Ÿฎ\n"; - text_append(t2, 0, 0, (uint8_t *)txt3, strlen(txt3), &lines_added, - &cols_added); + text_append_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 // the two unicode code points ๐Ÿ‡ซ and ๐Ÿ‡ฎ as two chars. -- cgit v1.2.3