From 919cdb2c583163411b3b15b2eae0ce72cf2d7981 Mon Sep 17 00:00:00 2001 From: Yuki Izumi Date: Wed, 9 Aug 2017 15:56:21 +1000 Subject: Add sourcepos info for inlines --- api_test/main.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 3 deletions(-) (limited to 'api_test') diff --git a/api_test/main.c b/api_test/main.c index d720234..08f3c98 100644 --- a/api_test/main.c +++ b/api_test/main.c @@ -552,9 +552,9 @@ static void render_xml(test_batch_runner *runner) { STR_EQ(runner, xml, "\n" "\n" "\n" - " foo \n" - " \n" - " bar\n" + " foo \n" + " \n" + " bar\n" " \n" "\n", "render first paragraph with source pos"); @@ -883,6 +883,95 @@ static void test_feed_across_line_ending(test_batch_runner *runner) { cmark_node_free(document); } +static void source_pos(test_batch_runner *runner) { + static const char markdown[] = + "Hi *there*.\n" + "\n" + "Hello “ \n" + "there `hi` -- [okay](www.google.com (ok)).\n" + "\n" + "> 1. Okay.\n" + "> Sure.\n" + ">\n" + "> 2. Yes, okay.\n" + "> ![ok](hi \"yes\")\n"; + + cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT); + char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS); + STR_EQ(runner, xml, "\n" + "\n" + "\n" + " \n" + " Hi \n" + " \n" + " there\n" + " \n" + " .\n" + " \n" + " \n" + " Hello “ \n" + " \n" + " http://www.google.com\n" + " \n" + " \n" + " there \n" + " hi\n" + " -- \n" + " \n" + " okay\n" + " \n" + " .\n" + " \n" + " \n" + " \n" + " \n" + " \n" + " Okay.\n" + " \n" + " Sure.\n" + " \n" + " \n" + " \n" + " \n" + " Yes, okay.\n" + " \n" + " \n" + " ok\n" + " \n" + " \n" + " \n" + " \n" + " \n" + "\n", + "sourcepos are as expected"); + free(xml); + cmark_node_free(doc); +} + +static void ref_source_pos(test_batch_runner *runner) { + static const char markdown[] = + "Let's try [reference] links.\n" + "\n" + "[reference]: https://github.com (GitHub)\n"; + + cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT); + char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS); + STR_EQ(runner, xml, "\n" + "\n" + "\n" + " \n" + " Let's try \n" + " \n" + " reference\n" + " \n" + " links.\n" + " \n" + "\n", + "sourcepos are as expected"); + free(xml); + cmark_node_free(doc); +} + int main() { int retval; test_batch_runner *runner = test_batch_runner_new(); @@ -908,6 +997,8 @@ int main() { test_cplusplus(runner); test_safe(runner); test_feed_across_line_ending(runner); + source_pos(runner); + ref_source_pos(runner); test_print_summary(runner); retval = test_ok(runner) ? 0 : 1; -- cgit v1.2.3