type enum, clode cleaning, readme tables

This commit is contained in:
pantor
2017-08-14 15:16:01 +02:00
parent 28582ceb55
commit df8764f70b
6 changed files with 263 additions and 219 deletions

View File

@@ -8,10 +8,10 @@ using json = nlohmann::json;
TEST_CASE("string vector join function") {
REQUIRE( inja::join_strings({"1", "2", "3"}, ",") == "1,2,3" );
REQUIRE( inja::join_strings({"1", "2", "3", "4", "5"}, " ") == "1 2 3 4 5" );
REQUIRE( inja::join_strings({}, " ") == "" );
REQUIRE( inja::join_strings({"single"}, "---") == "single" );
CHECK( inja::join_strings({"1", "2", "3"}, ",") == "1,2,3" );
CHECK( inja::join_strings({"1", "2", "3", "4", "5"}, " ") == "1 2 3 4 5" );
CHECK( inja::join_strings({}, " ") == "" );
CHECK( inja::join_strings({"single"}, "---") == "single" );
}
TEST_CASE("basic search in string") {
@@ -20,18 +20,18 @@ TEST_CASE("basic search in string") {
SECTION("basic search from start") {
inja::SearchMatch match = inja::search(input, regex, 0);
REQUIRE( match.found == true );
REQUIRE( match.position == 6 );
REQUIRE( match.length == 5 );
REQUIRE( match.end_position == 11 );
REQUIRE( match.outer == "ipsum" );
REQUIRE( match.inner == "psu" );
CHECK( match.found == true );
CHECK( match.position == 6 );
CHECK( match.length == 5 );
CHECK( match.end_position == 11 );
CHECK( match.outer == "ipsum" );
CHECK( match.inner == "psu" );
}
SECTION("basic search from position") {
inja::SearchMatch match = inja::search(input, regex, 8);
REQUIRE( match.found == false );
REQUIRE( match.length == 0 );
CHECK( match.found == false );
CHECK( match.length == 0 );
}
}
@@ -40,54 +40,56 @@ TEST_CASE("search in string with multiple possible regexes") {
SECTION("basic 1") {
std::vector<std::string> regex_patterns = { "tras", "do(\\w*)or", "es(\\w*)as", "ip(\\w*)um" };
inja::SearchMatch match = inja::search(input, regex_patterns, 0);
REQUIRE( match.regex_number == 3 );
REQUIRE( match.outer == "ipsum" );
REQUIRE( match.inner == "s" );
inja::SearchMatchVector match = inja::search(input, regex_patterns, 0);
CHECK( match.regex_number == 3 );
CHECK( match.outer == "ipsum" );
CHECK( match.inner == "s" );
}
SECTION("basic 2") {
std::vector<std::string> regex_patterns = { "tras", "ip(\\w*)um", "do(\\w*)or", "es(\\w*)as" };
inja::SearchMatch match = inja::search(input, regex_patterns, 0);
REQUIRE( match.regex_number == 1 );
REQUIRE( match.outer == "ipsum" );
REQUIRE( match.inner == "s" );
inja::SearchMatchVector match = inja::search(input, regex_patterns, 0);
CHECK( match.regex_number == 1 );
CHECK( match.outer == "ipsum" );
CHECK( match.inner == "s" );
}
}
TEST_CASE("search on level") {
std::string input = "(% up %)(% up %)(% N1 %)(% down %)...(% up %)(% N2 %)(% up %)(% N3 %)(% down %)(% N4 %)(% down %)(% N5 %)(% down %)";
std::string input = "(% up %)(% up %)Test(% N1 %)(% down %)...(% up %)(% N2 %)(% up %)(% N3 %)(% down %)(% N4 %)(% down %)(% N5 %)(% down %)";
std::regex regex_statement("\\(\\% (.*?) \\%\\)");
std::regex regex_level_up("up");
std::regex regex_level_down("down");
std::regex regex_search("N(\\d+)");
SECTION("basic 1") {
SECTION("first instance") {
inja::SearchMatch open_match = inja::search(input, regex_statement, 0);
CHECK( open_match.position == 0 );
CHECK( open_match.end_position == 8 );
CHECK( open_match.inner == "up" );
REQUIRE( open_match.position == 0 );
REQUIRE( open_match.end_position == 8 );
REQUIRE( open_match.inner == "up" );
inja::SearchClosedMatch match = inja::search_on_level(input, regex_statement, regex_level_up, regex_level_down, regex_search, open_match);
REQUIRE( match.position == 0 );
REQUIRE( match.end_position == 105 );
inja::SearchClosedMatch match = inja::search_closed_match_on_level(input, regex_statement, regex_level_up, regex_level_down, regex_search, open_match);
CHECK( match.position == 0 );
CHECK( match.end_position == 109 );
}
SECTION("basic 1") {
SECTION("second instance") {
inja::SearchMatch open_match = inja::search(input, regex_statement, 4);
REQUIRE( open_match.position == 8 );
REQUIRE( open_match.end_position == 16 );
REQUIRE( open_match.inner == "up" );
CHECK( open_match.position == 8 );
CHECK( open_match.end_position == 16 );
CHECK( open_match.inner == "up" );
inja::SearchClosedMatch match = inja::search_on_level(input, regex_statement, regex_level_up, regex_level_down, regex_search, open_match);
inja::SearchClosedMatch match = inja::search_closed_match_on_level(input, regex_statement, regex_level_up, regex_level_down, regex_search, open_match);
REQUIRE( match.position == 8 );
// REQUIRE( match.end_position == 24 );
// REQUIRE( match.outer == "(% up %)(% N1 %)(% down %)" );
// REQUIRE( match.inner == "(% N1 %)" );
CHECK( match.open_match.position == 8 );
CHECK( match.open_match.end_position== 16 );
CHECK( match.close_match.position == 20 );
CHECK( match.close_match.end_position == 28 );
CHECK( match.position == 8 );
CHECK( match.end_position == 28 );
CHECK( match.outer == "(% up %)Test(% N1 %)" );
CHECK( match.inner == "Test" );
}
}