mirror of
https://github.com/pantor/inja.git
synced 2026-06-03 17:39:46 +00:00
Merge branch 'hunter' into master
This commit is contained in:
+9
-2
@@ -52,10 +52,17 @@ else() # Manage dependencies manually
|
||||
target_link_libraries(${UNITTEST_TARGET_NAME} inja)
|
||||
endif()
|
||||
|
||||
# Copy test files to build directory
|
||||
add_custom_command(
|
||||
TARGET ${UNITTEST_TARGET_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_SOURCE_DIR}/test/data
|
||||
${CMAKE_CURRENT_BINARY_DIR}/data)
|
||||
|
||||
##
|
||||
## Add tests to make
|
||||
##
|
||||
add_test(NAME "${UNITTEST_TARGET_NAME}_default"
|
||||
COMMAND ${UNITTEST_TARGET_NAME}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
COMMAND ${UNITTEST_TARGET_NAME}
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
@@ -216,6 +216,7 @@ TEST_CASE("Parse functions") {
|
||||
data["name"] = "Peter";
|
||||
data["city"] = "New York";
|
||||
data["names"] = {"Jeff", "Seb", "Peter", "Tom"};
|
||||
data["temperature"] = 25.6789;
|
||||
|
||||
SECTION("Upper") {
|
||||
CHECK( env.eval_variable("upper(name)", data) == "PETER" );
|
||||
@@ -238,4 +239,10 @@ TEST_CASE("Parse functions") {
|
||||
CHECK( env.eval_variable("length(names)", data) == 4 );
|
||||
CHECK_THROWS_WITH( env.eval_variable("length(5)", data), "Argument in length function is not a list." );
|
||||
}
|
||||
|
||||
SECTION("Round") {
|
||||
CHECK( env.eval_variable("round(4, 0)", data) == 4 );
|
||||
CHECK( env.eval_variable("round(temperature, 2)", data) == 25.68 );
|
||||
CHECK_THROWS_WITH( env.eval_variable("round(name, 2)", data), "Argument in round function is not a number." );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,30 @@ TEST_CASE("Renderer") {
|
||||
CHECK( env.render("{% if age != 28 %}Right{% else %}Wrong{% endif %}", data) == "Right" );
|
||||
CHECK( env.render("{% if age >= 30 %}Right{% else %}Wrong{% endif %}", data) == "Wrong" );
|
||||
CHECK( env.render("{% if age in [28, 29, 30] %}True{% endif %}", data) == "True" );
|
||||
// CHECK( env.render(R"({% if name in ["Simon", "Tom"] %}Test1{% else if name in ["Peter"] %}Test2{% else %}Test3{% endif %})", data) == "Test2" );
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Renderer other syntax") {
|
||||
json data;
|
||||
data["name"] = "Peter";
|
||||
data["names"] = {"Jeff", "Seb"};
|
||||
|
||||
SECTION("Other expression syntax") {
|
||||
inja::Environment env = inja::Environment();
|
||||
|
||||
CHECK( env.render("Hello {{ name }}!", data) == "Hello Peter!" );
|
||||
|
||||
env.setExpression("\\(&", "&\\)");
|
||||
|
||||
CHECK( env.render("Hello {{ name }}!", data) == "Hello {{ name }}!" );
|
||||
CHECK( env.render("Hello (& name &)!", data) == "Hello Peter!" );
|
||||
}
|
||||
|
||||
SECTION("Other comment syntax") {
|
||||
inja::Environment env = inja::Environment();
|
||||
env.setComment("\\(&", "&\\)");
|
||||
|
||||
CHECK( env.render("Hello {# Test #}", data) == "Hello {# Test #}" );
|
||||
CHECK( env.render("Hello (& Test &)", data) == "Hello " );
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+9197
-8803
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user