add tests for get source location function

This commit is contained in:
Lars Berscheid
2020-06-30 09:25:02 +02:00
parent bb613e29ba
commit db4356b345
3 changed files with 29 additions and 3 deletions

View File

@@ -263,7 +263,7 @@ env.set_lstrip_blocks(true);
With both `trim_blocks` and `lstrip_blocks` enabled, you can put statements on their own lines. Furthermore, you can also strip whitespaces by hand. If you add a minus sign (`-`) to the start or end of a statement, the whitespaces before or after that block will be removed:
```.cpp
render("""{% if neighbour in guests -%} I was there{% endif -%} !""", data); // Renders without any whitespaces
render("{% if neighbour in guests -%} I was there{% endif -%} !", data); // Renders without any whitespaces
```
Stripping behind a statement also remove any newlines.

View File

@@ -457,7 +457,7 @@ TEST_CASE("templates") {
}
}
TEST_CASE("other-syntax") {
TEST_CASE("other syntax") {
json data;
data["name"] = "Peter";
data["city"] = "Brunswick";

View File

@@ -7,7 +7,33 @@
using json = nlohmann::json;
TEST_CASE("copy-environment") {
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>();