diff options
author | Danny van Kooten <dannyvankooten@users.noreply.github.com> | 2020-03-19 20:05:39 +0100 |
---|---|---|
committer | Danny van Kooten <dannyvankooten@users.noreply.github.com> | 2020-03-19 20:05:39 +0100 |
commit | fd6465aad222a00d4c805043b7c0cf3b2d0f3c6b (patch) | |
tree | e40554a08d2037af60b8efbc4ecd616c09dd1dd1 /tests | |
parent | 3353eb18a8ff2480c089ab083c474bf2a2a62b96 (diff) | |
download | unja-fd6465aad222a00d4c805043b7c0cf3b2d0f3c6b.tar.gz unja-fd6465aad222a00d4c805043b7c0cf3b2d0f3c6b.zip |
add operator precedence
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_template.c | 22 |
1 files changed, 22 insertions, 0 deletions
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(); |