diff options
| author | Albert Cervin <albert@acervin.com> | 2023-02-11 23:03:39 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2023-02-15 23:41:35 +0100 |
| commit | e45499816eab8abadbdd5bb6dd79b526a4ed6648 (patch) | |
| tree | 3cdcb0238aaae8ed1b3578e4ad71883f0702de3c /test/text.c | |
| parent | c2976cea9bbca465712534b7e523783e2ccc6c6e (diff) | |
| download | dged-e45499816eab8abadbdd5bb6dd79b526a4ed6648.tar.gz dged-e45499816eab8abadbdd5bb6dd79b526a4ed6648.tar.xz dged-e45499816eab8abadbdd5bb6dd79b526a4ed6648.zip | |
Implement undo
This also fixes a bunch of valgrind errors
Diffstat (limited to 'test/text.c')
| -rw-r--r-- | test/text.c | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/test/text.c b/test/text.c index 9c8d825..cb18df5 100644 --- a/test/text.c +++ b/test/text.c @@ -8,6 +8,10 @@ #include <string.h> #include <wchar.h> +void assert_line_eq(struct text_chunk line, const char *txt, const char *msg) { + ASSERT(strncmp((const char *)line.text, txt, line.nbytes) == 0, msg); +} + void assert_line_equal(struct text_chunk *line) {} void test_add_text() { @@ -24,16 +28,16 @@ void test_add_text() { ASSERT(text_line_size(t, 0) == 14 && text_line_length(t, 0) == 14, "Expected line 1 to have 14 chars and 14 bytes"); - ASSERT_STR_EQ((const char *)text_get_line(t, 0).text, "This is line 1", - "Expected line 1 to be line 1"); + assert_line_eq(text_get_line(t, 0), "This is line 1", + "Expected line 1 to be line 1"); const char *txt2 = "This is line 2\n"; text_insert_at(t, 1, 0, (uint8_t *)txt2, strlen(txt2), &lines_added, &cols_added); ASSERT(text_num_lines(t) == 2, "Expected text to have two 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"); + assert_line_eq(text_get_line(t, 1), "This is line 2", + "Expected line 2 to be line 2"); // simulate indentation const char *txt3 = " "; @@ -41,19 +45,18 @@ void test_add_text() { &cols_added); ASSERT(text_num_lines(t) == 2, "Expected text to have two 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"); + assert_line_eq(text_get_line(t, 0), " This is line 1", + "Expected line 1 to be indented"); + assert_line_eq(text_get_line(t, 1), "This is line 2", + "Expected line 2 to be line 2 still"); // insert newline in middle of line text_insert_at(t, 1, 4, (uint8_t *)"\n", 1, &lines_added, &cols_added); ASSERT(text_num_lines(t) == 3, "Expected text to have three lines after inserting a new line"); - ASSERT_STR_EQ((const char *)text_get_line(t, 1).text, "This", - "Expected line 2 to be split"); - ASSERT_STR_EQ((const char *)text_get_line(t, 2).text, " is line 2", - "Expected line 2 to be split"); + assert_line_eq(text_get_line(t, 1), "This", "Expected line 2 to be split"); + assert_line_eq(text_get_line(t, 2), " is line 2", + "Expected line 2 to be split"); // insert newline before line 1 text_insert_at(t, 1, 0, (uint8_t *)"\n", 1, &lines_added, &cols_added); @@ -61,10 +64,10 @@ void test_add_text() { text_num_lines(t) == 4, "Expected to have four lines after adding an empty line in the middle"); ASSERT(text_line_length(t, 1) == 0, "Expected line 2 to be empty"); - ASSERT_STR_EQ((const char *)text_get_line(t, 2).text, "This", - "Expected line 3 to be previous line 2"); - ASSERT_STR_EQ((const char *)text_get_line(t, 3).text, " is line 2", - "Expected line 4 to be previous line 3"); + assert_line_eq(text_get_line(t, 2), "This", + "Expected line 3 to be previous line 2"); + assert_line_eq(text_get_line(t, 3), " is line 2", + "Expected line 4 to be previous line 3"); text_destroy(t); } @@ -151,6 +154,7 @@ void test_delete_text() { text_destroy(t); text_destroy(t2); text_destroy(t3); + text_destroy(t4); } void run_text_tests() { |
