mirror of
https://github.com/pantor/inja.git
synced 2026-02-20 18:36:24 +00:00
* test * improve ast * add if statement * shunting-yard start * renderer as node visitor * improve ast * improve ast further * first functions * improve ast v3 * improve ast v4 * fix parser error location * nested ifs * fix comma, activate more tests * fix line statements * fix some more tests * fix callbacks without arguments * add json literal array and object * use switch in expression * fix default function * fix loop data * improved tests and benchmark * fix minus numbers * improve all * fix warnings, optimizations * fix callbacks argument order * dont move loop parent * a few more test * fix clang-3 * fix pointers * clean * update single include
56 lines
1.5 KiB
C++
56 lines
1.5 KiB
C++
// Copyright (c) 2019 Pantor. All rights reserved.
|
|
|
|
#include "doctest/doctest.h"
|
|
#include "inja/inja.hpp"
|
|
|
|
|
|
TEST_CASE("source location") {
|
|
std::string content = R"DELIM(Lorem Ipsum
|
|
Dolor
|
|
Amid
|
|
Set ().$
|
|
Try this
|
|
|
|
)DELIM";
|
|
|
|
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, 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");
|
|
}
|