mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-29 23:57:51 +00:00
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:
parent
c9ce80a82a
commit
16aa8e8f10
1 changed files with 124 additions and 124 deletions
|
@ -906,137 +906,137 @@ fn test_diff_dir_file() {
|
|||
(&path6.join(&file), "right"),
|
||||
],
|
||||
);
|
||||
let left_merged = MergedTree::new(Merge::new(
|
||||
vec![left_base.clone()],
|
||||
vec![left_side1.clone(), left_side2.clone()],
|
||||
));
|
||||
let right_merged = MergedTree::new(Merge::new(
|
||||
vec![right_base.clone()],
|
||||
vec![right_side1.clone(), right_side2.clone()],
|
||||
));
|
||||
let left_merged = MergedTree::new(Merge::new(vec![left_base], vec![left_side1, left_side2]));
|
||||
let right_merged =
|
||||
MergedTree::new(Merge::new(vec![right_base], vec![right_side1, right_side2]));
|
||||
|
||||
// Test the forwards diff
|
||||
let actual_diff = left_merged
|
||||
.diff(&right_merged, &EverythingMatcher)
|
||||
.map(|(path, diff)| (path, diff.unwrap()))
|
||||
.collect_vec();
|
||||
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(),
|
||||
{
|
||||
let actual_diff = left_merged
|
||||
.diff(&right_merged, &EverythingMatcher)
|
||||
.map(|(path, diff)| (path, diff.unwrap()))
|
||||
.collect_vec();
|
||||
let expected_diff = vec![
|
||||
// path1: file1 -> directory1
|
||||
(
|
||||
left_merged.path_value(&path3),
|
||||
right_merged.path_value(&path3),
|
||||
path1.clone(),
|
||||
(left_merged.path_value(&path1), Merge::absent()),
|
||||
),
|
||||
),
|
||||
// path4: file1+(file2-file3) -> directory1+(directory2-directory3)
|
||||
(
|
||||
path4.clone(),
|
||||
(left_merged.path_value(&path4), Merge::absent()),
|
||||
),
|
||||
(
|
||||
path4.join(&file),
|
||||
(Merge::absent(), right_merged.path_value(&path4.join(&file))),
|
||||
),
|
||||
// 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);
|
||||
(
|
||||
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),
|
||||
right_merged.path_value(&path3),
|
||||
),
|
||||
),
|
||||
// path4: file1+(file2-file3) -> directory1+(directory2-directory3)
|
||||
(
|
||||
path4.clone(),
|
||||
(left_merged.path_value(&path4), Merge::absent()),
|
||||
),
|
||||
(
|
||||
path4.join(&file),
|
||||
(Merge::absent(), right_merged.path_value(&path4.join(&file))),
|
||||
),
|
||||
// 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
|
||||
let actual_diff = right_merged
|
||||
.diff(&left_merged, &EverythingMatcher)
|
||||
.map(|(path, diff)| (path, diff.unwrap()))
|
||||
.collect_vec();
|
||||
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(),
|
||||
{
|
||||
let actual_diff = right_merged
|
||||
.diff(&left_merged, &EverythingMatcher)
|
||||
.map(|(path, diff)| (path, diff.unwrap()))
|
||||
.collect_vec();
|
||||
let expected_diff = vec![
|
||||
// path1: file1 -> directory1
|
||||
(
|
||||
right_merged.path_value(&path3),
|
||||
left_merged.path_value(&path3),
|
||||
path1.join(&file),
|
||||
(right_merged.path_value(&path1.join(&file)), Merge::absent()),
|
||||
),
|
||||
),
|
||||
// path4: file1+(file2-file3) -> directory1+(directory2-directory3)
|
||||
(
|
||||
path4.join(&file),
|
||||
(right_merged.path_value(&path4.join(&file)), Merge::absent()),
|
||||
),
|
||||
(
|
||||
path4.clone(),
|
||||
(Merge::absent(), left_merged.path_value(&path4)),
|
||||
),
|
||||
// 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);
|
||||
(
|
||||
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),
|
||||
left_merged.path_value(&path3),
|
||||
),
|
||||
),
|
||||
// path4: file1+(file2-file3) -> directory1+(directory2-directory3)
|
||||
(
|
||||
path4.join(&file),
|
||||
(right_merged.path_value(&path4.join(&file)), Merge::absent()),
|
||||
),
|
||||
(
|
||||
path4.clone(),
|
||||
(Merge::absent(), left_merged.path_value(&path4)),
|
||||
),
|
||||
// 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
|
||||
|
|
Loading…
Reference in a new issue