1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
// Copyright (c) 2020 Pantor. All rights reserved.
#include "inja/environment.hpp"
#include "test-common.hpp"
TEST_CASE("source location") {
std::string content = R""""(Lorem Ipsum
Dolor
Amid
Set ().$
Try this
)"""";
CHECK(inja::get_source_location(content, 0).line == 1);
CHECK(inja::get_source_location(content, 0).column == 1);
CHECK(inja::get_source_location(content, 10).line == 1);
CHECK(inja::get_source_location(content, 10).column == 11);
CHECK(inja::get_source_location(content, 25).line == 4);
CHECK(inja::get_source_location(content, 25).column == 1);
CHECK(inja::get_source_location(content, 29).line == 4);
CHECK(inja::get_source_location(content, 29).column == 5);
CHECK(inja::get_source_location(content, 43).line == 6);
CHECK(inja::get_source_location(content, 43).column == 1);
}
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, inja::json()) == "4");
inja::Environment copy(env);
CHECK(copy.render(test_tpl, inja::json()) == "4");
// overwrite template in source env
const inja::Template t2 = env.parse("{{ double(4) }}");
env.include_template("tpl", t2);
REQUIRE(env.render(test_tpl, inja::json()) == "8");
// template is unchanged in copy
CHECK(copy.render(test_tpl, inja::json()) == "4");
}
|