aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-16 16:24:56 +0100
committerDanny van Kooten <dannyvankooten@users.noreply.github.com>2020-03-16 16:24:56 +0100
commitc3ebcee2541d7dcc515fba929aa83555ccbdc030 (patch)
tree69c9ffaea1a653f6876363cf4699a00136dd23d3 /tests
parent31e98ced014b9326ddfc990b003864df69cd4dcc (diff)
downloadunja-c3ebcee2541d7dcc515fba929aa83555ccbdc030.tar.gz
unja-c3ebcee2541d7dcc515fba929aa83555ccbdc030.zip
add if statements & use object values internally
Diffstat (limited to 'tests')
-rw-r--r--tests/test.h1
-rw-r--r--tests/test_template.c30
2 files changed, 28 insertions, 3 deletions
diff --git a/tests/test.h b/tests/test.h
index 7a82d08..dec4ba4 100644
--- a/tests/test.h
+++ b/tests/test.h
@@ -7,7 +7,6 @@
#define END_TESTS }
#define TEST(name) strcpy(current_test, #name);
#define assert_null(actual) _assert(actual == NULL, __FILE__, __LINE__, "invalid value: expected NULL, got %s", actual)
-
#define assert_str(actual, expected) _assert(actual != NULL && strcmp(actual, expected) == 0, __FILE__, __LINE__, "invalid string: expected %s, got %s", expected, actual)
#define assert(assertion, format, ...) _assert(assertion, __FILE__, __LINE__, format, ##__VA_ARGS__)
#define ARRAY_SIZE(arr) sizeof arr / sizeof arr[0]
diff --git a/tests/test_template.c b/tests/test_template.c
index 61a027f..329075e 100644
--- a/tests/test_template.c
+++ b/tests/test_template.c
@@ -145,10 +145,36 @@ TEST(var_dot_notation) {
}
TEST(comments) {
- char *input = "Hello {# comment here #} world.";
+ char *input = "Hello {# comment here #}world.";
char *output = template(input, NULL);
- assert_str(output, "Hello world.");
+ assert_str(output, "Hello world.");
free(output);
}
+
+TEST(if_block) {
+
+ struct {
+ char *input;
+ char *expected_output;
+ } tests[] = {
+ {"{% if 5 > 10 %}OK{% endif %}.", "."},
+ {"{% if 10 > 5 %}OK{% endif %}.", "OK."},
+ {"{% if foobar %}OK{% endif %}.", "."},
+ {"{% if name %}OK{% endif %}.", "OK."},
+ {"{% if age > 10 %}OK{% endif %}.", "OK."},
+ };
+
+ struct hashmap *ctx = hashmap_new();
+ hashmap_insert(ctx, "name", "Danny");
+ hashmap_insert(ctx, "age", "29");
+ 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);
+}
+
END_TESTS