From 81d2434dbbd61a3b677a41aa5d896eec9a358dae Mon Sep 17 00:00:00 2001 From: Tristan F <26509014+LeoDog896@users.noreply.github.com> Date: Thu, 7 Mar 2024 19:04:09 -0500 Subject: [PATCH] test: properly run against suite --- crates/redos/tests/lib.rs | 23 +++++++++++++++------ crates/redos/tests/safe.txt | 40 ++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/crates/redos/tests/lib.rs b/crates/redos/tests/lib.rs index 88702e0..01e2362 100644 --- a/crates/redos/tests/lib.rs +++ b/crates/redos/tests/lib.rs @@ -16,7 +16,7 @@ mod tests { if line.starts_with('\t') { let mut line = line.to_string(); - line.pop(); + line.remove(0); tests.last_mut().unwrap().1.push(line); } else { tests.push((line.to_string(), vec![])); @@ -27,12 +27,20 @@ mod tests { } fn assert_safe(regex: &str, message: &str) { + let vulnerabilities = vulnerabilities(regex, &Default::default()) + .map(|r| r.vulnerabilities); + + assert!( + vulnerabilities.is_ok(), + "{} failed to get vulnerabilities: {}", + message, + regex + ); + assert_eq!( - vulnerabilities(regex, &Default::default()) - .unwrap() - .vulnerabilities, + vulnerabilities.unwrap(), vec![], - "{} failed: {}", + "{} was not safe: {}", message, regex ); @@ -40,7 +48,10 @@ mod tests { #[test] fn check_safe() { - for (name, tests) in parse_test_file(SAFE) { + let test_suite = parse_test_file(SAFE); + assert!(!test_suite.is_empty()); + for (name, tests) in test_suite { + assert!(!tests.is_empty()); for test in tests { assert_safe(&test, &name); } diff --git a/crates/redos/tests/safe.txt b/crates/redos/tests/safe.txt index d139af8..eb0c898 100644 --- a/crates/redos/tests/safe.txt +++ b/crates/redos/tests/safe.txt @@ -1,30 +1,30 @@ base example - abc + abc lets try out groups - (abc|def)|[nhi]? + (abc|def)|[nhi]? tiny repeating string - a{1,10} + a{1,10} bigger repeated string that's just right - a{} + a{} nested group - (((a))) + (((a))) try putting some quantifiers outside - ((a+)+)+ + ((a+)+)+ are optionals detected? - (a?)+ + (a?)+ lets try lookarounds - (?<=a) - (?a) - (?>a+) + (?<=a) + (?a) + (?>a+) can we decompose alternations? - (a+)|(b+)|(((a))) + (a+)|(b+)|(((a))) how about alternations in lookarounds? - (?<=a|b) - (?a|b) - (?>a+|b+) + (?<=a|b) + (?a|b) + (?>a+|b+) \ No newline at end of file