bin(patch): Extend review tests

This commit is contained in:
Erik Kundt
2024-12-11 14:37:36 +01:00
parent baf03356d6
commit b399bc4626
2 changed files with 70 additions and 4 deletions
+65 -4
View File
@@ -684,9 +684,24 @@ mod test {
}
#[test]
fn app_can_be_constructed() -> Result<()> {
fn app_with_single_hunk_can_be_constructed() -> Result<()> {
let alice = test::fixtures::node_with_repo();
let branch = test::fixtures::branch(&alice);
let branch = test::fixtures::branch_with_line_added(&alice);
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
let app = fixtures::app(&alice, patch)?;
assert_eq!(app.hunks().len(), 1);
Ok(())
}
#[test]
fn app_with_single_file_multiple_hunks_can_be_constructed() -> Result<()> {
let alice = test::fixtures::node_with_repo();
let branch = test::fixtures::branch_with_eof_removed(&alice);
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
@@ -701,7 +716,7 @@ mod test {
#[test]
fn first_hunk_is_selected_by_default() -> Result<()> {
let alice = test::fixtures::node_with_repo();
let branch = test::fixtures::branch(&alice);
let branch = test::fixtures::branch_with_line_added(&alice);
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
@@ -716,7 +731,7 @@ mod test {
#[test]
fn hunk_can_be_selected() -> Result<()> {
let alice = test::fixtures::node_with_repo();
let branch = test::fixtures::branch(&alice);
let branch = test::fixtures::branch_with_eof_removed(&alice);
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
@@ -730,4 +745,50 @@ mod test {
Ok(())
}
#[test]
fn single_file_single_hunk_can_be_accepted() -> Result<()> {
let alice = test::fixtures::node_with_repo();
let branch = test::fixtures::branch_with_line_added(&alice);
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
let mut app = fixtures::app(&alice, patch)?;
app.update(Message::Accept);
let hunks = app.hunks();
let state = &hunks.get(0).unwrap().inner.state();
assert_eq!(**state, HunkState::Accepted);
Ok(())
}
#[test]
fn multiple_files_single_hunk_can_be_accepted() -> Result<()> {
let alice = test::fixtures::node_with_repo();
let branch = test::fixtures::branch_with_files_added(&alice);
let mut patches = Cache::no_cache(&alice.repo.repo).unwrap();
let patch = test::fixtures::patch(&alice, &branch, &mut patches)?;
let mut app = fixtures::app(&alice, patch)?;
app.update(Message::Accept);
app.update(Message::HunkChanged {
state: TableState::new(Some(1)),
});
app.update(Message::Accept);
let hunks = app.hunks();
let states = [
hunks.get(0).unwrap().inner.state(),
hunks.get(1).unwrap().inner.state(),
];
assert_eq!(states, [&HunkState::Accepted, &HunkState::Accepted]);
Ok(())
}
}
+5
View File
@@ -20,6 +20,11 @@ pub mod fixtures {
checkout.branch_with([("README", b"Hello World!\nHello World!\n")])
}
pub fn branch_with_files_added(node: &NodeWithRepo) -> BranchWith {
let checkout = node.repo.checkout();
checkout.branch_with([("CONTRIBUTE", b"TBD\n"), ("LICENSE", b"TBD\n")])
}
pub fn patch<'a, 'g>(
node: &'a NodeWithRepo,
branch: &BranchWith,