add test and readme

This commit is contained in:
pantor
2019-09-08 16:19:50 +02:00
parent 66196fdd6b
commit d25937a85b
7 changed files with 100 additions and 8 deletions
+4
View File
@@ -0,0 +1,4 @@
{
"xarray": [0, 1],
"yarray": [0, 1, 2]
}
+6
View File
@@ -0,0 +1,6 @@
0-0
0-1
0-2
1-0
1-1
1-2
+3
View File
@@ -0,0 +1,3 @@
{% for x in xarray %}{% for y in yarray %}
{{x}}-{{y}}
{% endfor %}{% endfor %}
+12
View File
@@ -41,6 +41,18 @@ TEST_CASE("complete-files") {
}
}
TEST_CASE("complete-files-whitespace-control") {
inja::Environment env {test_file_directory};
env.set_trim_blocks(true);
env.set_lstrip_blocks(true);
for (std::string test_name : {"nested-whitespace"}) {
SECTION(test_name) {
CHECK( env.render_file_with_json_file(test_name + "/template.txt", test_name + "/data.json") == env.load_file(test_name + "/result.txt") );
}
}
}
TEST_CASE("global-path") {
inja::Environment env {test_file_directory, "./"};
inja::Environment env_result {"./"};
+2 -2
View File
@@ -7,8 +7,9 @@ using json = nlohmann::json;
TEST_CASE("dot-to-pointer") {
std::string buffer;
CHECK( inja::convert_dot_to_json_pointer("person.names.surname", buffer) == "/person/names/surname" );
CHECK( inja::convert_dot_to_json_pointer("test", buffer) == "/test" );
CHECK( inja::convert_dot_to_json_pointer("guests.2", buffer) == "/guests/2" );
CHECK( inja::convert_dot_to_json_pointer("person.names.surname", buffer) == "/person/names/surname" );
}
TEST_CASE("types") {
@@ -172,7 +173,6 @@ TEST_CASE("functions") {
SECTION("length") {
CHECK( env.render("{{ length(names) }}", data) == "4" ); // Length of array
CHECK( env.render("{{ length(name) }}", data) == "5" ); // Length of string
// CHECK_THROWS_WITH( env.render("{{ length(5) }}", data), "[inja.exception.json_error] [json.exception.type_error.302] type must be array, but is number" );
}