conflicts: use insta in conflict tests

This commit is contained in:
Martin von Zweigbergk 2022-07-10 11:01:48 -07:00 committed by Martin von Zweigbergk
parent 9dab88260a
commit fc578a2dd7

View file

@ -16,6 +16,7 @@ use jujutsu_lib::backend::{Conflict, ConflictPart, TreeValue};
use jujutsu_lib::conflicts::{materialize_conflict, parse_conflict, update_conflict_from_content}; use jujutsu_lib::conflicts::{materialize_conflict, parse_conflict, update_conflict_from_content};
use jujutsu_lib::files::MergeHunk; use jujutsu_lib::files::MergeHunk;
use jujutsu_lib::repo_path::RepoPath; use jujutsu_lib::repo_path::RepoPath;
use jujutsu_lib::store::Store;
use jujutsu_lib::testutils; use jujutsu_lib::testutils;
use jujutsu_lib::testutils::TestRepo; use jujutsu_lib::testutils::TestRepo;
@ -78,23 +79,22 @@ line 5
}, },
], ],
}; };
let mut result: Vec<u8> = vec![]; insta::assert_snapshot!(
materialize_conflict(store, &path, &conflict, &mut result).unwrap(); &materialize_conflict_string(store, &path, &conflict),
assert_eq!( @r###"
String::from_utf8(result).unwrap().as_str(), line 1
"line 1 line 2
line 2 <<<<<<<
<<<<<<< -------
------- +++++++
+++++++ -line 3
-line 3 +left
+left +++++++
+++++++ right
right >>>>>>>
>>>>>>> line 4
line 4 line 5
line 5 "###
"
); );
} }
@ -156,22 +156,19 @@ line 5
}, },
], ],
}; };
let mut result: Vec<u8> = vec![]; insta::assert_snapshot!(&materialize_conflict_string(store, &path, &conflict), @r###"
materialize_conflict(store, &path, &conflict, &mut result).unwrap(); line 1
assert_eq!( line 2
String::from_utf8(result).unwrap().as_str(), <<<<<<<
"line 1 -------
line 2 +++++++
<<<<<<< -line 3
------- +left
+++++++ +++++++
-line 3 >>>>>>>
+left line 4
+++++++ line 5
>>>>>>> "###
line 4
line 5
"
); );
} }
@ -234,22 +231,21 @@ line 5
], ],
}; };
let mut result: Vec<u8> = vec![]; insta::assert_snapshot!(
materialize_conflict(store, &path, &conflict, &mut result).unwrap(); &materialize_conflict_string(store, &path, &conflict),
assert_eq!( @r###"
String::from_utf8(result).unwrap().as_str(), line 1
"line 1 line 2
line 2 <<<<<<<
<<<<<<< -------
------- +++++++
+++++++ -line 3
-line 3 +++++++
+++++++ right
right >>>>>>>
>>>>>>> line 4
line 4 line 5
line 5 "###
"
); );
} }
@ -503,3 +499,9 @@ fn test_update_conflict_from_content() {
} }
) )
} }
fn materialize_conflict_string(store: &Store, path: &RepoPath, conflict: &Conflict) -> String {
let mut result: Vec<u8> = vec![];
materialize_conflict(store, path, conflict, &mut result).unwrap();
String::from_utf8(result).unwrap()
}