aboutsummaryrefslogtreecommitdiff
path: root/tests/test_template.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_template.c')
-rw-r--r--tests/test_template.c75
1 files changed, 67 insertions, 8 deletions
diff --git a/tests/test_template.c b/tests/test_template.c
index 5c17dd4..61a027f 100644
--- a/tests/test_template.c
+++ b/tests/test_template.c
@@ -34,22 +34,81 @@ TEST(expr_symbol) {
free(output);
}
-TEST(var_whitespace) {
- char *input = "Hello \n{{-name -}}\n.";
+TEST(expr_add) {
+ struct {
+ char *input;
+ char *expected_output;
+ } tests[] = {
+ {"{{ 5 + 5 }}.", "10."},
+ {"{{ 5 + foo }}.", "15."},
+ {"{{ \"foo\" + \"bar\" }}", "foobar"},
+ {"{{ \"Hello \" + name }}", "Hello Danny"},
+ };
+
struct hashmap *ctx = hashmap_new();
- hashmap_insert(ctx, "name", "world");
- char *output = template(input, ctx);
- assert_str(output, "Helloworld.");
+ hashmap_insert(ctx, "foo", "10");
+ hashmap_insert(ctx, "name", "Danny");
+
+ for (int i=0; i < ARRAY_SIZE(tests); i++) {
+ char *output = template(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(input, NULL);
+ assert_str(output, "Hello 0.");
+ free(output);
+}
+
+TEST(expr_divide) {
+ char *input = "Hello {{ 5 / 5 }}.";
+ char *output = template(input, NULL);
+ assert_str(output, "Hello 1.");
+ free(output);
+}
+
+TEST(expr_multiply) {
+ char *input = "Hello {{ 5 * 5 }}.";
+ char *output = template(input, NULL);
+ assert_str(output, "Hello 25.");
+ free(output);
+}
+
+TEST(expr_gt) {
+ char *input = "Hello {{ 5 > 4 }}.";
+ char *output = template(input, NULL);
+ assert_str(output, "Hello 1.");
+ free(output);
+
+ input = "Hello {{ 5 > 6 }}.";
+ output = template(input, NULL);
+ assert_str(output, "Hello 0.");
free(output);
}
-TEST(multiline) {
- char *input = "Hello {{name}}.\nL2";
+TEST(expr_lt) {
+ char *input = "Hello {{ 5 < 4 }}.";
+ char *output = template(input, NULL);
+ assert_str(output, "Hello 0.");
+ free(output);
+
+ input = "Hello {{ 4 < 5 }}.";
+ output = template(input, NULL);
+ assert_str(output, "Hello 1.");
+ free(output);
+}
+
+TEST(expr_whitespace) {
+ char *input = "Hello \n{{-name -}}\n.";
struct hashmap *ctx = hashmap_new();
hashmap_insert(ctx, "name", "world");
char *output = template(input, ctx);
- assert_str(output, "Hello world.\nL2");
+ assert_str(output, "Helloworld.");
hashmap_free(ctx);
free(output);
}