Skip to content

Commit

Permalink
Test subdocument creation and rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Ericson2314 committed Jan 18, 2024
1 parent eb1a857 commit bd46a95
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,64 @@ static void test_feed_across_line_ending(test_batch_runner *runner) {
cmark_node_free(document);
}

static void sub_document(test_batch_runner *runner) {
cmark_node *doc = cmark_node_new(CMARK_NODE_NO_OP);
cmark_node *list = cmark_node_new(CMARK_NODE_LIST);
OK(runner, cmark_node_append_child(doc, list), "list");

{
static const char markdown[] =
"Hello &ldquo; <http://www.google.com>\n";
cmark_node *item = cmark_node_new(CMARK_NODE_ITEM);
OK(runner, cmark_node_append_child(list, item), "item0");
cmark_node *sub_doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
OK(runner, cmark_node_append_child(item, sub_doc), "append0");
}

{
static const char markdown[] =
"Bye &ldquo; <http://www.geocities.com>\n";
cmark_node *item = cmark_node_new(CMARK_NODE_ITEM);
OK(runner, cmark_node_append_child(list, item), "item1");
cmark_node *sub_doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
OK(runner, cmark_node_append_child(item, sub_doc), "append1");
}

char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT);
STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
"<document xmlns=\"http://commonmark.org/xml/1.0\">\n"
" <list type=\"bullet\" tight=\"false\">\n"
" <item>\n"
" <paragraph>\n"
" <text xml:space=\"preserve\">Hello “ </text>\n"
" <link destination=\"http://www.google.com\">\n"
" <text xml:space=\"preserve\">http://www.google.com</text>\n"
" </link>\n"
" </paragraph>\n"
" </item>\n"
" <item>\n"
" <paragraph>\n"
" <text xml:space=\"preserve\">Bye “ </text>\n"
" <link destination=\"http://www.geocities.com\">\n"
" <text xml:space=\"preserve\">http://www.geocities.com</text>\n"
" </link>\n"
" </paragraph>\n"
" </item>\n"
" </list>\n"
"</document>\n",
"nested document XML is as expected");
free(xml);

char *cmark = cmark_render_commonmark(doc, CMARK_OPT_DEFAULT, 0);
STR_EQ(runner, cmark, " - Hello “ <http://www.google.com>\n"
"\n"
" - Bye “ <http://www.geocities.com>\n",
"nested document CommonMark is as expected");

cmark_node_free(doc);
}

static void source_pos(test_batch_runner *runner) {
static const char markdown[] =
"# Hi *there*.\n"
Expand Down Expand Up @@ -1094,6 +1152,7 @@ int main(void) {
test_cplusplus(runner);
test_safe(runner);
test_feed_across_line_ending(runner);
sub_document(runner);
source_pos(runner);
source_pos_inlines(runner);
ref_source_pos(runner);
Expand Down

0 comments on commit bd46a95

Please sign in to comment.