diff options
-rw-r--r-- | api_test/main.c | 35 | ||||
-rw-r--r-- | src/node.c | 19 |
2 files changed, 54 insertions, 0 deletions
diff --git a/api_test/main.c b/api_test/main.c index e17beda..933a4bd 100644 --- a/api_test/main.c +++ b/api_test/main.c @@ -37,6 +37,40 @@ test_content(test_batch_runner *runner, cmark_node_type type, int allowed_content); static void +constructor(test_batch_runner *runner) +{ + for (int i = 0; i < num_node_types; ++i) { + cmark_node_type type = node_types[i]; + cmark_node *node = cmark_node_new(type); + OK(runner, node != NULL, "new type %d", type); + + switch (node->type) { + case CMARK_NODE_ATX_HEADER: + case CMARK_NODE_SETEXT_HEADER: + INT_EQ(runner, cmark_node_get_header_level(node), 1, + "default header level is 1"); + node->as.header.level = 1; + break; + + case CMARK_NODE_LIST: + INT_EQ(runner, cmark_node_get_list_type(node), + CMARK_BULLET_LIST, + "default is list type is bullet"); + INT_EQ(runner, cmark_node_get_list_start(node), 1, + "default is list start is 1"); + INT_EQ(runner, cmark_node_get_list_tight(node), 0, + "default is list is loose"); + break; + + default: + break; + } + + cmark_node_destroy(node); + } +} + +static void accessors(test_batch_runner *runner) { static const unsigned char markdown[] = @@ -398,6 +432,7 @@ int main() { int retval; test_batch_runner *runner = test_batch_runner_new(); + constructor(runner); accessors(runner); create_tree(runner); hierarchy(runner); @@ -11,6 +11,25 @@ cmark_node* cmark_node_new(cmark_node_type type) { cmark_node *node = (cmark_node *)calloc(1, sizeof(*node)); node->type = type; + + switch (node->type) { + case CMARK_NODE_ATX_HEADER: + case CMARK_NODE_SETEXT_HEADER: + node->as.header.level = 1; + break; + + case CMARK_NODE_LIST: { + cmark_list *list = &node->as.list; + list->list_type = CMARK_BULLET_LIST; + list->start = 1; + list->tight = false; + break; + } + + default: + break; + } + return node; } |