Undo PIMPL pattern in Environment (#127)

* resync single_include

* Undo PIMPL pattern in Environment

* Environment now supports copy construction and assignment
* Add test for copying Environment

Closes #126
This commit is contained in:
Tom
2019-11-22 11:12:28 +01:00
committed by pantor
parent 1d419d1940
commit 8e6a8428fa
3 changed files with 232 additions and 197 deletions

View File

@@ -2,3 +2,33 @@
#define CATCH_CONFIG_MAIN
#include "catch/catch.hpp"
#include "inja/inja.hpp"
using json = nlohmann::json;
TEST_CASE("copy-environment") {
inja::Environment env;
env.add_callback("double", 1, [](inja::Arguments& args) {
int number = args.at(0)->get<int>();
return 2 * number;
});
inja::Template t1 = env.parse("{{ double(2) }}");
env.include_template("tpl", t1);
std::string test_tpl = "{% include \"tpl\" %}";
REQUIRE(env.render(test_tpl, json()) == "4");
inja::Environment copy(env);
CHECK(copy.render(test_tpl, json()) == "4");
// overwrite template in source env
inja::Template t2 = env.parse("{{ double(4) }}");
env.include_template("tpl", t2);
REQUIRE(env.render(test_tpl, json()) == "8");
// template is unchanged in copy
CHECK(copy.render(test_tpl, json()) == "4");
}