ok/jj
1
0
Fork 0
forked from mirrors/jj

conflicts: demo bad roundtripping of conflict

This commit is contained in:
Martin von Zweigbergk 2023-02-17 22:02:43 -08:00 committed by Martin von Zweigbergk
parent fe0eb9137c
commit 975350f73b

View file

@ -111,6 +111,106 @@ line 5
);
}
#[test]
fn test_materialize_parse_roundtrip() {
let test_repo = TestRepo::init(false);
let store = test_repo.repo.store();
let path = RepoPath::from_internal_string("file");
let base_id = testutils::write_file(
store,
&path,
"line 1
line 2
line 3
line 4
line 5
",
);
let left_id = testutils::write_file(
store,
&path,
"line 1 left
line 2 left
line 3
line 4
line 5 left
",
);
let right_id = testutils::write_file(
store,
&path,
"line 1 right
line 2
line 3
line 4 right
line 5 right
",
);
let conflict = Conflict {
removes: vec![file_conflict_term(&base_id)],
adds: vec![file_conflict_term(&left_id), file_conflict_term(&right_id)],
};
let mut result: Vec<u8> = vec![];
materialize_conflict(store, &path, &conflict, &mut result).unwrap();
insta::assert_snapshot!(
String::from_utf8(result.clone()).unwrap(),
@r###"
<<<<<<<
%%%%%%%
-line 1
+line 1 right
line 2
+++++++
line 1 left
line 2 left
>>>>>>>
line 3
<<<<<<<
%%%%%%%
line 4
-line 5
+line 5 left
+++++++
line 4 right
line 5 right
>>>>>>>
"###
);
// TODO: The first add should always be from the left side
insta::assert_debug_snapshot!(
parse_conflict(&result, conflict.removes.len(), conflict.adds.len()),
@r###"
Some(
[
Conflict {
removes: [
"line 1\nline 2\n",
],
adds: [
"line 1 right\nline 2\n",
"line 1 left\nline 2 left\n",
],
},
Resolved(
"line 3\n",
),
Conflict {
removes: [
"line 4\nline 5\n",
],
adds: [
"line 4\nline 5 left\n",
"line 4 right\nline 5 right\n",
],
},
],
)
"###);
}
#[test]
fn test_materialize_conflict_modify_delete() {
let test_repo = TestRepo::init(false);