mirror of
https://github.com/pantor/inja.git
synced 2026-03-15 13:41:25 +00:00
add clang-format
This commit is contained in:
@@ -1,34 +1,33 @@
|
||||
// Copyright (c) 2019 Pantor. All rights reserved.
|
||||
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
|
||||
#include "doctest/doctest.h"
|
||||
#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::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\" %}";
|
||||
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");
|
||||
REQUIRE(env.render(test_tpl, json()) == "4");
|
||||
|
||||
inja::Environment copy(env);
|
||||
CHECK(copy.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");
|
||||
// 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");
|
||||
// template is unchanged in copy
|
||||
CHECK(copy.render(test_tpl, json()) == "4");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user