summaryrefslogtreecommitdiff
path: root/api_test/main.c
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-12-13 14:13:58 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-12-13 19:40:21 -0800
commita3030f985a973b3b835645313fdad1a8a72ff432 (patch)
treee1b1b43b16102b106bc43f4dd5eee32bb11b2a73 /api_test/main.c
parent8d6efe632aaeb1831c86b27e120a344c5e3ee7d4 (diff)
Added iterator interface to API, removed cmark_walk.
* Added `iterator.c`, `iterator.h`. * Removed `cmark_walk`. * Replaced `cmark_walk` with iterator in HTML renderer. * Replaced API test for `cmark_walk` with simple iterator test.
Diffstat (limited to 'api_test/main.c')
-rw-r--r--api_test/main.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/api_test/main.c b/api_test/main.c
index c975060..42cc70d 100644
--- a/api_test/main.c
+++ b/api_test/main.c
@@ -293,27 +293,24 @@ node_check(test_batch_runner *runner) {
cmark_node_free(doc);
}
-static int
-S_handler(cmark_node *node, cmark_event_type ev_type, void *state)
-{
- int *textnodes = state;
- if (ev_type == CMARK_EVENT_ENTER) {
- if (node->type == CMARK_NODE_TEXT) {
- *textnodes += 1;
- }
- }
- return 1;
-}
-
static void
-walk(test_batch_runner *runner) {
- // Construct an incomplete tree.
+iterator(test_batch_runner *runner) {
cmark_node *doc = cmark_parse_document("> a *b*\n\nc", 10);
- int textnodes = 0;
- INT_EQ(runner, cmark_walk(doc, S_handler, &textnodes), 1,
- "walk succeeds");
- INT_EQ(runner, textnodes, 3, "walk correctly counts text nodes");
+ int parnodes = 0;
+ cmark_event_type ev_type;
+ cmark_iter *iter = cmark_iter_new(doc);
+ cmark_node *cur;
+
+ while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
+ cur = cmark_iter_get_node(iter);
+ if (cur->type == CMARK_NODE_PARAGRAPH &&
+ ev_type == CMARK_EVENT_ENTER) {
+ parnodes += 1;
+ }
+ }
+ INT_EQ(runner, parnodes, 2, "iterate correctly counts paragraphs");
+ cmark_iter_free(iter);
cmark_node_free(doc);
}
@@ -627,7 +624,7 @@ int main() {
constructor(runner);
accessors(runner);
node_check(runner);
- walk(runner);
+ iterator(runner);
create_tree(runner);
hierarchy(runner);
parser(runner);