From: Olaf Wintermann Date: Mon, 9 Mar 2026 20:17:06 +0000 (+0100) Subject: add more markdow editor tests X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=8ab00e76908e10954fb460a571b0d9b9a2979650;p=note.git add more markdow editor tests --- diff --git a/application/tests/test-editor.c b/application/tests/test-editor.c index dda0752..d5b5043 100644 --- a/application/tests/test-editor.c +++ b/application/tests/test-editor.c @@ -443,28 +443,42 @@ static int md_equal(cxmutstr md0, cxmutstr md1) { return para1 == NULL; } +CX_TEST_SUBROUTINE(test_editor_markdown_load_get, cxmutstr md0) { + UiObject *obj = ui_simple_window("test"); + CxAllocator *a = ui_allocator(obj->ctx); + + Note note; + memset(¬e, 0, sizeof(Note)); + note.model = notemodel_create(a); + + UiText *text = note.model->text; + UIWIDGET textview = ui_textarea(obj, .value = text); + + editor_init_textview(obj, ui_textarea_gettextwidget(textview)); + editor_init_textbuf(text); + + editor_load_markdown(¬e, textview, md0); + cxmutstr mdtext = editor_get_markdown(text, a); + CX_TEST_ASSERT(md_equal(md0, mdtext)); + + // TODO: cleanup + ui_close(obj); +} + CX_TEST(test_editor_load_markdown_para1) { CX_TEST_DO { - UiObject *obj = ui_simple_window("test"); - CxAllocator *a = ui_allocator(obj->ctx); - - Note note; - memset(¬e, 0, sizeof(Note)); - note.model = notemodel_create(a); - - UiText *text = note.model->text; - UIWIDGET textview = ui_textarea(obj, .value = text); - - editor_init_textview(obj, ui_textarea_gettextwidget(textview)); - editor_init_textbuf(text); - - cxmutstr md0 = cx_mutstr("Hello World\n\nParagraph 2"); - - editor_load_markdown(¬e, textview, md0); - cxmutstr mdtext = editor_get_markdown(text, a); - CX_TEST_ASSERT(md_equal(md0, mdtext)); - - // TODO: cleanup - ui_close(obj); + CX_TEST_CALL_SUBROUTINE(test_editor_markdown_load_get, cx_mutstr("Hello World\n\nParagraph 2")); + } +} + +CX_TEST(test_editor_load_markdown_heading_para) { + CX_TEST_DO { + CX_TEST_CALL_SUBROUTINE(test_editor_markdown_load_get, cx_mutstr("# Heading 1\n\nParagraph text\n\n## Heading 2\n\nText Paragraph 2\n")); + } +} + +CX_TEST(test_editor_load_markdown_list1) { + CX_TEST_DO { + CX_TEST_CALL_SUBROUTINE(test_editor_markdown_load_get, cx_mutstr("Bullet list\n\n - Element 1\n - Element 2\n -n Element 3\n\nEnd.")); } } diff --git a/application/tests/test-editor.h b/application/tests/test-editor.h index 641af2c..2096eba 100644 --- a/application/tests/test-editor.h +++ b/application/tests/test-editor.h @@ -43,6 +43,8 @@ CX_TEST(test_mddoc_linearization); CX_TEST(test_editor_load_markdown_simple); CX_TEST(test_editor_load_markdown_para1); +CX_TEST(test_editor_load_markdown_heading_para); +CX_TEST(test_editor_load_markdown_list1); #ifdef __cplusplus } diff --git a/application/tests/testmain.c b/application/tests/testmain.c index 3e650c7..b2b39e2 100644 --- a/application/tests/testmain.c +++ b/application/tests/testmain.c @@ -84,6 +84,8 @@ int main(int argc, char **argv) { cx_test_register(suite, test_editor_load_markdown_simple); cx_test_register(suite, test_editor_load_markdown_para1); + cx_test_register(suite, test_editor_load_markdown_heading_para); + cx_test_register(suite, test_editor_load_markdown_list1); cx_test_register(suite, test_text_search_strcasestr); cx_test_register(suite, test_text_search_cs);