diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_template.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/tests/test_template.c b/tests/test_template.c index d94ddd6..69ff7fe 100644 --- a/tests/test_template.c +++ b/tests/test_template.c @@ -3,7 +3,7 @@ START_TESTS -TEST(text_only) { +TEST(textvc_only) { char *input = "Hello world."; char *output = template_string(input, NULL); assert_str(output, "Hello world."); @@ -89,7 +89,6 @@ TEST(expr_add) { hashmap_free(ctx); } - TEST(expr_op_precedence) { struct { char *input; @@ -162,6 +161,28 @@ TEST(for_block) { free(output); } + +TEST(for_block_vars) { + char *input = "{% for n in names %}" + "{{loop.index + 1}}: {{ n }}" + "{% if loop.first %} <--{% endif %}" + "{% if not loop.last %}\n{% endif %}" + "{% endfor %}"; + struct hashmap *ctx = hashmap_new(); + + struct vector *names = vector_new(9); + vector_push(names, "John"); + vector_push(names, "Sally"); + vector_push(names, "Eric"); + hashmap_insert(ctx, "names", names); + + char *output = template_string(input, ctx); + assert_str(output, "1: John <--\n2: Sally\n3: Eric"); + vector_free(names); + hashmap_free(ctx); + free(output); +} + TEST(for_block_whitespace) { char *input = "\n{%- for n in names -%}\n{{ n }}\n{%- endfor -%}\n"; struct hashmap *ctx = hashmap_new(); @@ -292,7 +313,6 @@ TEST(expr_lte) { } } - TEST(expr_eq) { struct { char *input; @@ -412,7 +432,6 @@ TEST(buffer_alloc) { } TEST(inheritance_depth_1) { - /* TODO: Check why this fails with files names 1.tmpl */ struct env *env = env_new("./tests/data/inheritance-depth-1/"); char *output = template(env, "one.tmpl", NULL); assert_str(output, "Header\nChild content\nFooter\n"); @@ -420,7 +439,6 @@ TEST(inheritance_depth_1) { env_free(env); } - TEST(inheritance_depth_2) { struct env *env = env_new("./tests/data/inheritance-depth-2/"); char *output = template(env, "two.tmpl", NULL); |