Skip to content

Commit

Permalink
Add edit_diff_builtin tests for deleting and emptying files (jj-vcs#3702
Browse files Browse the repository at this point in the history
)
  • Loading branch information
30350n committed Jul 12, 2024
1 parent b805584 commit 7120c48
Showing 1 changed file with 128 additions and 0 deletions.
128 changes: 128 additions & 0 deletions cli/src/merge_tools/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,70 @@ mod tests {
);
}

#[test]
fn test_edit_diff_builtin_delete_file() {
let test_repo = TestRepo::init();
let store = test_repo.repo.store();

let file_path = RepoPath::from_internal_string("file_with_content");
let left_tree = testutils::create_tree(&test_repo.repo, &[(file_path, "content\n")]);
let right_tree = testutils::create_tree(&test_repo.repo, &[]);

let changed_files = vec![file_path.to_owned()];
let files = make_diff_files(store, &left_tree, &right_tree, &changed_files).unwrap();
insta::assert_debug_snapshot!(files, @r###"
[
File {
old_path: None,
path: "file_with_content",
file_mode: Some(
FileMode(
33188,
),
),
sections: [
Changed {
lines: [
SectionChangedLine {
is_checked: false,
change_type: Removed,
line: "content\n",
},
],
},
],
},
]
"###);
let no_changes_tree_id = apply_diff_builtin(
store,
&left_tree,
&right_tree,
changed_files.clone(),
&files,
)
.unwrap();
let no_changes_tree = store.get_root_tree(&no_changes_tree_id).unwrap();
assert_eq!(
no_changes_tree.id(),
left_tree.id(),
"no-changes tree was different",
);

let mut files = files;
for file in files.iter_mut() {
file.toggle_all();
}
let all_changes_tree_id =
apply_diff_builtin(store, &left_tree, &right_tree, changed_files, &files).unwrap();
let all_changes_tree = store.get_root_tree(&all_changes_tree_id).unwrap();
assert_eq!(
all_changes_tree.id(),
right_tree.id(),
"all-changes tree was different",
);
}

#[test]
fn test_edit_diff_builtin_delete_empty_file() {
let test_repo = TestRepo::init();
Expand Down Expand Up @@ -985,6 +1049,70 @@ mod tests {
);
}

#[test]
fn test_edit_diff_builtin_make_file_empty() {
let test_repo = TestRepo::init();
let store = test_repo.repo.store();

let file_path = RepoPath::from_internal_string("file_with_content");
let left_tree = testutils::create_tree(&test_repo.repo, &[(file_path, "content\n")]);
let right_tree = testutils::create_tree(&test_repo.repo, &[(file_path, "")]);

let changed_files = vec![file_path.to_owned()];
let files = make_diff_files(store, &left_tree, &right_tree, &changed_files).unwrap();
insta::assert_debug_snapshot!(files, @r###"
[
File {
old_path: None,
path: "file_with_content",
file_mode: Some(
FileMode(
33188,
),
),
sections: [
Changed {
lines: [
SectionChangedLine {
is_checked: false,
change_type: Removed,
line: "content\n",
},
],
},
],
},
]
"###);
let no_changes_tree_id = apply_diff_builtin(
store,
&left_tree,
&right_tree,
changed_files.clone(),
&files,
)
.unwrap();
let no_changes_tree = store.get_root_tree(&no_changes_tree_id).unwrap();
assert_eq!(
no_changes_tree.id(),
left_tree.id(),
"no-changes tree was different",
);

let mut files = files;
for file in files.iter_mut() {
file.toggle_all();
}
let all_changes_tree_id =
apply_diff_builtin(store, &left_tree, &right_tree, changed_files, &files).unwrap();
let all_changes_tree = store.get_root_tree(&all_changes_tree_id).unwrap();
assert_eq!(
all_changes_tree.id(),
right_tree.id(),
"all-changes tree was different",
);
}

#[test]
fn test_make_merge_sections() {
let test_repo = TestRepo::init();
Expand Down

0 comments on commit 7120c48

Please sign in to comment.