refactor: clean up issue regex
All checks were successful
Test / test (push) Successful in 6s

This commit is contained in:
Paul Campbell 2024-09-20 19:11:46 +01:00
parent a0e293fc1a
commit 926b90c37f
3 changed files with 22 additions and 3 deletions

View file

@ -17,3 +17,4 @@ serde_json = "1.0"
[dev-dependencies] [dev-dependencies]
assert2 = "0.3" assert2 = "0.3"
pretty_assertions = "1.4" pretty_assertions = "1.4"
rstest = "0.22"

View file

@ -12,5 +12,5 @@ pub fn marker_pattern() -> Result<Regex> {
/// The pattern to find an issue number on an already found TODO or FIXME comment /// The pattern to find an issue number on an already found TODO or FIXME comment
pub fn issue_pattern() -> Result<Regex> { pub fn issue_pattern() -> Result<Regex> {
regex::Regex::new(r"( |)(\(|\(#)(?P<ISSUE_NUMBER>\d+)(\))").context("issue regex") regex::Regex::new(r"\(#?(?P<ISSUE_NUMBER>\d+)\)").context("issue regex")
} }

View file

@ -1,8 +1,10 @@
use anyhow::Result;
// //
use super::*; use super::*;
#[test] #[test]
fn when_issue_should_find_number() -> anyhow::Result<()> { fn when_issue_should_find_number() -> Result<()> {
//given //given
let line = " a line with a // TODO: (#13) issue number"; let line = " a line with a // TODO: (#13) issue number";
@ -18,8 +20,24 @@ fn when_issue_should_find_number() -> anyhow::Result<()> {
Ok(()) Ok(())
} }
#[rstest::rstest]
#[case("(#13)")]
#[case("(13)")]
fn find_issue_thirteen(#[case] input: &str) -> Result<()> {
assert_eq!(
issue_pattern()?
.captures(input)
.unwrap()
.name("ISSUE_NUMBER")
.unwrap()
.as_str(),
"13"
);
Ok(())
}
#[test] #[test]
fn when_no_issue_should_find_nothing() -> anyhow::Result<()> { fn when_no_issue_should_find_nothing() -> Result<()> {
//given //given
let line = " a line with a // TODO: and no issue number"; let line = " a line with a // TODO: and no issue number";