aboutsummaryrefslogtreecommitdiffstats
path: root/tests/check_renderer.c
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-01-08 02:36:17 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-01-08 02:36:17 +0100
commit56a5ebf7f0b0d86b7d6e3fd468d3415da312e69b (patch)
tree1405b183551c93baf575d1efda5e65f461d7c36b /tests/check_renderer.c
parentfc0e0f4c2415b816daaca8d292aada532be19faa (diff)
downloadblogc-56a5ebf7f0b0d86b7d6e3fd468d3415da312e69b.tar.gz
blogc-56a5ebf7f0b0d86b7d6e3fd468d3415da312e69b.tar.bz2
blogc-56a5ebf7f0b0d86b7d6e3fd468d3415da312e69b.zip
renderer: handle FOREACH_ITEM as a normal variable
Diffstat (limited to 'tests/check_renderer.c')
-rw-r--r--tests/check_renderer.c56
1 files changed, 52 insertions, 4 deletions
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
@@ -557,6 +557,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)
{
assert_null(blogc_render(NULL, NULL, NULL, false));
@@ -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);
@@ -799,6 +824,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)
{
b_trie_t *g = b_trie_new(free);
@@ -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),
};