Skip to content

Commit

Permalink
Skip leading ./s
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
jonhoo committed Dec 19, 2021
1 parent 398f6df commit f1827f3
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ fn reorder<I>(input: I, context_path: &str) -> impl Iterator<Item = Line>
where
I: IntoIterator<Item = Vec<u8>>,
{
let path: Vec<_> = Path::new(context_path).components().collect();
let path: Vec<_> = Path::new(context_path)
.components()
.skip_while(|c| matches!(c, std::path::Component::CurDir))
.collect();
let mut lines = BinaryHeap::new();
for (i, line) in input.into_iter().enumerate() {
let mut missed = false;
let mut path = path.iter();
let proximity = Path::new(OsStr::from_bytes(&line))
.components()
.skip_while(|c| matches!(c, std::path::Component::CurDir))
.map(|c| {
// if we've already missed, each additional dir is one further away
if missed {
Expand Down Expand Up @@ -232,6 +236,27 @@ mod tests {
);
}

#[test]
fn skip_leading_dot() {
assert_eq!(
reorder(
vec![
bts!("./first.txt"),
bts!("././second.txt"),
bts!("third.txt"),
],
"null.txt",
)
.map(Into::into)
.collect::<Vec<Vec<u8>>>(),
vec![
bts!("./first.txt"),
bts!("././second.txt"),
bts!("third.txt"),
]
);
}

#[test]
fn check_same_proximity_sorted() {
assert_eq!(
Expand Down

0 comments on commit f1827f3

Please sign in to comment.