fix include of in-memory templates

This commit is contained in:
pantor
2021-05-17 20:44:32 +02:00
parent ca3c7a0cd6
commit eac2162629
4 changed files with 30 additions and 16 deletions
+15 -3
View File
@@ -73,7 +73,19 @@ TEST_CASE("include-without-local-files") {
inja::Environment env {test_file_directory};
env.set_search_included_templates_in_files(false);
SUBCASE("html") {
CHECK_THROWS_WITH(env.render_file_with_json_file("html/template.txt", "html/data.json"), "[inja.exception.render_error] (at 3:14) include '../test/data/html/header.txt' not found");
}
CHECK_THROWS_WITH(env.render_file_with_json_file("html/template.txt", "html/data.json"), "[inja.exception.render_error] (at 3:14) include 'header.txt' not found");
}
TEST_CASE("include-in-memory-and-file-template") {
inja::Environment env {test_file_directory};
json data;
data["name"] = "Jeff";
CHECK_THROWS_WITH(env.render_file("include-both.txt", data), "[inja.exception.file_error] failed accessing file at '../test/data/body'");
const auto parsed_body_template = env.parse("Bye {{ name }}.");
env.include_template("body", parsed_body_template);
CHECK(env.render_file("include-both.txt", data) == "Hello Jeff. - Bye Jeff.");
}