Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cole-miller committed Feb 21, 2025
1 parent 2379029 commit 45d5625
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
16 changes: 10 additions & 6 deletions crates/file_finder/src/file_finder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1484,10 +1484,12 @@ impl<'a> PathComponentSlice<'a> {
let mut len_with_elision = self.path_str.len();
let mut i = eligible_range.start;
while i < eligible_range.end {
if pick_from_end {
i = eligible_range.end - i + eligible_range.start - 1;
}
len_with_elision -= self.component_ranges[i]
let x = if pick_from_end {
eligible_range.end - i + eligible_range.start - 1
} else {
i
};
len_with_elision -= self.component_ranges[x]
.0
.as_os_str()
.as_encoded_bytes()
Expand All @@ -1501,9 +1503,11 @@ impl<'a> PathComponentSlice<'a> {
if len_with_elision > budget {
return None;
} else if pick_from_end {
i..eligible_range.end
let x = eligible_range.end - i + eligible_range.start - 1;
x..eligible_range.end
} else {
eligible_range.start..i + 1
let x = i;
eligible_range.start..x + 1
}
};

Expand Down
29 changes: 14 additions & 15 deletions crates/file_finder/src/file_finder_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,30 @@ fn init_logger() {
#[test]
fn test_path_component_slice() {
#[track_caller]
fn check(path: &str, matches: impl IntoIterator<Item = usize>, expected: &str) {
fn check(path: &str, budget: usize, matches: impl IntoIterator<Item = usize>, expected: &str) {
let mut path = path.to_owned();
let slice = PathComponentSlice::new(&path);
let matches = Vec::from_iter(matches);
// FIXME make it work again
if let Some(range) = slice.elision_range(0, &matches) {
if let Some(range) = slice.elision_range(budget - 1, &matches) {
path.replace_range(range, "…");
}
assert_eq!(path, expected);
}

check("p/a/b/c/d/", [], "p/…/d/");
check("p/a/b/c/d/", [2, 4, 6], "p/a/b/c/d/");
check("p/a/b/c/d/", [2, 6], "p/a/…/c/d/");
check("p/a/b/c/d/", [6], "p/…/c/d/");
check("p/a/b/c/d/", 6, [], "p/…/d/");
check("p/a/b/c/d/", 1, [2, 4, 6], "p/a/b/c/d/");
check("p/a/b/c/d/", 10, [2, 6], "p/a/…/c/d/");
check("p/a/b/c/d/", 8, [6], "p/…/c/d/");

check("p/a/b/c/d", [], "p/…/d");
check("p/a/b/c/d", [2, 4, 6], "p/a/b/c/d");
check("p/a/b/c/d", [2, 6], "p/a/…/c/d");
check("p/a/b/c/d", [6], "p/…/c/d");
check("p/a/b/c/d", 5, [], "p/…/d");
check("p/a/b/c/d", 9, [2, 4, 6], "p/a/b/c/d");
check("p/a/b/c/d", 9, [2, 6], "p/a/…/c/d");
check("p/a/b/c/d", 7, [6], "p/…/c/d");

check("/p/a/b/c/d/", [], "/p/…/d/");
check("/p/a/b/c/d/", [3, 5, 7], "/p/a/b/c/d/");
check("/p/a/b/c/d/", [3, 7], "/p/a/…/c/d/");
check("/p/a/b/c/d/", [7], "/p/…/c/d/");
check("/p/a/b/c/d/", 7, [], "/p/…/d/");
check("/p/a/b/c/d/", 11, [3, 5, 7], "/p/a/b/c/d/");
check("/p/a/b/c/d/", 11, [3, 7], "/p/a/…/c/d/");
check("/p/a/b/c/d/", 9, [7], "/p/…/c/d/");
}

#[test]
Expand Down

0 comments on commit 45d5625

Please sign in to comment.