From 0501ee7b850936db0e518dc734e62db13cd07006 Mon Sep 17 00:00:00 2001 From: Danny van Kooten Date: Fri, 4 Dec 2020 09:52:35 +0100 Subject: add context_free function for easily getting rid of context --- tests/data/template-with-logic/base.tmpl | 9 +++++++++ tests/data/template-with-logic/child.tmpl | 10 ++++++++++ tests/test_template.c | 8 ++++++++ 3 files changed, 27 insertions(+) create mode 100644 tests/data/template-with-logic/base.tmpl create mode 100644 tests/data/template-with-logic/child.tmpl (limited to 'tests') diff --git a/tests/data/template-with-logic/base.tmpl b/tests/data/template-with-logic/base.tmpl new file mode 100644 index 0000000..241c78c --- /dev/null +++ b/tests/data/template-with-logic/base.tmpl @@ -0,0 +1,9 @@ +Header + +{%- block content %} +Content +{%- endblock %} + +{%- block footer %} +Footer +{%- endblock -%} \ No newline at end of file diff --git a/tests/data/template-with-logic/child.tmpl b/tests/data/template-with-logic/child.tmpl new file mode 100644 index 0000000..42687b6 --- /dev/null +++ b/tests/data/template-with-logic/child.tmpl @@ -0,0 +1,10 @@ +{% extends "base.tmpl" %} + +{% block content -%} + {{ "Hello World" | lower }} + {% if 2 < 1 -%} + 2 is less than 1. + {%- else -%} + 2 is more than 1. + {%- endif %} +{%- endblock %} \ No newline at end of file diff --git a/tests/test_template.c b/tests/test_template.c index 1ad131e..e85eec2 100644 --- a/tests/test_template.c +++ b/tests/test_template.c @@ -491,4 +491,12 @@ TEST(filter_title) { free(output); } +TEST(inheritance_depth_2) { + struct env *env = env_new("./tests/data/template-with-logic/"); + char *output = template(env, "child.tmpl", NULL); + assert_str(output, "Header\n\thello world\n\t2 is more than 1.\nFooter\n"); + free(output); + env_free(env); +} + END_TESTS \ No newline at end of file -- cgit v1.2.3