Compare commits

...

2 commits

Author SHA1 Message Date
926b90c37f refactor: clean up issue regex
All checks were successful
Test / test (push) Successful in 6s
2024-09-20 20:05:52 +01:00
a0e293fc1a fix: recheck tests
All checks were successful
Test / test (push) Successful in 9s
2024-09-20 20:03:18 +01:00
5 changed files with 52 additions and 17 deletions

View file

@ -17,3 +17,4 @@ serde_json = "1.0"
[dev-dependencies]
assert2 = "0.3"
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
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::*;
#[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";

View file

@ -2,7 +2,8 @@
use super::*;
use anyhow::Result;
use kxio::network::StatusCode;
use kxio::network::{RequestBody, RequestMethod, SavedRequest, StatusCode};
use pretty_assertions::assert_eq;
#[tokio::test]
async fn run_with_some_invalids() -> Result<()> {
@ -28,11 +29,19 @@ async fn run_with_some_invalids() -> Result<()> {
std::env::set_var("GITHUB_SERVER_URL", "https://git.kemitix.net");
//when
run(net.into()).await?;
let result = run(net.clone().into()).await;
//then
// TODO: add check that run fails because file_1.txt is invalid
// TODO: add check that network requests were made to get issues
assert!(result.is_err()); // there is an invalid file
let requests = net.requests();
assert_eq!(
requests,
vec![SavedRequest::new(
RequestMethod::Get,
"https://git.kemitix.net/api/v1/repos/kemitix/test/issues?state=open",
RequestBody::None,
)]
);
Ok(())
}
@ -44,7 +53,7 @@ async fn run_with_no_invalids() -> Result<()> {
net.add_get_response(
"https://git.kemitix.net/api/v1/repos/kemitix/test/issues?state=open",
StatusCode::OK,
r#"[{"number": 13}]"#,
r#"[{"number":23},{"number":43}]"#,
);
let _env = THE_ENVIRONMENT.lock();
let fs = kxio::fs::temp()?;
@ -57,12 +66,19 @@ async fn run_with_no_invalids() -> Result<()> {
std::env::set_var("GITHUB_SERVER_URL", "https://git.kemitix.net");
//when
run(net.into()).await?;
let result = run(net.clone().into()).await;
//then
// TODO: add check that run fails because file_1.txt is invalid
// TODO: add check that network requests were made to get issues
assert!(result.is_ok()); // there is an invalid file
let requests = net.requests();
assert_eq!(
requests,
vec![SavedRequest::new(
RequestMethod::Get,
"https://git.kemitix.net/api/v1/repos/kemitix/test/issues?state=open",
RequestBody::None,
)]
);
Ok(())
}

View file

@ -38,15 +38,15 @@ fn find_markers_in_dir() -> anyhow::Result<()> {
assert_eq!(
markers.to_string().lines().collect::<Vec<_>>(),
vec![
"- Invalid: file_with_invalids.txt#2:",
"- Invalid: file_with_invalids.txt#3:",
" It contains a todo comment: // TODO: this is it",
"- Invalid: file_with_invalids.txt#4:",
"- Invalid: file_with_invalids.txt#5:",
" It also contains a fix-me comment: // FIXME: and this is it",
"- Closed : (3) file_with_invalids.txt#8:",
"- Closed : (3) file_with_invalids.txt#9:",
" We also have a todo comment: // TODO: (#3) and it has an issue number, but it is closed",
"- Valid : (23) file_with_valids.txt#2:",
"- Valid : (23) file_with_valids.txt#3:",
" It also has a todo comment: // TODO: (#23) and it has an issue number",
"- Valid : (43) file_with_valids.txt#4:",
"- Valid : (43) file_with_valids.txt#5:",
" Here is a fix-me comment: // FIXME: (#43) and is also has an issue number"
]
);