mirror of
https://github.com/pantor/inja.git
synced 2026-03-26 10:52:48 +00:00
add test for nested functions
This commit is contained in:
@@ -288,10 +288,13 @@ class Parser {
|
||||
func->callback = function_data.callback;
|
||||
}
|
||||
|
||||
function_stack.pop();
|
||||
|
||||
if (operator_stack.empty()) {
|
||||
throw_parser_error("internal error at function " + func->name);
|
||||
}
|
||||
|
||||
current_expression_list->rpn_output.emplace_back(operator_stack.top());
|
||||
operator_stack.pop();
|
||||
function_stack.pop();
|
||||
}
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -3000,10 +3000,13 @@ class Parser {
|
||||
func->callback = function_data.callback;
|
||||
}
|
||||
|
||||
function_stack.pop();
|
||||
|
||||
if (operator_stack.empty()) {
|
||||
throw_parser_error("internal error at function " + func->name);
|
||||
}
|
||||
|
||||
current_expression_list->rpn_output.emplace_back(operator_stack.top());
|
||||
operator_stack.pop();
|
||||
function_stack.pop();
|
||||
}
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -223,6 +223,11 @@ TEST_CASE("callbacks") {
|
||||
return number1 * number2 * number3;
|
||||
});
|
||||
|
||||
env.add_callback("length", 1, [](inja::Arguments args) {
|
||||
auto number1 = args.at(0)->get<std::string>();
|
||||
return number1.length();
|
||||
});
|
||||
|
||||
env.add_callback("multiply", 0, [](inja::Arguments args) { return 1.0; });
|
||||
|
||||
CHECK(env.render("{{ double(age) }}", data) == "56");
|
||||
@@ -230,6 +235,8 @@ TEST_CASE("callbacks") {
|
||||
CHECK(env.render("{{ double-greetings }}", data) == "Hello Hello!");
|
||||
CHECK(env.render("{{ double-greetings() }}", data) == "Hello Hello!");
|
||||
CHECK(env.render("{{ multiply(4, 5) }}", data) == "20.0");
|
||||
CHECK(env.render("{{ multiply(length(\"tester\"), 5) }}", data) == "30.0");
|
||||
CHECK(env.render("{{ multiply(5, length(\"t\")) }}", data) == "5.0");
|
||||
CHECK(env.render("{{ multiply(3, 4, 5) }}", data) == "60.0");
|
||||
CHECK(env.render("{{ multiply }}", data) == "1.0");
|
||||
|
||||
@@ -268,6 +275,7 @@ TEST_CASE("combinations") {
|
||||
CHECK(env.render("{{ last(list_of_objects).d * 2}}", data) == "10");
|
||||
CHECK(env.render("{{ last(range(5)) * 2 }}", data) == "8");
|
||||
CHECK(env.render("{{ last(range(5 * 2)) }}", data) == "9");
|
||||
CHECK(env.render("{{ last(range(5 * 2)) }}", data) == "9");
|
||||
CHECK(env.render("{{ not true }}", data) == "false");
|
||||
CHECK(env.render("{{ not (true) }}", data) == "false");
|
||||
CHECK(env.render("{{ true or (true or true) }}", data) == "true");
|
||||
|
||||
Reference in New Issue
Block a user