Compare commits

..

No commits in common. "926b90c37f127b2a8ce758e708d31c66866a0a8c" and "2e990ef462ac247fc14d7b9e3745caeeb1d9792c" have entirely different histories.

5 changed files with 17 additions and 52 deletions

View file

@ -17,4 +17,3 @@ 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,10 +1,8 @@
use anyhow::Result;
//
use super::*;
#[test]
fn when_issue_should_find_number() -> Result<()> {
fn when_issue_should_find_number() -> anyhow::Result<()> {
//given
let line = " a line with a // TODO: (#13) issue number";
@ -20,24 +18,8 @@ fn when_issue_should_find_number() -> 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() -> Result<()> {
fn when_no_issue_should_find_nothing() -> anyhow::Result<()> {
//given
let line = " a line with a // TODO: and no issue number";

View file

@ -2,8 +2,7 @@
use super::*;
use anyhow::Result;
use kxio::network::{RequestBody, RequestMethod, SavedRequest, StatusCode};
use pretty_assertions::assert_eq;
use kxio::network::StatusCode;
#[tokio::test]
async fn run_with_some_invalids() -> Result<()> {
@ -29,19 +28,11 @@ async fn run_with_some_invalids() -> Result<()> {
std::env::set_var("GITHUB_SERVER_URL", "https://git.kemitix.net");
//when
let result = run(net.clone().into()).await;
run(net.into()).await?;
//then
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,
)]
);
// TODO: add check that run fails because file_1.txt is invalid
// TODO: add check that network requests were made to get issues
Ok(())
}
@ -53,7 +44,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":23},{"number":43}]"#,
r#"[{"number": 13}]"#,
);
let _env = THE_ENVIRONMENT.lock();
let fs = kxio::fs::temp()?;
@ -66,19 +57,12 @@ async fn run_with_no_invalids() -> Result<()> {
std::env::set_var("GITHUB_SERVER_URL", "https://git.kemitix.net");
//when
let result = run(net.clone().into()).await;
run(net.into()).await?;
//then
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,
)]
);
// TODO: add check that run fails because file_1.txt is invalid
// TODO: add check that network requests were made to get issues
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#3:",
"- Invalid: file_with_invalids.txt#2:",
" It contains a todo comment: // TODO: this is it",
"- Invalid: file_with_invalids.txt#5:",
"- Invalid: file_with_invalids.txt#4:",
" It also contains a fix-me comment: // FIXME: and this is it",
"- Closed : (3) file_with_invalids.txt#9:",
"- Closed : (3) file_with_invalids.txt#8:",
" We also have a todo comment: // TODO: (#3) and it has an issue number, but it is closed",
"- Valid : (23) file_with_valids.txt#3:",
"- Valid : (23) file_with_valids.txt#2:",
" It also has a todo comment: // TODO: (#23) and it has an issue number",
"- Valid : (43) file_with_valids.txt#5:",
"- Valid : (43) file_with_valids.txt#4:",
" Here is a fix-me comment: // FIXME: (#43) and is also has an issue number"
]
);