diff --git a/Cargo.toml b/Cargo.toml index 5477e5c..40dcfdf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,4 @@ serde_json = "1.0" [dev-dependencies] assert2 = "0.3" pretty_assertions = "1.4" +rstest = "0.22" diff --git a/src/patterns/mod.rs b/src/patterns/mod.rs index 0fa64ad..592a9bd 100644 --- a/src/patterns/mod.rs +++ b/src/patterns/mod.rs @@ -12,5 +12,5 @@ pub fn marker_pattern() -> Result { /// The pattern to find an issue number on an already found TODO or FIXME comment pub fn issue_pattern() -> Result { - regex::Regex::new(r"( |)(\(|\(#)(?P\d+)(\))").context("issue regex") + regex::Regex::new(r"\(#?(?P\d+)\)").context("issue regex") } diff --git a/src/patterns/tests/issue.rs b/src/patterns/tests/issue.rs index f0845a1..869fe16 100644 --- a/src/patterns/tests/issue.rs +++ b/src/patterns/tests/issue.rs @@ -1,8 +1,10 @@ +use anyhow::Result; + // use super::*; #[test] -fn when_issue_should_find_number() -> anyhow::Result<()> { +fn when_issue_should_find_number() -> Result<()> { //given let line = " a line with a // TODO: (#13) issue number"; @@ -18,8 +20,24 @@ fn when_issue_should_find_number() -> anyhow::Result<()> { 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] -fn when_no_issue_should_find_nothing() -> anyhow::Result<()> { +fn when_no_issue_should_find_nothing() -> Result<()> { //given let line = " a line with a // TODO: and no issue number";