From 7582a32c837c8b55613b547799d1a6405e926cba Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Thu, 23 Apr 2015 19:44:39 -0300 Subject: template parser: added "if not" support --- tests/check_renderer.c | 34 ++++++++++++++++++++++++++++++++++ tests/check_template_parser.c | 21 +++++++++++++++------ 2 files changed, 49 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/check_renderer.c b/tests/check_renderer.c index bbc2953..539d122 100644 --- a/tests/check_renderer.c +++ b/tests/check_renderer.c @@ -213,6 +213,39 @@ test_render_if3(void **state) } +static void +test_render_if_not(void **state) +{ + const char *str = + "{% block entry %}\n" + "{% if not CHUNDA %}chunda\n" + "{% if GUDA %}guda\n" + "{% if not BOLA %}bola\n" + "{% endif %}\n" + "{% 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 = create_sources(1); + assert_non_null(s); + char *out = blogc_render(l, s, false); + assert_string_equal(out, + "\n" + "chunda\n" + "guda\n" + "\n" + "\n" + "\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) { @@ -229,6 +262,7 @@ main(void) unit_test(test_render_if), unit_test(test_render_if2), unit_test(test_render_if3), + unit_test(test_render_if_not), unit_test(test_render_null), }; return run_tests(tests); diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c index f4c0825..fcf4ee8 100644 --- a/tests/check_template_parser.c +++ b/tests/check_template_parser.c @@ -43,6 +43,9 @@ test_template_parse(void **state) "{% if CHUNDA %}\n" "bola\n" "{% endif %}\n" + "{% if not BOLA %}\n" + "bolao\n" + "{% endif %}\n" "{% endblock %}\n" "{% block listing %}{{ BOLA }}{% endblock %}\n" "{% block listing_once %}asd{% endblock %}\n"; @@ -60,19 +63,25 @@ test_template_parse(void **state) BLOGC_TEMPLATE_IF_STMT); blogc_assert_template_stmt(stmts->next->next->next->next, "\nbola\n", BLOGC_TEMPLATE_CONTENT_STMT); - blogc_assert_template_stmt(stmts->next->next->next->next->next, - NULL, BLOGC_TEMPLATE_ENDIF_STMT); - blogc_assert_template_stmt(stmts->next->next->next->next->next->next, - "\n", BLOGC_TEMPLATE_CONTENT_STMT); + blogc_assert_template_stmt(stmts->next->next->next->next->next, NULL, + BLOGC_TEMPLATE_ENDIF_STMT); + blogc_assert_template_stmt(stmts->next->next->next->next->next->next, "\n", + BLOGC_TEMPLATE_CONTENT_STMT); b_slist_t *tmp = stmts->next->next->next->next->next->next->next; + blogc_assert_template_stmt(tmp, "BOLA", BLOGC_TEMPLATE_IF_NOT_STMT); + blogc_assert_template_stmt(tmp->next, "\nbolao\n", 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); + tmp = tmp->next->next->next->next; blogc_assert_template_stmt(tmp, NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); blogc_assert_template_stmt(tmp->next, "\n", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(tmp->next->next, "listing", BLOGC_TEMPLATE_BLOCK_STMT); blogc_assert_template_stmt(tmp->next->next->next, "BOLA", BLOGC_TEMPLATE_VARIABLE_STMT); - blogc_assert_template_stmt(tmp->next->next->next->next, NULL, - BLOGC_TEMPLATE_ENDBLOCK_STMT); + blogc_assert_template_stmt(tmp->next->next->next->next, + NULL, BLOGC_TEMPLATE_ENDBLOCK_STMT); blogc_assert_template_stmt(tmp->next->next->next->next->next, "\n", BLOGC_TEMPLATE_CONTENT_STMT); blogc_assert_template_stmt(tmp->next->next->next->next->next->next, -- cgit v1.2.3-18-g5258