summaryrefslogtreecommitdiff
path: root/api_test
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2015-01-10 16:10:35 +0100
committerNick Wellnhofer <wellnhofer@aevum.de>2015-01-10 17:40:13 +0100
commit009c3847f004fda437dd5376a9452973b1cb913e (patch)
treef1e51be8affaa4c46231fd10590acc674b21bf16 /api_test
parentd548d56d604193e4eebb4ab81c347887763b7d69 (diff)
Rework iterators
* Advance to the next node when calling 'cmark_iter_next', not when calling 'cmark_iter_get_node'. * Add 'cmark_iter_get_event_type' accessor. * Allow deletion of nodes after an 'EXIT' event, or an 'ENTER' event for leaf nodes.
Diffstat (limited to 'api_test')
-rw-r--r--api_test/main.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/api_test/main.c b/api_test/main.c
index d2e41d3..af40a9f 100644
--- a/api_test/main.c
+++ b/api_test/main.c
@@ -320,6 +320,46 @@ iterator(test_batch_runner *runner) {
}
static void
+iterator_delete(test_batch_runner *runner) {
+ static const char md[] =
+ "a *b* c\n"
+ "\n"
+ "* item1\n"
+ "* item2\n"
+ "\n"
+ "a `b` c\n"
+ "\n"
+ "* item1\n"
+ "* item2\n";
+ cmark_node *doc = cmark_parse_document(md, sizeof(md) - 1);
+ cmark_iter *iter = cmark_iter_new(doc);
+ cmark_event_type ev_type;
+
+ while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
+ cmark_node *node = cmark_iter_get_node(iter);
+ // Delete list, emph, and code nodes.
+ if ((ev_type == CMARK_EVENT_EXIT &&
+ node->type == CMARK_NODE_LIST) ||
+ (ev_type == CMARK_EVENT_EXIT &&
+ node->type == CMARK_NODE_EMPH) ||
+ (ev_type == CMARK_EVENT_ENTER &&
+ node->type == CMARK_NODE_CODE)) {
+ cmark_node_free(node);
+ }
+ }
+
+ char *html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
+ static const char expected[] =
+ "<p>a c</p>\n"
+ "<p>a c</p>\n";
+ STR_EQ(runner, html, expected, "iterate and delete nodes");
+
+ free(html);
+ cmark_iter_free(iter);
+ cmark_node_free(doc);
+}
+
+static void
create_tree(test_batch_runner *runner)
{
char *html;
@@ -630,6 +670,7 @@ int main() {
accessors(runner);
node_check(runner);
iterator(runner);
+ iterator_delete(runner);
create_tree(runner);
hierarchy(runner);
parser(runner);