diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2014-11-20 15:17:33 +0100 |
---|---|---|
committer | Nick Wellnhofer <wellnhofer@aevum.de> | 2014-11-22 16:08:32 +0100 |
commit | 32be14c39f67eedf356adc4f673b66479b717c7c (patch) | |
tree | fa33fca26fb0ef02a708fc9cca89acf85cb183dc | |
parent | 759e03748a368be8b209dfd113441c05e1a5dcc0 (diff) |
Set defaults for new headers and lists
-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; } |