From 8d96c02e5118cf7bd656fde9100570a67115d19a Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 29 Dec 2015 00:12:51 +0100 Subject: man: renderer: template-parser: added foreach iterator support --- tests/check_renderer.c | 70 +++++++++++++++++++++++- tests/check_template_parser.c | 121 +++++++++++++++++++++++++++++++++++++++--- 2 files changed, 182 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/check_renderer.c b/tests/check_renderer.c index cb8f8f1..cc04fdc 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -31,6 +31,7 @@ create_sources(unsigned int count) "GUDA2: zxc\n" "DATE: 2015-01-02 03:04:05\n" "DATE_FORMAT: %R\n" + "TAGS: foo, bar,baz\n" "-----\n" "ahahahahahahahaha", "BOLA: asd2\n" @@ -74,7 +75,8 @@ test_render_entry(void **state) "{% if GUDA != \"bola\" %}HEHE{% endif %}\n" "{% if GUDA < \"zxd\" %}LOL2{% endif %}\n" "{% if GUDA > \"zxd\" %}LOL3{% endif %}\n" - "{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n"; + "{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n" + "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"; blogc_error_t *err = NULL; b_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); @@ -97,7 +99,8 @@ test_render_entry(void **state) "HEHE\n" "LOL2\n" "\n" - "LOL4\n"); + "LOL4\n" + "lol foo haha lol bar haha lol baz haha \n"); blogc_template_free_stmts(l); b_slist_free_full(s, (b_free_func_t) b_trie_free); free(out); @@ -117,6 +120,7 @@ test_render_listing(void **state) "{% block listing %}\n" "{% ifdef DATE_FORMATTED %}{{ DATE_FORMATTED }}{% endif %}\n" "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" + "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; b_slist_t *l = blogc_template_parse(str, strlen(str), &err); @@ -132,12 +136,15 @@ test_render_listing(void **state) "\n" "03:04\n" "bola: asd\n" + "lol foo haha lol bar haha lol baz haha \n" "\n" "2014-02-03 04:05:06\n" "bola: asd2\n" "\n" + "\n" "2013-01-02 03:04:05\n" "bola: asd3\n" + "\n" "\n"); blogc_template_free_stmts(l); b_slist_free_full(s, (b_free_func_t) b_trie_free); @@ -158,6 +165,7 @@ test_render_listing_empty(void **state) "{% block listing %}\n" "{% ifdef DATE_FORMATTED %}{{ DATE_FORMATTED }}{% endif %}\n" "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" + "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; b_slist_t *l = blogc_template_parse(str, strlen(str), &err); @@ -518,6 +526,30 @@ test_render_if_gt_eq(void **state) } +static void +test_render_foreach(void **state) +{ + const char *str = + "{% block entry %}\n" + "{% foreach TAGS %} {{ FOREACH_ITEM }} {% endforeach %}\n" + "{% endblock %}\n"; + blogc_error_t *err = NULL; + b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + assert_non_null(l); + assert_null(err); + b_slist_t *s = create_sources(1); + assert_non_null(s); + char *out = blogc_render(l, s, NULL, false); + assert_string_equal(out, + "\n" + " foo bar baz \n" + "\n"); + blogc_template_free_stmts(l); + b_slist_free_full(s, (b_free_func_t) b_trie_free); + free(out); +} + + static void test_render_null(void **state) { @@ -760,6 +792,37 @@ test_format_variable_with_date(void **state) } +static void +test_split_list_variable(void **state) +{ + b_trie_t *g = b_trie_new(free); + b_trie_insert(g, "TAGS", b_strdup("asd, lol,hehe")); + b_trie_t *l = b_trie_new(free); + b_trie_insert(l, "TAGS", b_strdup("asd, lol,XD")); + b_slist_t *tmp = blogc_split_list_variable("TAGS", g, l); + assert_string_equal(tmp->data, "asd"); + assert_string_equal(tmp->next->data, "lol"); + assert_string_equal(tmp->next->next->data, "XD"); + b_slist_free_full(tmp, free); + b_trie_free(g); + b_trie_free(l); +} + + +static void +test_split_list_variable_not_found(void **state) +{ + b_trie_t *g = b_trie_new(free); + b_trie_insert(g, "TAGS", b_strdup("asd, lol,hehe")); + b_trie_t *l = b_trie_new(free); + b_trie_insert(l, "TAGS", b_strdup("asd, lol,XD")); + b_slist_t *tmp = blogc_split_list_variable("TAG", g, l); + assert_null(tmp); + b_trie_free(g); + b_trie_free(l); +} + + int main(void) { @@ -777,6 +840,7 @@ main(void) unit_test(test_render_if_gt), unit_test(test_render_if_lt_eq), unit_test(test_render_if_gt_eq), + unit_test(test_render_foreach), unit_test(test_render_null), unit_test(test_render_outside_block), unit_test(test_render_prefer_local_variable), @@ -790,6 +854,8 @@ main(void) unit_test(test_format_date_without_date), unit_test(test_format_variable), unit_test(test_format_variable_with_date), + unit_test(test_split_list_variable), + unit_test(test_split_list_variable_not_found), }; return run_tests(tests); } diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index b712f22..6aaceed 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -61,6 +61,7 @@ test_template_parse(void **state) "{% endblock %}\n" "{% block listing %}{{ BOLA }}{% endblock %}\n" "{% block listing_once %}asd{% endblock %}\n" + "{% foreach BOLA %}hahaha{% endforeach %}\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; blogc_error_t *err = NULL; b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); @@ -106,11 +107,20 @@ test_template_parse(void **state) blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next->next, "\n", BLOGC_TEMPLATE_CONTENT_STMT); tmp = tmp->next->next->next->next->next->next->next->next->next->next; - blogc_assert_template_if_stmt(tmp, "BOLA", BLOGC_TEMPLATE_OP_EQ, "\"1\\\"0\""); - blogc_assert_template_stmt(tmp->next, "aee", BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_FOREACH_STMT); + blogc_assert_template_stmt(tmp->next, "hahaha", + BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(tmp->next->next, NULL, + BLOGC_TEMPLATE_ENDFOREACH_STMT); + blogc_assert_template_stmt(tmp->next->next->next, "\n", + BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_if_stmt(tmp->next->next->next->next, "BOLA", + BLOGC_TEMPLATE_OP_EQ, "\"1\\\"0\""); + blogc_assert_template_stmt(tmp->next->next->next->next->next, "aee", + BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_stmt(tmp->next->next->next->next->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); - assert_null(tmp->next->next->next); + assert_null(tmp->next->next->next->next->next->next->next); blogc_template_free_stmts(stmts); } @@ -131,6 +141,7 @@ test_template_parse_crlf(void **state) "{% endblock %}\r\n" "{% block listing %}{{ BOLA }}{% endblock %}\r\n" "{% block listing_once %}asd{% endblock %}\r\n" + "{% foreach BOLA %}hahaha{% endforeach %}\r\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; blogc_error_t *err = NULL; b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); @@ -176,11 +187,20 @@ test_template_parse_crlf(void **state) blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next->next, "\r\n", BLOGC_TEMPLATE_CONTENT_STMT); tmp = tmp->next->next->next->next->next->next->next->next->next->next; - blogc_assert_template_if_stmt(tmp, "BOLA", BLOGC_TEMPLATE_OP_EQ, "\"1\\\"0\""); - blogc_assert_template_stmt(tmp->next, "aee", BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_FOREACH_STMT); + blogc_assert_template_stmt(tmp->next, "hahaha", + BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(tmp->next->next, NULL, + BLOGC_TEMPLATE_ENDFOREACH_STMT); + blogc_assert_template_stmt(tmp->next->next->next, "\r\n", + BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_if_stmt(tmp->next->next->next->next, "BOLA", + BLOGC_TEMPLATE_OP_EQ, "\"1\\\"0\""); + blogc_assert_template_stmt(tmp->next->next->next->next->next, "aee", + BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_stmt(tmp->next->next->next->next->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); - assert_null(tmp->next->next->next); + assert_null(tmp->next->next->next->next->next->next->next); blogc_template_free_stmts(stmts); } @@ -382,6 +402,24 @@ test_template_parse_invalid_block_nested(void **state) } +static void +test_template_parse_invalid_foreach_nested(void **state) +{ + const char *a = + "{% foreach A %}\n" + "{% foreach B %}\n"; + blogc_error_t *err = NULL; + b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "'foreach' statements can't be nested.\n" + "Error occurred near line 2, position 11: {% foreach B %}"); + blogc_error_free(err); +} + + static void test_template_parse_invalid_block_not_open(void **state) { @@ -415,6 +453,22 @@ test_template_parse_invalid_endif_not_open(void **state) } +static void +test_template_parse_invalid_endforeach_not_open(void **state) +{ + const char *a = "{% endforeach %}\n"; + blogc_error_t *err = NULL; + b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "'endforeach' statement without an open 'foreach' statement.\n" + "Error occurred near line 1, position 14: {% endforeach %}"); + blogc_error_free(err); +} + + static void test_template_parse_invalid_block_name(void **state) { @@ -426,7 +480,7 @@ test_template_parse_invalid_block_name(void **state) assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, "Invalid statement type: Allowed types are: 'block', 'endblock', 'ifdef', " - "'ifndef' and 'endif'.\n" + "'ifndef', 'endif', 'foreach' and 'endforeach'.\n" "Error occurred near line 1, position 10: {% chunda %}"); blogc_error_free(err); } @@ -481,6 +535,23 @@ test_template_parse_invalid_ifdef_start(void **state) } +static void +test_template_parse_invalid_foreach_start(void **state) +{ + const char *a = "{% block entry %}{% foreach guda %}\n"; + blogc_error_t *err = NULL; + b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "Invalid foreach variable name. Must begin with uppercase letter.\n" + "Error occurred near line 1, position 29: " + "{% block entry %}{% foreach guda %}"); + blogc_error_free(err); +} + + static void test_template_parse_invalid_ifdef_variable(void **state) { @@ -498,6 +569,23 @@ test_template_parse_invalid_ifdef_variable(void **state) } +static void +test_template_parse_invalid_foreach_variable(void **state) +{ + const char *a = "{% block entry %}{% foreach BoLA %}\n"; + blogc_error_t *err = NULL; + b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "Invalid foreach variable name. Must be uppercase letter, number or '_'.\n" + "Error occurred near line 1, position 30: " + "{% block entry %}{% foreach BoLA %}"); + blogc_error_free(err); +} + + static void test_template_parse_invalid_if_operator(void **state) { @@ -678,6 +766,20 @@ test_template_parse_invalid_block_not_closed(void **state) } +static void +test_template_parse_invalid_foreach_not_closed(void **state) +{ + const char *a = "{% foreach ASD %}\n"; + blogc_error_t *err = NULL; + b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, "An open 'foreach' statement was not closed!"); + blogc_error_free(err); +} + + int main(void) { @@ -688,13 +790,17 @@ main(void) unit_test(test_template_parse_ifdef_and_var_outside_block), unit_test(test_template_parse_invalid_block_start), unit_test(test_template_parse_invalid_block_nested), + unit_test(test_template_parse_invalid_foreach_nested), unit_test(test_template_parse_invalid_block_not_open), unit_test(test_template_parse_invalid_endif_not_open), + unit_test(test_template_parse_invalid_endforeach_not_open), unit_test(test_template_parse_invalid_block_name), unit_test(test_template_parse_invalid_block_type_start), unit_test(test_template_parse_invalid_block_type), unit_test(test_template_parse_invalid_ifdef_start), + unit_test(test_template_parse_invalid_foreach_start), unit_test(test_template_parse_invalid_ifdef_variable), + unit_test(test_template_parse_invalid_foreach_variable), unit_test(test_template_parse_invalid_if_operator), unit_test(test_template_parse_invalid_if_operand), unit_test(test_template_parse_invalid_if_operand2), @@ -706,6 +812,7 @@ main(void) unit_test(test_template_parse_invalid_close2), unit_test(test_template_parse_invalid_if_not_closed), unit_test(test_template_parse_invalid_block_not_closed), + unit_test(test_template_parse_invalid_foreach_not_closed), }; return run_tests(tests); } -- cgit v1.2.3-18-g5258 From e727bdcde63804a308103adeaa2637c5ee1ebdc8 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 29 Dec 2015 00:39:01 +0100 Subject: template-parser: do not accept variables startins with numbers and _ --- tests/check_template_parser.c | 74 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index 6aaceed..145a27e 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -569,6 +569,23 @@ test_template_parse_invalid_ifdef_variable(void **state) } +static void +test_template_parse_invalid_ifdef_variable2(void **state) +{ + const char *a = "{% block entry %}{% ifdef 0123 %}\n"; + blogc_error_t *err = NULL; + b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "Invalid variable name. Must begin with uppercase letter.\n" + "Error occurred near line 1, position 27: " + "{% block entry %}{% ifdef 0123 %}"); + blogc_error_free(err); +} + + static void test_template_parse_invalid_foreach_variable(void **state) { @@ -586,6 +603,23 @@ test_template_parse_invalid_foreach_variable(void **state) } +static void +test_template_parse_invalid_foreach_variable2(void **state) +{ + const char *a = "{% block entry %}{% foreach 0123 %}\n"; + blogc_error_t *err = NULL; + b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "Invalid foreach variable name. Must begin with uppercase letter.\n" + "Error occurred near line 1, position 29: {% block entry %}" + "{% foreach 0123 %}"); + blogc_error_free(err); +} + + static void test_template_parse_invalid_if_operator(void **state) { @@ -613,7 +647,7 @@ test_template_parse_invalid_if_operand(void **state) assert_null(stmts); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, - "Invalid 'if' operand. Must be double-quoted static string.\n" + "Invalid 'if' operand. Must be double-quoted static string or variable.\n" "Error occurred near line 1, position 32: " "{% block entry %}{% if BOLA == asd %}"); blogc_error_free(err); @@ -637,6 +671,23 @@ test_template_parse_invalid_if_operand2(void **state) } +static void +test_template_parse_invalid_if_operand3(void **state) +{ + const char *a = "{% block entry %}{% if BOLA == 0123 %}\n"; + blogc_error_t *err = NULL; + b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "Invalid 'if' operand. Must be double-quoted static string or variable.\n" + "Error occurred near line 1, position 32: " + "{% block entry %}{% if BOLA == 0123 %}"); + blogc_error_free(err); +} + + static void test_template_parse_invalid_block_end(void **state) { @@ -687,6 +738,23 @@ test_template_parse_invalid_variable_name2(void **state) } +static void +test_template_parse_invalid_variable_name3(void **state) +{ + const char *a = "{% block entry %}{{ 0123 }}{% endblock %}\n"; + blogc_error_t *err = NULL; + b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "Invalid variable name. Must begin with uppercase letter.\n" + "Error occurred near line 1, position 21: {% block entry %}{{ 0123 }}" + "{% endblock %}"); + blogc_error_free(err); +} + + static void test_template_parse_invalid_variable_end(void **state) { @@ -800,13 +868,17 @@ main(void) unit_test(test_template_parse_invalid_ifdef_start), unit_test(test_template_parse_invalid_foreach_start), unit_test(test_template_parse_invalid_ifdef_variable), + unit_test(test_template_parse_invalid_ifdef_variable2), unit_test(test_template_parse_invalid_foreach_variable), + unit_test(test_template_parse_invalid_foreach_variable2), unit_test(test_template_parse_invalid_if_operator), unit_test(test_template_parse_invalid_if_operand), unit_test(test_template_parse_invalid_if_operand2), + unit_test(test_template_parse_invalid_if_operand3), unit_test(test_template_parse_invalid_block_end), unit_test(test_template_parse_invalid_variable_name), unit_test(test_template_parse_invalid_variable_name2), + unit_test(test_template_parse_invalid_variable_name3), unit_test(test_template_parse_invalid_variable_end), unit_test(test_template_parse_invalid_close), unit_test(test_template_parse_invalid_close2), -- cgit v1.2.3-18-g5258 From 3d24a8847e156804e19515ddeefd3912402515be Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 29 Dec 2015 01:46:50 +0100 Subject: renderer: foreach variables should be splitted in spaces rather than commas --- tests/check_renderer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/check_renderer.c b/tests/check_renderer.c index cc04fdc..e380be7 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -31,7 +31,7 @@ create_sources(unsigned int count) "GUDA2: zxc\n" "DATE: 2015-01-02 03:04:05\n" "DATE_FORMAT: %R\n" - "TAGS: foo, bar,baz\n" + "TAGS: foo bar baz\n" "-----\n" "ahahahahahahahaha", "BOLA: asd2\n" @@ -796,9 +796,9 @@ static void test_split_list_variable(void **state) { b_trie_t *g = b_trie_new(free); - b_trie_insert(g, "TAGS", b_strdup("asd, lol,hehe")); + b_trie_insert(g, "TAGS", b_strdup("asd lol hehe")); b_trie_t *l = b_trie_new(free); - b_trie_insert(l, "TAGS", b_strdup("asd, lol,XD")); + b_trie_insert(l, "TAGS", b_strdup("asd lol XD")); b_slist_t *tmp = blogc_split_list_variable("TAGS", g, l); assert_string_equal(tmp->data, "asd"); assert_string_equal(tmp->next->data, "lol"); @@ -813,9 +813,9 @@ static void test_split_list_variable_not_found(void **state) { b_trie_t *g = b_trie_new(free); - b_trie_insert(g, "TAGS", b_strdup("asd, lol,hehe")); + b_trie_insert(g, "TAGS", b_strdup("asd lol hehe")); b_trie_t *l = b_trie_new(free); - b_trie_insert(l, "TAGS", b_strdup("asd, lol,XD")); + b_trie_insert(l, "TAGS", b_strdup("asd lol XD")); b_slist_t *tmp = blogc_split_list_variable("TAG", g, l); assert_null(tmp); b_trie_free(g); -- cgit v1.2.3-18-g5258 From 1b851a5778196a34affe397e4c502b326afd3270 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 29 Dec 2015 22:32:38 +0100 Subject: loader: parse tags as space-separated string --- tests/check_loader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/check_loader.c b/tests/check_loader.c index f5be3e7..03f0ef1 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -478,7 +478,7 @@ test_source_parse_from_files_filter_by_page_and_tag(void **state) will_return(__wrap_blogc_file_get_contents, b_strdup( "ASD: 789\n" "DATE: 2003-02-03 04:05:06\n" - "TAGS: chunda, bola\n" + "TAGS: chunda bola\n" "--------\n" "bola")); will_return(__wrap_blogc_file_get_contents, "bola4.txt"); @@ -505,7 +505,7 @@ test_source_parse_from_files_filter_by_page_and_tag(void **state) will_return(__wrap_blogc_file_get_contents, b_strdup( "ASD: 7894\n" "DATE: 2007-02-03 04:05:06\n" - "TAGS: yay, chunda\n" + "TAGS: yay chunda\n" "--------\n" "bola")); blogc_error_t *err = NULL; -- cgit v1.2.3-18-g5258 From a5b155fde8c69d8954a13a4ff6fbdb7633094da7 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 4 Jan 2016 00:33:06 +0100 Subject: renderer: improved foreach tests --- tests/check_renderer.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/check_renderer.c b/tests/check_renderer.c index e380be7..d641506 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -76,7 +76,8 @@ test_render_entry(void **state) "{% if GUDA < \"zxd\" %}LOL2{% endif %}\n" "{% if GUDA > \"zxd\" %}LOL3{% endif %}\n" "{% if GUDA <= \"zxc\" %}LOL4{% endif %}\n" - "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n"; + "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" + "{% foreach TAGS_ASD %}yay{% endforeach %}\n"; blogc_error_t *err = NULL; b_slist_t *l = blogc_template_parse(str, strlen(str), &err); assert_non_null(l); @@ -100,7 +101,8 @@ test_render_entry(void **state) "LOL2\n" "\n" "LOL4\n" - "lol foo haha lol bar haha lol baz haha \n"); + "lol foo haha lol bar haha lol baz haha \n" + "\n"); blogc_template_free_stmts(l); b_slist_free_full(s, (b_free_func_t) b_trie_free); free(out); @@ -121,6 +123,7 @@ test_render_listing(void **state) "{% ifdef DATE_FORMATTED %}{{ DATE_FORMATTED }}{% endif %}\n" "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" + "{% foreach TAGS_ASD %}yay{% endforeach %}\n" "{% endblock %}\n"; blogc_error_t *err = NULL; b_slist_t *l = blogc_template_parse(str, strlen(str), &err); @@ -138,13 +141,16 @@ test_render_listing(void **state) "bola: asd\n" "lol foo haha lol bar haha lol baz haha \n" "\n" + "\n" "2014-02-03 04:05:06\n" "bola: asd2\n" "\n" "\n" + "\n" "2013-01-02 03:04:05\n" "bola: asd3\n" "\n" + "\n" "\n"); blogc_template_free_stmts(l); b_slist_free_full(s, (b_free_func_t) b_trie_free); -- cgit v1.2.3-18-g5258 From 56a5ebf7f0b0d86b7d6e3fd468d3415da312e69b Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 8 Jan 2016 02:36:17 +0100 Subject: renderer: handle FOREACH_ITEM as a normal variable --- tests/check_renderer.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/check_renderer.c b/tests/check_renderer.c index d641506..014cd84 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -556,6 +556,31 @@ test_render_foreach(void **state) } +static void +test_render_foreach_if(void **state) +{ + const char *str = + "{% block entry %}\n" + "{% foreach TAGS %} {% if FOREACH_ITEM == \"bar\" %}{{ FOREACH_ITEM }}" + "{% endif %} {% endforeach %}\n" + "{% endblock %}\n"; + blogc_error_t *err = NULL; + b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + assert_non_null(l); + assert_null(err); + b_slist_t *s = create_sources(1); + assert_non_null(s); + char *out = blogc_render(l, s, NULL, false); + assert_string_equal(out, + "\n" + " bar \n" + "\n"); + blogc_template_free_stmts(l); + b_slist_free_full(s, (b_free_func_t) b_trie_free); + free(out); +} + + static void test_render_null(void **state) { @@ -770,13 +795,13 @@ test_format_variable(void **state) b_trie_t *l = b_trie_new(free); b_trie_insert(l, "NAME", b_strdup("chunda")); b_trie_insert(l, "TITLE", b_strdup("chunda2")); - char *tmp = blogc_format_variable("NAME", g, l); + char *tmp = blogc_format_variable("NAME", g, l, NULL); assert_string_equal(tmp, "chunda"); free(tmp); - tmp = blogc_format_variable("TITLE", g, l); + tmp = blogc_format_variable("TITLE", g, l, NULL); assert_string_equal(tmp, "chunda2"); free(tmp); - assert_null(blogc_format_variable("BOLA", g, l)); + assert_null(blogc_format_variable("BOLA", g, l, NULL)); b_trie_free(g); b_trie_free(l); } @@ -790,7 +815,7 @@ test_format_variable_with_date(void **state) b_trie_insert(g, "DATE_FORMAT", b_strdup("%R")); b_trie_t *l = b_trie_new(free); b_trie_insert(l, "DATE", b_strdup("2011-12-13 14:15:16")); - char *tmp = blogc_format_variable("DATE_FORMATTED", g, l); + char *tmp = blogc_format_variable("DATE_FORMATTED", g, l, NULL); assert_string_equal(tmp, "14:15"); free(tmp); b_trie_free(g); @@ -798,6 +823,26 @@ test_format_variable_with_date(void **state) } +static void +test_format_variable_foreach(void **state) +{ + b_slist_t *l = NULL; + l = b_slist_append(l, b_strdup("asd")); + l = b_slist_append(l, b_strdup("qwe")); + char *tmp = blogc_format_variable("FOREACH_ITEM", NULL, NULL, l->next); + assert_string_equal(tmp, "qwe"); + free(tmp); + b_slist_free_full(l, free); +} + + +static void +test_format_variable_foreach_empty(void **state) +{ + assert_null(blogc_format_variable("FOREACH_ITEM", NULL, NULL, NULL)); +} + + static void test_split_list_variable(void **state) { @@ -847,6 +892,7 @@ main(void) unit_test(test_render_if_lt_eq), unit_test(test_render_if_gt_eq), unit_test(test_render_foreach), + unit_test(test_render_foreach_if), unit_test(test_render_null), unit_test(test_render_outside_block), unit_test(test_render_prefer_local_variable), @@ -860,6 +906,8 @@ main(void) unit_test(test_format_date_without_date), unit_test(test_format_variable), unit_test(test_format_variable_with_date), + unit_test(test_format_variable_foreach), + unit_test(test_format_variable_foreach_empty), unit_test(test_split_list_variable), unit_test(test_split_list_variable_not_found), }; -- cgit v1.2.3-18-g5258 From 687fa0ef362dfdacb6ee0a169d7ab0a84e747cc4 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 8 Jan 2016 18:53:51 +0100 Subject: fixed copyright --- tests/check_content_parser.c | 2 +- tests/check_datetime_parser.c | 2 +- tests/check_error.c | 2 +- tests/check_loader.c | 2 +- tests/check_renderer.c | 2 +- tests/check_source_parser.c | 2 +- tests/check_template_parser.c | 2 +- tests/check_utils.c | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index dc3485e..8ed9520 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2015 Rafael G. Martins + * Copyright (C) 2015-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. diff --git a/tests/check_datetime_parser.c b/tests/check_datetime_parser.c index 1ac976d..ba5a79d 100644 --- a/tests/check_datetime_parser.c +++ b/tests/check_datetime_parser.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2015 Rafael G. Martins + * Copyright (C) 2015-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. diff --git a/tests/check_error.c b/tests/check_error.c index 17e1c40..d3af9c0 100644 --- a/tests/check_error.c +++ b/tests/check_error.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2015 Rafael G. Martins + * Copyright (C) 2015-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. diff --git a/tests/check_loader.c b/tests/check_loader.c index 03f0ef1..ac8bdb3 100644 --- a/tests/check_loader.c +++ b/tests/check_loader.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2015 Rafael G. Martins + * Copyright (C) 2015-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. diff --git a/tests/check_renderer.c b/tests/check_renderer.c index 014cd84..360f067 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2015 Rafael G. Martins + * Copyright (C) 2015-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c index 4d8518e..8d6c039 100644 --- a/tests/check_source_parser.c +++ b/tests/check_source_parser.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2015 Rafael G. Martins + * Copyright (C) 2015-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index 145a27e..f9fd71a 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2015 Rafael G. Martins + * Copyright (C) 2015-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. diff --git a/tests/check_utils.c b/tests/check_utils.c index a42c75a..cb24625 100644 --- a/tests/check_utils.c +++ b/tests/check_utils.c @@ -1,6 +1,6 @@ /* * blogc: A blog compiler. - * Copyright (C) 2014-2015 Rafael G. Martins + * Copyright (C) 2014-2016 Rafael G. Martins * * This program can be distributed under the terms of the BSD License. * See the file LICENSE. -- cgit v1.2.3-18-g5258 From f7aa4a3269a21f4d0c83f11a0aef4ccf821ce6e2 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Thu, 14 Jan 2016 03:50:42 +0100 Subject: template-parser: added whitespace cleaners. needs more tests and docs --- tests/check_template_parser.c | 48 ++++++++++++++++++++++++++----------- tests/check_utils.c | 55 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index f9fd71a..f655896 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -51,27 +51,27 @@ test_template_parse(void **state) const char *a = "Test\n" "\n" - " {% block entry %}\n" + " {%- block entry -%}\n" "{% ifdef CHUNDA %}\n" "bola\n" "{% endif %}\n" "{% ifndef BOLA %}\n" "bolao\n" - "{% endif %}\n" + "{%- endif %}\n" "{% endblock %}\n" "{% block listing %}{{ BOLA }}{% endblock %}\n" "{% block listing_once %}asd{% endblock %}\n" - "{% foreach BOLA %}hahaha{% endforeach %}\n" + "{%- foreach BOLA %}hahaha{% endforeach %}\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; blogc_error_t *err = NULL; b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); - blogc_assert_template_stmt(stmts, "Test\n\n ", + blogc_assert_template_stmt(stmts, "Test", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(stmts->next, "entry", BLOGC_TEMPLATE_BLOCK_STMT); - blogc_assert_template_stmt(stmts->next->next, "\n", + blogc_assert_template_stmt(stmts->next->next, "", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(stmts->next->next->next, "CHUNDA", BLOGC_TEMPLATE_IFDEF_STMT); @@ -83,7 +83,7 @@ test_template_parse(void **state) BLOGC_TEMPLATE_CONTENT_STMT); b_slist_t *tmp = stmts->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT); - blogc_assert_template_stmt(tmp->next, "\nbolao\n", BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_stmt(tmp->next, "\nbolao", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); blogc_assert_template_stmt(tmp->next->next->next, "\n", BLOGC_TEMPLATE_CONTENT_STMT); @@ -105,7 +105,7 @@ test_template_parse(void **state) blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next, NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next->next, - "\n", BLOGC_TEMPLATE_CONTENT_STMT); + "", BLOGC_TEMPLATE_CONTENT_STMT); tmp = tmp->next->next->next->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_FOREACH_STMT); blogc_assert_template_stmt(tmp->next, "hahaha", @@ -131,27 +131,27 @@ test_template_parse_crlf(void **state) const char *a = "Test\r\n" "\r\n" - " {% block entry %}\r\n" + " {%- block entry -%}\r\n" "{% ifdef CHUNDA %}\r\n" "bola\r\n" "{% endif %}\r\n" "{% ifndef BOLA %}\r\n" "bolao\r\n" - "{% endif %}\r\n" + "{%- endif %}\r\n" "{% endblock %}\r\n" "{% block listing %}{{ BOLA }}{% endblock %}\r\n" "{% block listing_once %}asd{% endblock %}\r\n" - "{% foreach BOLA %}hahaha{% endforeach %}\r\n" + "{%- foreach BOLA %}hahaha{% endforeach %}\r\n" "{% if BOLA == \"1\\\"0\" %}aee{% endif %}"; blogc_error_t *err = NULL; b_slist_t *stmts = blogc_template_parse(a, strlen(a), &err); assert_null(err); assert_non_null(stmts); - blogc_assert_template_stmt(stmts, "Test\r\n\r\n ", + blogc_assert_template_stmt(stmts, "Test", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(stmts->next, "entry", BLOGC_TEMPLATE_BLOCK_STMT); - blogc_assert_template_stmt(stmts->next->next, "\r\n", + blogc_assert_template_stmt(stmts->next->next, "", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(stmts->next->next->next, "CHUNDA", BLOGC_TEMPLATE_IFDEF_STMT); @@ -163,7 +163,7 @@ test_template_parse_crlf(void **state) BLOGC_TEMPLATE_CONTENT_STMT); b_slist_t *tmp = stmts->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IFNDEF_STMT); - blogc_assert_template_stmt(tmp->next, "\r\nbolao\r\n", BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_stmt(tmp->next, "\r\nbolao", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(tmp->next->next, NULL, BLOGC_TEMPLATE_ENDIF_STMT); blogc_assert_template_stmt(tmp->next->next->next, "\r\n", BLOGC_TEMPLATE_CONTENT_STMT); @@ -185,7 +185,7 @@ test_template_parse_crlf(void **state) blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next, NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); blogc_assert_template_stmt(tmp->next->next->next->next->next->next->next->next->next, - "\r\n", BLOGC_TEMPLATE_CONTENT_STMT); + "", BLOGC_TEMPLATE_CONTENT_STMT); tmp = tmp->next->next->next->next->next->next->next->next->next->next; blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_FOREACH_STMT); blogc_assert_template_stmt(tmp->next, "hahaha", @@ -381,6 +381,26 @@ test_template_parse_invalid_block_start(void **state) "Invalid statement syntax. Must begin with lowercase letter.\n" "Error occurred near line 1, position 4: {% ASD %}"); blogc_error_free(err); + a = "{%-- block entry %}\n"; + err = NULL; + stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "Invalid statement syntax. Duplicated whitespace cleaner before statement.\n" + "Error occurred near line 1, position 4: {%-- block entry %}"); + blogc_error_free(err); + a = "{% block entry --%}\n"; + err = NULL; + stmts = blogc_template_parse(a, strlen(a), &err); + assert_non_null(err); + assert_null(stmts); + assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); + assert_string_equal(err->msg, + "Invalid statement syntax. Duplicated whitespace cleaner after statement.\n" + "Error occurred near line 1, position 17: {% block entry --%}"); + blogc_error_free(err); } diff --git a/tests/check_utils.c b/tests/check_utils.c index cb24625..a511dda 100644 --- a/tests/check_utils.c +++ b/tests/check_utils.c @@ -128,6 +128,50 @@ test_str_ends_with(void **state) } +static void +test_str_lstrip(void **state) +{ + char *str = b_strdup(" \tbola\n \t"); + assert_string_equal(b_str_lstrip(str), "bola\n \t"); + free(str); + str = b_strdup("guda"); + assert_string_equal(b_str_lstrip(str), "guda"); + free(str); + str = b_strdup("\n"); + assert_string_equal(b_str_lstrip(str), ""); + free(str); + str = b_strdup("\t \n"); + assert_string_equal(b_str_lstrip(str), ""); + free(str); + str = b_strdup(""); + assert_string_equal(b_str_lstrip(str), ""); + free(str); + assert_null(b_str_lstrip(NULL)); +} + + +static void +test_str_rstrip(void **state) +{ + char *str = b_strdup(" \tbola\n \t"); + assert_string_equal(b_str_rstrip(str), " \tbola"); + free(str); + str = b_strdup("guda"); + assert_string_equal(b_str_rstrip(str), "guda"); + free(str); + str = b_strdup("\n"); + assert_string_equal(b_str_rstrip(str), ""); + free(str); + str = b_strdup("\t \n"); + assert_string_equal(b_str_rstrip(str), ""); + free(str); + str = b_strdup(""); + assert_string_equal(b_str_rstrip(str), ""); + free(str); + assert_null(b_str_rstrip(NULL)); +} + + static void test_str_strip(void **state) { @@ -137,6 +181,15 @@ test_str_strip(void **state) str = b_strdup("guda"); assert_string_equal(b_str_strip(str), "guda"); free(str); + str = b_strdup("\n"); + assert_string_equal(b_str_strip(str), ""); + free(str); + str = b_strdup("\t \n"); + assert_string_equal(b_str_strip(str), ""); + free(str); + str = b_strdup(""); + assert_string_equal(b_str_strip(str), ""); + free(str); assert_null(b_str_strip(NULL)); } @@ -799,6 +852,8 @@ main(void) unit_test(test_strdup_printf), unit_test(test_str_starts_with), unit_test(test_str_ends_with), + unit_test(test_str_lstrip), + unit_test(test_str_rstrip), unit_test(test_str_strip), unit_test(test_str_split), unit_test(test_str_replace), -- cgit v1.2.3-18-g5258 From cb132cf02e57f57f4507fbc0126481629d83f209 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Fri, 22 Jan 2016 19:29:57 +0100 Subject: content-parser: encode html entities found in code blocks (fixes #3) --- tests/check_content_parser.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/check_content_parser.c b/tests/check_content_parser.c index 8ed9520..970ec5c 100644 --- a/tests/check_content_parser.c +++ b/tests/check_content_parser.c @@ -48,6 +48,17 @@ test_slugify(void **state) } +static void +test_htmlentities(void **state) +{ + char *s = blogc_htmlentities(NULL); + assert_null(s); + s = blogc_htmlentities("asdxcv & < > \" 'sfd/gf"); + assert_string_equal(s, "asdxcv & < > " 'sfd/gf"); + free(s); +} + + static void test_is_ordered_list_item(void **state) { @@ -87,7 +98,7 @@ test_content_parse(void **state) "> \n" "> asd\n" "\n" - " bola\n" + " bola\n" " asd\n" " qwewer\n" "\n" @@ -122,7 +133,7 @@ test_content_parse(void **state) "buga

\n" "
asd
\n" "\n" - "
bola\n"
+        "
<asd>bola</asd>\n"
         " asd\n"
         "qwewer
\n" "
\n" @@ -165,7 +176,7 @@ test_content_parse_crlf(void **state) "> \r\n" "> asd\r\n" "\r\n" - " bola\r\n" + " bola\r\n" " asd\r\n" " qwewer\r\n" "\r\n" @@ -200,7 +211,7 @@ test_content_parse_crlf(void **state) "buga

\r\n" "
asd
\r\n" "\r\n" - "
bola\r\n"
+        "
<asd>bola</asd>\r\n"
         " asd\r\n"
         "qwewer
\r\n" "
\r\n" @@ -1663,6 +1674,7 @@ main(void) { const UnitTest tests[] = { unit_test(test_slugify), + unit_test(test_htmlentities), unit_test(test_is_ordered_list_item), unit_test(test_content_parse), unit_test(test_content_parse_crlf), -- cgit v1.2.3-18-g5258 From 35c4f119ca188fd9e90a2bbada864f9d121459ba Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Mon, 25 Jan 2016 04:46:19 +0100 Subject: renderer: fix bug when 'if' evals to false after 'if' evals to true --- tests/check_renderer.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') diff --git a/tests/check_renderer.c b/tests/check_renderer.c index 360f067..d6bc947 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -686,6 +686,37 @@ test_render_respect_variable_scope(void **state) } +static void +test_render_ifcount_bug(void **state) +{ + const char *str = + "{% block entry %}\n" + "{% ifdef TITLE %}

{{ TITLE }}

{% endif %}\n" + "{% ifdef IS_POST %}\n" + "{% ifdef ASD %}ASD{% endif %}\n" + "{% endif %}\n" + "{% endblock %}\n"; + blogc_error_t *err = NULL; + b_slist_t *l = blogc_template_parse(str, strlen(str), &err); + assert_non_null(l); + assert_null(err); + b_slist_t *s = NULL; + s = b_slist_append(s, b_trie_new(free)); + b_trie_insert(s->data, "TITLE", b_strdup("bola")); + b_trie_t *c = b_trie_new(free); + char *out = blogc_render(l, s, c, false); + assert_string_equal(out, + "\n" + "

bola

\n" + "\n" + "\n"); + b_trie_free(c); + blogc_template_free_stmts(l); + b_slist_free_full(s, (b_free_func_t) b_trie_free); + free(out); +} + + static void test_get_variable(void **state) { @@ -897,6 +928,7 @@ main(void) unit_test(test_render_outside_block), unit_test(test_render_prefer_local_variable), unit_test(test_render_respect_variable_scope), + unit_test(test_render_ifcount_bug), unit_test(test_get_variable), unit_test(test_get_variable_only_local), unit_test(test_get_variable_only_global), -- cgit v1.2.3-18-g5258