diff options
author | Danny van Kooten <dannyvankooten@users.noreply.github.com> | 2020-03-12 16:41:28 +0100 |
---|---|---|
committer | Danny van Kooten <dannyvankooten@users.noreply.github.com> | 2020-03-12 16:41:28 +0100 |
commit | 9acd91d41469ed4024e3a8aa85ef1fb2eec909bd (patch) | |
tree | 420f8b6b409f452815029e5de2db1535723bf26c /tests/test_template.c | |
parent | 791e03d8199fa1177f970f45a8a436912d229d1c (diff) | |
download | unja-9acd91d41469ed4024e3a8aa85ef1fb2eec909bd.tar.gz unja-9acd91d41469ed4024e3a8aa85ef1fb2eec909bd.zip |
dot notation in hashmaps
Diffstat (limited to 'tests/test_template.c')
-rw-r--r-- | tests/test_template.c | 23 |
1 files changed, 18 insertions, 5 deletions
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 |