diff --git a/src/main.rs b/src/main.rs index 0af0c32..ed3de52 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,13 +70,17 @@ fn reorder(input: I, context_path: &str) -> impl Iterator where I: IntoIterator>, { - 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 { @@ -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![ + bts!("./first.txt"), + bts!("././second.txt"), + bts!("third.txt"), + ] + ); + } + #[test] fn check_same_proximity_sorted() { assert_eq!(