From ba2744d9a35b5f202aae7bd405873a1535438ed9 Mon Sep 17 00:00:00 2001 From: Evan Mesterhazy Date: Sun, 14 Apr 2024 20:30:31 -0400 Subject: [PATCH] Fix TestFilesystem::read_dir_diff_paths This function collects the files present in the `left` and `right` directories. It should return the path suffix with the `left` and `right` prefix stripped. This is necessary because `process_opts` will add the `left` and `right` prefix back to the paths returned by `read_dir_diff_paths`. If we don't strip the prefix, we will end up with invalid paths where the prefix is duplicated. This went unnoticed since the current tests don't diff directories. I will add a test that diffs directories in a subsequent commit. --- src/scm_diff_editor.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/scm_diff_editor.rs b/src/scm_diff_editor.rs index cfbe3b4..3450a32 100644 --- a/src/scm_diff_editor.rs +++ b/src/scm_diff_editor.rs @@ -1088,11 +1088,17 @@ mod tests { impl Filesystem for TestFilesystem { fn read_dir_diff_paths(&self, left: &Path, right: &Path) -> Result> { - Ok(self + let left_files = self .files .keys() - .filter(|path| path.starts_with(left) || path.starts_with(right)) - .cloned() + .filter_map(|path| path.strip_prefix(left).ok()); + let right_files = self + .files + .keys() + .filter_map(|path| path.strip_prefix(right).ok()); + Ok(left_files + .chain(right_files) + .map(|path| path.to_path_buf()) .collect()) }