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