This commit is contained in:
parent
056211ba05
commit
61351ba07a
7 changed files with 71 additions and 3 deletions
|
@ -13,7 +13,9 @@ impl FoundMarkers {
|
||||||
impl std::fmt::Display for FoundMarkers {
|
impl std::fmt::Display for FoundMarkers {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
for marker in self.markers.iter() {
|
for marker in self.markers.iter() {
|
||||||
write!(f, "- {marker}")?;
|
// if !matches!(marker, Marker::Unmarked) {
|
||||||
|
write!(f, "{marker}")?;
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ impl std::fmt::Display for Marker {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Marker::Unmarked => Ok(()),
|
Marker::Unmarked => Ok(()),
|
||||||
Marker::Invalid(line) => write!(f, "Invalid: {line}"),
|
Marker::Invalid(line) => write!(f, "- Invalid: {line}"),
|
||||||
Marker::Valid(line, _) => write!(f, "Valid : {line}"),
|
Marker::Valid(line, _) => write!(f, "- Valid : {line}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,5 +3,8 @@ mod found;
|
||||||
mod issue;
|
mod issue;
|
||||||
mod marker;
|
mod marker;
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
pub use found::FoundMarkers;
|
pub use found::FoundMarkers;
|
||||||
pub use marker::Marker;
|
pub use marker::Marker;
|
||||||
|
|
57
src/model/markers/tests/found.rs
Normal file
57
src/model/markers/tests/found.rs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
use crate::model::Line;
|
||||||
|
|
||||||
|
//
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn found_when_displayed() -> anyhow::Result<()> {
|
||||||
|
//given
|
||||||
|
let fs = kxio::fs::temp()?;
|
||||||
|
let file = fs.base().join("file-name");
|
||||||
|
let relative = file.strip_prefix(fs.base())?.to_path_buf();
|
||||||
|
|
||||||
|
let mut found = FoundMarkers::default();
|
||||||
|
|
||||||
|
let marker_unmarked = Line::builder()
|
||||||
|
.file(file.clone())
|
||||||
|
.relative_path(relative.clone())
|
||||||
|
.num(10)
|
||||||
|
.value("line with no comment".to_owned())
|
||||||
|
.build()
|
||||||
|
.into_marker()?;
|
||||||
|
let marker_invalid = Line::builder()
|
||||||
|
.file(file.clone())
|
||||||
|
.relative_path(relative.clone())
|
||||||
|
.num(10)
|
||||||
|
.value("line // TODO: comment".to_owned())
|
||||||
|
.build()
|
||||||
|
.into_marker()?;
|
||||||
|
let marker_valid = Line::builder()
|
||||||
|
.file(file)
|
||||||
|
.relative_path(relative)
|
||||||
|
.num(11)
|
||||||
|
.value("line // TODO: (#13) do this".to_owned())
|
||||||
|
.build()
|
||||||
|
.into_marker()?;
|
||||||
|
|
||||||
|
found.add_marker(marker_unmarked);
|
||||||
|
found.add_marker(marker_invalid);
|
||||||
|
found.add_marker(marker_valid);
|
||||||
|
|
||||||
|
//when
|
||||||
|
let markers_as_string = found.to_string();
|
||||||
|
let result = markers_as_string.lines().collect::<Vec<&str>>();
|
||||||
|
|
||||||
|
//then
|
||||||
|
assert_eq!(
|
||||||
|
result,
|
||||||
|
vec![
|
||||||
|
"- Invalid: file-name#10:",
|
||||||
|
" line // TODO: comment",
|
||||||
|
"- Valid : file-name#11:",
|
||||||
|
" line // TODO: (#13) do this"
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
0
src/model/markers/tests/issue.rs
Normal file
0
src/model/markers/tests/issue.rs
Normal file
0
src/model/markers/tests/marker.rs
Normal file
0
src/model/markers/tests/marker.rs
Normal file
6
src/model/markers/tests/mod.rs
Normal file
6
src/model/markers/tests/mod.rs
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
//
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
mod found;
|
||||||
|
mod issue;
|
||||||
|
mod marker;
|
Loading…
Reference in a new issue