Compare commits
2 commits
2e990ef462
...
926b90c37f
Author | SHA1 | Date | |
---|---|---|---|
926b90c37f | |||
a0e293fc1a |
5 changed files with 52 additions and 17 deletions
|
@ -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"
|
||||||
|
|
|
@ -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")
|
||||||
}
|
}
|
||||||
|
|
|
@ -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";
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use kxio::network::StatusCode;
|
use kxio::network::{RequestBody, RequestMethod, SavedRequest, StatusCode};
|
||||||
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn run_with_some_invalids() -> Result<()> {
|
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");
|
std::env::set_var("GITHUB_SERVER_URL", "https://git.kemitix.net");
|
||||||
|
|
||||||
//when
|
//when
|
||||||
run(net.into()).await?;
|
let result = run(net.clone().into()).await;
|
||||||
|
|
||||||
//then
|
//then
|
||||||
// TODO: add check that run fails because file_1.txt is invalid
|
assert!(result.is_err()); // there is an invalid file
|
||||||
// TODO: add check that network requests were made to get issues
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -44,7 +53,7 @@ async fn run_with_no_invalids() -> Result<()> {
|
||||||
net.add_get_response(
|
net.add_get_response(
|
||||||
"https://git.kemitix.net/api/v1/repos/kemitix/test/issues?state=open",
|
"https://git.kemitix.net/api/v1/repos/kemitix/test/issues?state=open",
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
r#"[{"number": 13}]"#,
|
r#"[{"number":23},{"number":43}]"#,
|
||||||
);
|
);
|
||||||
let _env = THE_ENVIRONMENT.lock();
|
let _env = THE_ENVIRONMENT.lock();
|
||||||
let fs = kxio::fs::temp()?;
|
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");
|
std::env::set_var("GITHUB_SERVER_URL", "https://git.kemitix.net");
|
||||||
|
|
||||||
//when
|
//when
|
||||||
|
let result = run(net.clone().into()).await;
|
||||||
run(net.into()).await?;
|
|
||||||
|
|
||||||
//then
|
//then
|
||||||
// TODO: add check that run fails because file_1.txt is invalid
|
assert!(result.is_ok()); // there is an invalid file
|
||||||
// TODO: add check that network requests were made to get issues
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,15 +38,15 @@ fn find_markers_in_dir() -> anyhow::Result<()> {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
markers.to_string().lines().collect::<Vec<_>>(),
|
markers.to_string().lines().collect::<Vec<_>>(),
|
||||||
vec![
|
vec![
|
||||||
"- Invalid: file_with_invalids.txt#2:",
|
"- Invalid: file_with_invalids.txt#3:",
|
||||||
" It contains a todo comment: // TODO: this is it",
|
" 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",
|
" 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",
|
" 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",
|
" 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"
|
" Here is a fix-me comment: // FIXME: (#43) and is also has an issue number"
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue