Fix for issue #80 (#81)

* Fix for issue #80

When updating the `opening_chars`, line_statment was forgotten. So, a
change to any of the openers would cause line statements to start being
unrecognized.

I added a unit test to cover this case.

* fix indentation

* add update to single_include
This commit is contained in:
Mark Hollomon
2019-01-23 13:18:47 -05:00
committed by pantor
parent 2c98adbcf7
commit 1dfd86fa6f
3 changed files with 21 additions and 2 deletions

View File

@@ -25,7 +25,10 @@ struct LexerConfig {
std::string open_chars {"#{"};
void update_open_chars() {
open_chars = "\n";
open_chars = "";
if (open_chars.find(line_statement[0]) == std::string::npos) {
open_chars += line_statement[0];
}
if (open_chars.find(statement_open[0]) == std::string::npos) {
open_chars += statement_open[0];
}

View File

@@ -1371,7 +1371,10 @@ struct LexerConfig {
std::string open_chars {"#{"};
void update_open_chars() {
open_chars = "\n";
open_chars = "";
if (open_chars.find(line_statement[0]) == std::string::npos) {
open_chars += line_statement[0];
}
if (open_chars.find(statement_open[0]) == std::string::npos) {
open_chars += statement_open[0];
}

View File

@@ -388,4 +388,17 @@ TEST_CASE("other-syntax") {
CHECK( env.render("Hello {# Test #}", data) == "Hello {# Test #}" );
CHECK( env.render("Hello (& Test &)", data) == "Hello " );
}
SECTION("multiple changes") {
inja::Environment env;
env.set_line_statement("$$");
env.set_expression("<%", "%>");
std::string string_template = R"DELIM(Hello <%name%>
$$ if name == "Peter"
You really are <%name%>
$$ endif
)DELIM";
CHECK( env.render(string_template, data) == "Hello Peter\n You really are Peter\n");
}
}