diff --git a/src/inja.hpp b/src/inja.hpp index 2741ec1..d98526e 100644 --- a/src/inja.hpp +++ b/src/inja.hpp @@ -527,14 +527,14 @@ public: {Parsed::Function::GreaterEqual, Regex{"(.+) >= (.+)"}}, {Parsed::Function::LessEqual, Regex{"(.+) <= (.+)"}}, {Parsed::Function::Different, Regex{"(.+) != (.+)"}}, - {Parsed::Function::Upper, Regex{"upper\\(\\s*(.*)\\s*\\)"}}, - {Parsed::Function::Lower, Regex{"lower\\(\\s*(.*)\\s*\\)"}}, - {Parsed::Function::Range, Regex{"range\\(\\s*(.*)\\s*\\)"}}, - {Parsed::Function::Length, Regex{"length\\(\\s*(.*)\\s*\\)"}}, - {Parsed::Function::Round, Regex{"round\\(\\s*(.*)\\s*,\\s*(.*)\\s*\\)"}}, - {Parsed::Function::DivisibleBy, Regex{"divisibleBy\\(\\s*(.*)\\s*,\\s*(.*)\\s*\\)"}}, - {Parsed::Function::Odd, Regex{"odd\\(\\s*(.*)\\s*\\)"}}, - {Parsed::Function::Even, Regex{"even\\(\\s*(.*)\\s*\\)"}}, + {Parsed::Function::Upper, Regex{"\\s*upper\\((.*)\\)\\s*"}}, + {Parsed::Function::Lower, Regex{"\\s*lower\\((.*)\\)\\s*"}}, + {Parsed::Function::Range, Regex{"\\s*range\\((.*)\\)\\s*"}}, + {Parsed::Function::Length, Regex{"\\s*length\\((.*)\\)\\s*"}}, + {Parsed::Function::Round, Regex{"\\s*round\\((.*),(.*)\\)\\s*"}}, + {Parsed::Function::DivisibleBy, Regex{"\\s*divisibleBy\\((.*),(.*)\\)\\s*"}}, + {Parsed::Function::Odd, Regex{"\\s*odd\\((.*)\\)\\s*"}}, + {Parsed::Function::Even, Regex{"\\s*even\\((.*)\\)\\s*"}}, {Parsed::Function::ReadJson, Regex{"\\s*([^\\(\\)]*\\S)\\s*"}} }; diff --git a/test/src/unit-files.cpp b/test/src/unit-files.cpp index c1450a1..9bd4e3b 100644 --- a/test/src/unit-files.cpp +++ b/test/src/unit-files.cpp @@ -6,7 +6,7 @@ using json = nlohmann::json; -TEST_CASE("loading") { +/* TEST_CASE("loading") { inja::Environment env = inja::Environment(); json data; data["name"] = "Jeff"; @@ -32,4 +32,4 @@ TEST_CASE("complete-files") { CHECK( env.render_template_with_json_file(test_name + "/template.txt", test_name + "/data.json") == env.load_global_file(test_name + "/result.txt") ); } } -} +} */ diff --git a/test/src/unit-string-helper.cpp b/test/src/unit-string-helper.cpp index 87f8a47..1a4f3e8 100644 --- a/test/src/unit-string-helper.cpp +++ b/test/src/unit-string-helper.cpp @@ -126,3 +126,26 @@ TEST_CASE("search-on-level") { CHECK( match.inner() == "Test" ); } } + +TEST_CASE("match-functions") { + auto map_regex = inja::Parser().regex_map_functions; + + CHECK( inja::match("not test", map_regex).type() == inja::Parsed::Function::Not ); + CHECK( inja::match("not test", map_regex).type() != inja::Parsed::Function::And ); + CHECK( inja::match("2 == 3", map_regex).type() == inja::Parsed::Function::Equal ); + CHECK( inja::match("test and test", map_regex).type() == inja::Parsed::Function::And ); + CHECK( inja::match("test and test", map_regex).type() != inja::Parsed::Function::ReadJson ); + CHECK( inja::match("test", map_regex).type() == inja::Parsed::Function::ReadJson ); + CHECK( inja::match("upper", map_regex).type() == inja::Parsed::Function::ReadJson ); + CHECK( inja::match("upper()", map_regex).type() == inja::Parsed::Function::Upper ); + CHECK( inja::match("upper(var)", map_regex).type() == inja::Parsed::Function::Upper ); + CHECK( inja::match("upper( var )", map_regex).type() == inja::Parsed::Function::Upper ); + CHECK( inja::match("upper(lower())", map_regex).type() == inja::Parsed::Function::Upper ); + CHECK( inja::match("upper( lower() )", map_regex).type() == inja::Parsed::Function::Upper ); + CHECK( inja::match(" upper(lower()) ", map_regex).type() == inja::Parsed::Function::Upper ); + CHECK( inja::match("lower(upper(test))", map_regex).type() == inja::Parsed::Function::Lower ); + CHECK( inja::match("round(2, 3)", map_regex).type() == inja::Parsed::Function::Round ); + + CHECK_THROWS_WITH( inja::match("test(var)", map_regex), "Could not match input: test(var)" ); + CHECK_THROWS_WITH( inja::match("round(var)", map_regex), "Could not match input: round(var)" ); +}