calculate length of strings with length function

This commit is contained in:
pantor
2019-04-07 13:27:43 +02:00
parent 3afc7f30cd
commit 6698e98ea3
3 changed files with 28 additions and 10 deletions

View File

@@ -73,7 +73,7 @@ TEST_CASE("types") {
SECTION("nested loops") {
auto ldata = json::parse(
R"DELIM(
{ "outer" : [
{ "outer" : [
{ "inner" : [
{ "in2" : [ 1, 2 ] },
{ "in2" : []},
@@ -170,7 +170,9 @@ TEST_CASE("functions") {
}
SECTION("length") {
CHECK( env.render("{{ length(names) }}", data) == "4" );
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" );
}