Skip to content

Commit

Permalink
Update for sanitizing regex results and matcher strings. (#1224)
Browse files Browse the repository at this point in the history
* Update for sanitizing regex results and matcher strings.

* Update for regression tests.
  • Loading branch information
MaxSagebaum committed Aug 14, 2024
1 parent d70601e commit 07d641b
Show file tree
Hide file tree
Showing 98 changed files with 3,879 additions and 7,981 deletions.
16 changes: 14 additions & 2 deletions regression-tests/pure2-regex_01_char_matcher.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
return result;
}

sanitize: (copy str: std::string) -> std::string =
{
str = cpp2::string_util::replace_all(str, "\a", "\\a");
str = cpp2::string_util::replace_all(str, "\f", "\\f");
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
str = cpp2::string_util::replace_all(str, "\n", "\\n");
str = cpp2::string_util::replace_all(str, "\r", "\\r");
str = cpp2::string_util::replace_all(str, "\t", "\\t");

return str;
}

test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
resultExpected: std::string) = {

Expand All @@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
result := create_result(resultExpr, r);

if result != resultExpected {
status = "Failure: Result is wrong. (is: (result)$)";
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
}
}
}
Expand All @@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
if !warning.empty() {
warning += " ";
}
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
}


Expand Down
16 changes: 14 additions & 2 deletions regression-tests/pure2-regex_02_ranges.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
return result;
}

sanitize: (copy str: std::string) -> std::string =
{
str = cpp2::string_util::replace_all(str, "\a", "\\a");
str = cpp2::string_util::replace_all(str, "\f", "\\f");
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
str = cpp2::string_util::replace_all(str, "\n", "\\n");
str = cpp2::string_util::replace_all(str, "\r", "\\r");
str = cpp2::string_util::replace_all(str, "\t", "\\t");

return str;
}

test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
resultExpected: std::string) = {

Expand All @@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
result := create_result(resultExpr, r);

if result != resultExpected {
status = "Failure: Result is wrong. (is: (result)$)";
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
}
}
}
Expand All @@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
if !warning.empty() {
warning += " ";
}
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
}


Expand Down
16 changes: 14 additions & 2 deletions regression-tests/pure2-regex_03_wildcard.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
return result;
}

sanitize: (copy str: std::string) -> std::string =
{
str = cpp2::string_util::replace_all(str, "\a", "\\a");
str = cpp2::string_util::replace_all(str, "\f", "\\f");
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
str = cpp2::string_util::replace_all(str, "\n", "\\n");
str = cpp2::string_util::replace_all(str, "\r", "\\r");
str = cpp2::string_util::replace_all(str, "\t", "\\t");

return str;
}

test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
resultExpected: std::string) = {

Expand All @@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
result := create_result(resultExpr, r);

if result != resultExpected {
status = "Failure: Result is wrong. (is: (result)$)";
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
}
}
}
Expand All @@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
if !warning.empty() {
warning += " ";
}
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
}


Expand Down
16 changes: 14 additions & 2 deletions regression-tests/pure2-regex_04_start_end.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
return result;
}

sanitize: (copy str: std::string) -> std::string =
{
str = cpp2::string_util::replace_all(str, "\a", "\\a");
str = cpp2::string_util::replace_all(str, "\f", "\\f");
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
str = cpp2::string_util::replace_all(str, "\n", "\\n");
str = cpp2::string_util::replace_all(str, "\r", "\\r");
str = cpp2::string_util::replace_all(str, "\t", "\\t");

return str;
}

test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
resultExpected: std::string) = {

Expand All @@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
result := create_result(resultExpr, r);

if result != resultExpected {
status = "Failure: Result is wrong. (is: (result)$)";
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
}
}
}
Expand All @@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
if !warning.empty() {
warning += " ";
}
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
}


Expand Down
16 changes: 14 additions & 2 deletions regression-tests/pure2-regex_05_classes.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
return result;
}

sanitize: (copy str: std::string) -> std::string =
{
str = cpp2::string_util::replace_all(str, "\a", "\\a");
str = cpp2::string_util::replace_all(str, "\f", "\\f");
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
str = cpp2::string_util::replace_all(str, "\n", "\\n");
str = cpp2::string_util::replace_all(str, "\r", "\\r");
str = cpp2::string_util::replace_all(str, "\t", "\\t");

return str;
}

test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
resultExpected: std::string) = {

Expand All @@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
result := create_result(resultExpr, r);

if result != resultExpected {
status = "Failure: Result is wrong. (is: (result)$)";
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
}
}
}
Expand All @@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
if !warning.empty() {
warning += " ";
}
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
}


Expand Down
16 changes: 14 additions & 2 deletions regression-tests/pure2-regex_06_boundaries.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
return result;
}

sanitize: (copy str: std::string) -> std::string =
{
str = cpp2::string_util::replace_all(str, "\a", "\\a");
str = cpp2::string_util::replace_all(str, "\f", "\\f");
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
str = cpp2::string_util::replace_all(str, "\n", "\\n");
str = cpp2::string_util::replace_all(str, "\r", "\\r");
str = cpp2::string_util::replace_all(str, "\t", "\\t");

return str;
}

test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
resultExpected: std::string) = {

Expand All @@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
result := create_result(resultExpr, r);

if result != resultExpected {
status = "Failure: Result is wrong. (is: (result)$)";
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
}
}
}
Expand All @@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
if !warning.empty() {
warning += " ";
}
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
}


Expand Down
16 changes: 14 additions & 2 deletions regression-tests/pure2-regex_07_short_classes.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
return result;
}

sanitize: (copy str: std::string) -> std::string =
{
str = cpp2::string_util::replace_all(str, "\a", "\\a");
str = cpp2::string_util::replace_all(str, "\f", "\\f");
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
str = cpp2::string_util::replace_all(str, "\n", "\\n");
str = cpp2::string_util::replace_all(str, "\r", "\\r");
str = cpp2::string_util::replace_all(str, "\t", "\\t");

return str;
}

test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
resultExpected: std::string) = {

Expand All @@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
result := create_result(resultExpr, r);

if result != resultExpected {
status = "Failure: Result is wrong. (is: (result)$)";
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
}
}
}
Expand All @@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
if !warning.empty() {
warning += " ";
}
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
}


Expand Down
16 changes: 14 additions & 2 deletions regression-tests/pure2-regex_08_alternatives.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
return result;
}

sanitize: (copy str: std::string) -> std::string =
{
str = cpp2::string_util::replace_all(str, "\a", "\\a");
str = cpp2::string_util::replace_all(str, "\f", "\\f");
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
str = cpp2::string_util::replace_all(str, "\n", "\\n");
str = cpp2::string_util::replace_all(str, "\r", "\\r");
str = cpp2::string_util::replace_all(str, "\t", "\\t");

return str;
}

test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
resultExpected: std::string) = {

Expand All @@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
result := create_result(resultExpr, r);

if result != resultExpected {
status = "Failure: Result is wrong. (is: (result)$)";
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
}
}
}
Expand All @@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
if !warning.empty() {
warning += " ";
}
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
}


Expand Down
16 changes: 14 additions & 2 deletions regression-tests/pure2-regex_09_groups.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
return result;
}

sanitize: (copy str: std::string) -> std::string =
{
str = cpp2::string_util::replace_all(str, "\a", "\\a");
str = cpp2::string_util::replace_all(str, "\f", "\\f");
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
str = cpp2::string_util::replace_all(str, "\n", "\\n");
str = cpp2::string_util::replace_all(str, "\r", "\\r");
str = cpp2::string_util::replace_all(str, "\t", "\\t");

return str;
}

test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
resultExpected: std::string) = {

Expand All @@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
result := create_result(resultExpr, r);

if result != resultExpected {
status = "Failure: Result is wrong. (is: (result)$)";
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
}
}
}
Expand All @@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
if !warning.empty() {
warning += " ";
}
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
}


Expand Down
16 changes: 14 additions & 2 deletions regression-tests/pure2-regex_10_escapes.cpp2
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ create_result: (resultExpr: std::string, r) -> std::string = {
return result;
}

sanitize: (copy str: std::string) -> std::string =
{
str = cpp2::string_util::replace_all(str, "\a", "\\a");
str = cpp2::string_util::replace_all(str, "\f", "\\f");
str = cpp2::string_util::replace_all(str, "\x1b", "\\e");
str = cpp2::string_util::replace_all(str, "\n", "\\n");
str = cpp2::string_util::replace_all(str, "\r", "\\r");
str = cpp2::string_util::replace_all(str, "\t", "\\t");

return str;
}

test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string, kind: std::string, resultExpr: std::string,
resultExpected: std::string) = {

Expand All @@ -131,7 +143,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
result := create_result(resultExpr, r);

if result != resultExpected {
status = "Failure: Result is wrong. (is: (result)$)";
status = "Failure: Result is wrong. (is: (sanitize(result))$)";
}
}
}
Expand All @@ -146,7 +158,7 @@ test: <M> (regex: M, id: std::string, regex_str: std::string, str: std::string,
if !warning.empty() {
warning += " ";
}
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (str)$ result_expr: (resultExpr)$ expected_results (resultExpected)$" << std::endl;
std::cout << "(id)$_(kind)$: (status)$ (warning)$regex: (regex_str)$ parsed_regex: (regex.to_string())$ str: (sanitize(str))$ result_expr: (resultExpr)$ expected_results (sanitize(resultExpected))$" << std::endl;
}


Expand Down
Loading

0 comments on commit 07d641b

Please sign in to comment.