From fd6465aad222a00d4c805043b7c0cf3b2d0f3c6b Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Thu, 19 Mar 2020 20:05:39 +0100 Subject: add operator precedence --- tests/test_template.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/test_template.c b/tests/test_template.c index cb23dbf..4521d6c 100644 --- a/tests/test_template.c +++ b/tests/test_template.c @@ -89,6 +89,27 @@ TEST(expr_add) { hashmap_free(ctx); } + +TEST(expr_op_precedence) { + struct { + char *input; + char *expected_output; + } tests[] = { + {"{{ 5 * 2 + 1 }}.", "11."}, + {"{{ 1 + 5 * 2 }}.", "11."}, + {"{{ 10 / 2 + 1 }}.", "6."}, + {"{{ 1 + 10 / 2 }}.", "6."}, + }; + + struct hashmap *ctx = hashmap_new(); + for (int i=0; i < ARRAY_SIZE(tests); i++) { + char *output = template_string(tests[i].input, ctx); + assert_str(output, tests[i].expected_output); + free(output); + } + hashmap_free(ctx); +} + TEST(expr_subtract) { char *input = "Hello {{ 5 - 5 }}."; char *output = template_string(input, NULL); @@ -211,6 +232,7 @@ TEST(if_block) { {"{% if foobar %}1{% endif %}.", "."}, {"{% if name %}1{% endif %}.", "1."}, {"{% if age > 10 %}1{% endif %}.", "1."}, + {"{% if 10+1 > 10 %}1{% endif %}.", "1."}, }; struct hashmap *ctx = hashmap_new(); -- cgit v1.2.3