test_merged_tree: nest each part of test_diff_dir_file()

I'm about to add a few more checks for diffing with a matcher. I think
it will help make it readable and reduce the risk of mixing up
variables between each part of the test if we use some nested blocks.

I also removed some unnecessary `.clone()` calls while at it.
This commit is contained in:
Martin von Zweigbergk 2023-11-04 15:51:39 -07:00 committed by Martin von Zweigbergk
parent c9ce80a82a
commit 16aa8e8f10

View file

@ -906,137 +906,137 @@ fn test_diff_dir_file() {
(&path6.join(&file), "right"), (&path6.join(&file), "right"),
], ],
); );
let left_merged = MergedTree::new(Merge::new( let left_merged = MergedTree::new(Merge::new(vec![left_base], vec![left_side1, left_side2]));
vec![left_base.clone()], let right_merged =
vec![left_side1.clone(), left_side2.clone()], MergedTree::new(Merge::new(vec![right_base], vec![right_side1, right_side2]));
));
let right_merged = MergedTree::new(Merge::new(
vec![right_base.clone()],
vec![right_side1.clone(), right_side2.clone()],
));
// Test the forwards diff // Test the forwards diff
let actual_diff = left_merged {
.diff(&right_merged, &EverythingMatcher) let actual_diff = left_merged
.map(|(path, diff)| (path, diff.unwrap())) .diff(&right_merged, &EverythingMatcher)
.collect_vec(); .map(|(path, diff)| (path, diff.unwrap()))
let expected_diff = vec![ .collect_vec();
// path1: file1 -> directory1 let expected_diff = vec![
( // path1: file1 -> directory1
path1.clone(),
(left_merged.path_value(&path1), Merge::absent()),
),
(
path1.join(&file),
(Merge::absent(), right_merged.path_value(&path1.join(&file))),
),
// path2: file1 -> directory1+(directory2-absent)
(
path2.clone(),
(left_merged.path_value(&path2), Merge::absent()),
),
(
path2.join(&file),
(Merge::absent(), right_merged.path_value(&path2.join(&file))),
),
// path3: file1 -> directory1+(file1-absent)
(
path3.clone(),
( (
left_merged.path_value(&path3), path1.clone(),
right_merged.path_value(&path3), (left_merged.path_value(&path1), Merge::absent()),
), ),
), (
// path4: file1+(file2-file3) -> directory1+(directory2-directory3) path1.join(&file),
( (Merge::absent(), right_merged.path_value(&path1.join(&file))),
path4.clone(), ),
(left_merged.path_value(&path4), Merge::absent()), // path2: file1 -> directory1+(directory2-absent)
), (
( path2.clone(),
path4.join(&file), (left_merged.path_value(&path2), Merge::absent()),
(Merge::absent(), right_merged.path_value(&path4.join(&file))), ),
), (
// path5: directory1 -> file1+(file2-absent) path2.join(&file),
( (Merge::absent(), right_merged.path_value(&path2.join(&file))),
path5.join(&file), ),
(left_merged.path_value(&path5.join(&file)), Merge::absent()), // path3: file1 -> directory1+(file1-absent)
), (
( path3.clone(),
path5.clone(), (
(Merge::absent(), right_merged.path_value(&path5)), left_merged.path_value(&path3),
), right_merged.path_value(&path3),
// path6: directory1 -> file1+(directory1-absent) ),
( ),
path6.join(&file), // path4: file1+(file2-file3) -> directory1+(directory2-directory3)
(left_merged.path_value(&path6.join(&file)), Merge::absent()), (
), path4.clone(),
( (left_merged.path_value(&path4), Merge::absent()),
path6.clone(), ),
(Merge::absent(), right_merged.path_value(&path6)), (
), path4.join(&file),
]; (Merge::absent(), right_merged.path_value(&path4.join(&file))),
assert_eq!(actual_diff, expected_diff); ),
// path5: directory1 -> file1+(file2-absent)
(
path5.join(&file),
(left_merged.path_value(&path5.join(&file)), Merge::absent()),
),
(
path5.clone(),
(Merge::absent(), right_merged.path_value(&path5)),
),
// path6: directory1 -> file1+(directory1-absent)
(
path6.join(&file),
(left_merged.path_value(&path6.join(&file)), Merge::absent()),
),
(
path6.clone(),
(Merge::absent(), right_merged.path_value(&path6)),
),
];
assert_eq!(actual_diff, expected_diff);
}
// Test the reverse diff // Test the reverse diff
let actual_diff = right_merged {
.diff(&left_merged, &EverythingMatcher) let actual_diff = right_merged
.map(|(path, diff)| (path, diff.unwrap())) .diff(&left_merged, &EverythingMatcher)
.collect_vec(); .map(|(path, diff)| (path, diff.unwrap()))
let expected_diff = vec![ .collect_vec();
// path1: file1 -> directory1 let expected_diff = vec![
( // path1: file1 -> directory1
path1.join(&file),
(right_merged.path_value(&path1.join(&file)), Merge::absent()),
),
(
path1.clone(),
(Merge::absent(), left_merged.path_value(&path1)),
),
// path2: file1 -> directory1+(directory2-absent)
(
path2.join(&file),
(right_merged.path_value(&path2.join(&file)), Merge::absent()),
),
(
path2.clone(),
(Merge::absent(), left_merged.path_value(&path2)),
),
// path3: file1 -> directory1+(file1-absent)
(
path3.clone(),
( (
right_merged.path_value(&path3), path1.join(&file),
left_merged.path_value(&path3), (right_merged.path_value(&path1.join(&file)), Merge::absent()),
), ),
), (
// path4: file1+(file2-file3) -> directory1+(directory2-directory3) path1.clone(),
( (Merge::absent(), left_merged.path_value(&path1)),
path4.join(&file), ),
(right_merged.path_value(&path4.join(&file)), Merge::absent()), // path2: file1 -> directory1+(directory2-absent)
), (
( path2.join(&file),
path4.clone(), (right_merged.path_value(&path2.join(&file)), Merge::absent()),
(Merge::absent(), left_merged.path_value(&path4)), ),
), (
// path5: directory1 -> file1+(file2-absent) path2.clone(),
( (Merge::absent(), left_merged.path_value(&path2)),
path5.clone(), ),
(right_merged.path_value(&path5), Merge::absent()), // path3: file1 -> directory1+(file1-absent)
), (
( path3.clone(),
path5.join(&file), (
(Merge::absent(), left_merged.path_value(&path5.join(&file))), right_merged.path_value(&path3),
), left_merged.path_value(&path3),
// path6: directory1 -> file1+(directory1-absent) ),
( ),
path6.clone(), // path4: file1+(file2-file3) -> directory1+(directory2-directory3)
(right_merged.path_value(&path6), Merge::absent()), (
), path4.join(&file),
( (right_merged.path_value(&path4.join(&file)), Merge::absent()),
path6.join(&file), ),
(Merge::absent(), left_merged.path_value(&path6.join(&file))), (
), path4.clone(),
]; (Merge::absent(), left_merged.path_value(&path4)),
assert_eq!(actual_diff, expected_diff); ),
// path5: directory1 -> file1+(file2-absent)
(
path5.clone(),
(right_merged.path_value(&path5), Merge::absent()),
),
(
path5.join(&file),
(Merge::absent(), left_merged.path_value(&path5.join(&file))),
),
// path6: directory1 -> file1+(directory1-absent)
(
path6.clone(),
(right_merged.path_value(&path6), Merge::absent()),
),
(
path6.join(&file),
(Merge::absent(), left_merged.path_value(&path6.join(&file))),
),
];
assert_eq!(actual_diff, expected_diff);
}
} }
/// Merge 3 resolved trees that can be resolved /// Merge 3 resolved trees that can be resolved