From a39e8c713e0a8ea9f2f8e455c1ce2b4d0c3f5115 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Thu, 12 Mar 2020 14:45:48 +0100 Subject: evaluate for blocks correctly --- tests/test_template.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/test_template.c b/tests/test_template.c index 88d1ab4..69f1d94 100644 --- a/tests/test_template.c +++ b/tests/test_template.c @@ -30,7 +30,21 @@ TEST(text_multiline) { free(output); } - - +TEST(for_block) { + char *input = "{% for n in numbers %}{{ n }}, {% endfor %}"; + struct hashmap *ctx = hashmap_new(); + struct list numbers; + numbers.size = 0; + numbers.cap = 64; + numbers.values = malloc(numbers.cap * sizeof *numbers.values); + numbers.values[numbers.size++] = "1"; + numbers.values[numbers.size++] = "2"; + numbers.values[numbers.size++] = "3"; + hashmap_insert(ctx, "numbers", &numbers); + char *output = template(input, ctx); + assert_str(output, "1, 2, 3, "); + hashmap_free(ctx); + free(output); +} END_TESTS \ No newline at end of file -- cgit v1.2.3