aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test.h3
-rw-r--r--tests/test_template.c23
2 files changed, 20 insertions, 6 deletions
diff --git a/tests/test.h b/tests/test.h
index d0c0e0a..5c76448 100644
--- a/tests/test.h
+++ b/tests/test.h
@@ -6,7 +6,7 @@
#define START_TESTS int main() {
#define END_TESTS }
#define TEST(name) strcpy(current_test, #name);
-#define assert_str(actual, expected) _assert(strcmp(actual, expected) == 0, __FILE__, __LINE__, "invalid string: expected %s, got %s", expected, 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__)
/* used to store the running test name */
@@ -25,4 +25,5 @@ static void _assert(int assertion, const char filename[64], const int line, char
vprintf(format, args);
va_end(args);
printf("\n");
+ exit(1);
} \ No newline at end of file
diff --git a/tests/test_template.c b/tests/test_template.c
index 55747e7..ac78677 100644
--- a/tests/test_template.c
+++ b/tests/test_template.c
@@ -10,7 +10,7 @@ TEST(text_only) {
free(output);
}
-TEST(text_with_var) {
+TEST(var) {
char *input = "Hello {{name}}.";
struct hashmap *ctx = hashmap_new();
hashmap_insert(ctx, "name", "world");
@@ -20,7 +20,7 @@ TEST(text_with_var) {
free(output);
}
-TEST(text_multiline) {
+TEST(multiline) {
char *input = "Hello {{name}}.\nL2";
struct hashmap *ctx = hashmap_new();
hashmap_insert(ctx, "name", "world");
@@ -39,13 +39,26 @@ TEST(for_block) {
vector_push(numbers, "2");
vector_push(numbers, "3");
hashmap_insert(ctx, "numbers", numbers);
-
+
char *output = template(input, ctx);
assert_str(output, "1, 2, 3, ");
-
vector_free(numbers);
hashmap_free(ctx);
free(output);
}
-END_TESTS \ No newline at end of file
+TEST(var_dot_notation) {
+ char *input = "Hello {{user.name}}!";
+ struct hashmap *user = hashmap_new();
+ hashmap_insert(user, "name", "Danny");
+
+ struct hashmap *ctx = hashmap_new();
+ hashmap_insert(ctx, "user", user);
+
+ char *output = template(input, ctx);
+ assert_str(output, "Hello Danny!");
+ hashmap_free(ctx);
+ free(output);
+}
+
+END_TESTS