Skip to content

Commit 26f06d0

Browse files
committed
test updates
1 parent 89161b8 commit 26f06d0

File tree

28 files changed

+683
-185
lines changed

28 files changed

+683
-185
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ redundant_closure_for_method_calls = "allow"
214214
redundant_pub_crate = "allow"
215215
ref_patterns = "allow"
216216
self_named_module_files = "allow"
217+
semicolon_outside_block = "allow"
217218
single_call_fn = "allow"
218219
std_instead_of_alloc = "allow"
219220
std_instead_of_core = "allow"

src/application.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ where ModuleProvider: module::ModuleProvider + Send + 'static
8585
let commit_diff_loader = CommitDiffLoader::new(config_loader.eject_repository(), commit_diff_loader_options);
8686

8787
let diff_update_handler = Self::create_diff_update_handler(input_state.clone());
88-
let diff_thread = diff::Thread::new(commit_diff_loader, diff_update_handler);
88+
let diff_thread = diff::thread::Thread::new(commit_diff_loader, diff_update_handler);
8989
let diff_state = diff_thread.state();
9090
threads.push(Box::new(diff_thread));
9191

src/application/app_data.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub(crate) struct AppData {
99
config: Arc<Config>,
1010
active_module: Arc<Mutex<module::State>>,
1111
todo_file: Arc<Mutex<TodoFile>>,
12-
diff_state: diff::State,
12+
diff_state: diff::thread::State,
1313
view_state: view::State,
1414
input_state: input::State,
1515
search_state: search::State,
@@ -20,7 +20,7 @@ impl AppData {
2020
config: Config,
2121
active_module: module::State,
2222
todo_file: Arc<Mutex<TodoFile>>,
23-
diff_state: diff::State,
23+
diff_state: diff::thread::State,
2424
view_state: view::State,
2525
input_state: input::State,
2626
search_state: search::State,
@@ -48,7 +48,7 @@ impl AppData {
4848
Arc::clone(&self.todo_file)
4949
}
5050

51-
pub(crate) fn diff_state(&self) -> diff::State {
51+
pub(crate) fn diff_state(&self) -> diff::thread::State {
5252
self.diff_state.clone()
5353
}
5454

src/diff.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
mod action;
21
mod commit;
32
mod commit_diff;
43
mod commit_diff_loader;
@@ -14,12 +13,9 @@ mod reference_kind;
1413
mod status;
1514
mod user;
1615

17-
mod state;
18-
mod thread;
19-
mod update_handler;
16+
pub(crate) mod thread;
2017

2118
pub(crate) use self::{
22-
action::Action,
2319
commit::Commit,
2420
commit_diff::CommitDiff,
2521
commit_diff_loader::CommitDiffLoader,
@@ -32,9 +28,6 @@ pub(crate) use self::{
3228
origin::Origin,
3329
reference::Reference,
3430
reference_kind::ReferenceKind,
35-
state::{LoadStatus, State},
3631
status::Status,
37-
thread::Thread,
38-
update_handler::UpdateHandlerFn,
3932
user::User,
4033
};

src/diff/commit_diff_loader.rs

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use crate::{
1818
FileMode,
1919
FileStatus,
2020
FileStatusBuilder,
21-
LoadStatus,
2221
Status,
22+
thread::LoadStatus,
2323
},
2424
git::GitError,
2525
};
@@ -62,12 +62,12 @@ impl CommitDiffLoader {
6262
Arc::clone(&self.commit_diff)
6363
}
6464

65-
fn diff<'r>(
66-
repository: &'r Repository,
65+
fn diff<'repo>(
66+
repository: &'repo Repository,
6767
config: &CommitDiffLoaderOptions,
6868
commit: &git2::Commit<'_>,
6969
diff_options: &mut DiffOptions,
70-
) -> Result<Diff<'r>, GitError> {
70+
) -> Result<Diff<'repo>, GitError> {
7171
_ = diff_options
7272
.context_lines(config.context_lines)
7373
.ignore_filemode(false)
@@ -154,8 +154,6 @@ impl CommitDiffLoader {
154154
Ok(())
155155
}
156156

157-
#[expect(clippy::as_conversions, reason = "Realistically safe conversion.")]
158-
#[expect(clippy::unwrap_in_result, reason = "Unwrap usage failure considered a bug.")]
159157
pub(crate) fn collect(
160158
&self,
161159
diff: &Diff<'_>,
@@ -863,18 +861,16 @@ mod tests {
863861
let notifier = move |status| {
864862
let mut c = notifier_calls.lock();
865863
c.push(status);
866-
return false;
864+
false
867865
};
868866

869867
_ = diff_with_notifier(repository, CommitDiffLoaderOptions::new(), notifier).unwrap();
870868

871869
let c = calls.lock();
872-
assert_eq!(c.get(0).unwrap(), &LoadStatus::New);
870+
assert_eq!(c.first().unwrap(), &LoadStatus::New);
873871
assert_eq!(c.get(1).unwrap(), &LoadStatus::Diff(0, 10));
874-
assert_eq!(c.get(2).unwrap(), &LoadStatus::Diff(3, 10));
875-
assert_eq!(c.get(3).unwrap(), &LoadStatus::Diff(6, 10));
876-
assert_eq!(c.get(4).unwrap(), &LoadStatus::Diff(9, 10));
877-
assert_eq!(c.get(5).unwrap(), &LoadStatus::DiffComplete);
872+
assert!(matches!(c.get(2).unwrap(), &LoadStatus::Diff(_, 10)));
873+
assert!(matches!(c.last().unwrap(), &LoadStatus::DiffComplete));
878874
});
879875
}
880876

@@ -891,23 +887,51 @@ mod tests {
891887
let notifier = move |status| {
892888
let mut c = notifier_calls.lock();
893889
c.push(status);
894-
return false;
890+
false
895891
};
896892

897893
_ = diff_with_notifier(repository, CommitDiffLoaderOptions::new().copies(true), notifier).unwrap();
898894

899-
let c = calls.lock();
900-
assert_eq!(c.get(0).unwrap(), &LoadStatus::New);
901-
assert_eq!(c.get(1).unwrap(), &LoadStatus::QuickDiff(0, 10));
902-
assert_eq!(c.get(2).unwrap(), &LoadStatus::QuickDiff(3, 10));
903-
assert_eq!(c.get(3).unwrap(), &LoadStatus::QuickDiff(6, 10));
904-
assert_eq!(c.get(4).unwrap(), &LoadStatus::QuickDiff(9, 10));
905-
assert_eq!(c.get(5).unwrap(), &LoadStatus::CompleteQuickDiff);
906-
assert_eq!(c.get(6).unwrap(), &LoadStatus::Diff(0, 10));
907-
assert_eq!(c.get(7).unwrap(), &LoadStatus::Diff(3, 10));
908-
assert_eq!(c.get(8).unwrap(), &LoadStatus::Diff(6, 10));
909-
assert_eq!(c.get(9).unwrap(), &LoadStatus::Diff(9, 10));
910-
assert_eq!(c.get(10).unwrap(), &LoadStatus::DiffComplete);
895+
// Since the exact emitted statues are based on time, this matches a dynamic pattern of:
896+
// - New
897+
// - QuickDiff(0, 10)
898+
// - QuickDiff(>0, 10)
899+
// - CompleteQuickDiff
900+
// - Diff(0, 10)
901+
// - Diff(>0, 10)
902+
// - DiffComplete
903+
let mut pass = false;
904+
let mut expected = LoadStatus::New;
905+
for c in calls.lock().clone() {
906+
match (&expected, c) {
907+
(&LoadStatus::New, LoadStatus::New) => {
908+
expected = LoadStatus::QuickDiff(0, 10);
909+
},
910+
(&LoadStatus::QuickDiff(0, 10), LoadStatus::QuickDiff(0, 10)) => {
911+
expected = LoadStatus::QuickDiff(1, 10);
912+
},
913+
(&LoadStatus::QuickDiff(1, 10), LoadStatus::QuickDiff(p, 10)) => {
914+
assert!(p > 0);
915+
expected = LoadStatus::CompleteQuickDiff;
916+
},
917+
(&LoadStatus::CompleteQuickDiff, LoadStatus::CompleteQuickDiff) => {
918+
expected = LoadStatus::Diff(0, 10);
919+
},
920+
(&LoadStatus::Diff(0, 10), LoadStatus::Diff(0, 10)) => {
921+
expected = LoadStatus::Diff(1, 10);
922+
},
923+
(&LoadStatus::Diff(1, 10), LoadStatus::Diff(p, 10)) => {
924+
assert!(p > 0);
925+
expected = LoadStatus::DiffComplete;
926+
},
927+
(&LoadStatus::DiffComplete, LoadStatus::DiffComplete) => {
928+
pass = true;
929+
},
930+
(..) => {},
931+
}
932+
}
933+
934+
assert!(pass);
911935
});
912936
}
913937

@@ -922,14 +946,14 @@ mod tests {
922946
let notifier = move |status| {
923947
let mut c = notifier_calls.lock();
924948
c.push(status);
925-
return true;
949+
true
926950
};
927951

928952
_ = diff_with_notifier(repository, CommitDiffLoaderOptions::new(), notifier).unwrap();
929953

930954
let c = calls.lock();
931955
assert_eq!(c.len(), 1);
932-
assert_eq!(c.get(0).unwrap(), &LoadStatus::New);
956+
assert_eq!(c.first().unwrap(), &LoadStatus::New);
933957
});
934958
}
935959

@@ -944,14 +968,14 @@ mod tests {
944968
let notifier = move |status| {
945969
let mut c = notifier_calls.lock();
946970
c.push(status);
947-
return c.len() == 2;
971+
c.len() == 2
948972
};
949973

950974
_ = diff_with_notifier(repository, CommitDiffLoaderOptions::new(), notifier).unwrap();
951975

952976
let c = calls.lock();
953977
assert_eq!(c.len(), 2);
954-
assert_eq!(c.get(0).unwrap(), &LoadStatus::New);
978+
assert_eq!(c.first().unwrap(), &LoadStatus::New);
955979
assert_eq!(c.get(1).unwrap(), &LoadStatus::Diff(0, 1));
956980
});
957981
}
@@ -969,16 +993,14 @@ mod tests {
969993
let notifier = move |status| {
970994
let mut c = notifier_calls.lock();
971995
c.push(status);
972-
return c.len() == 4;
996+
c.len() == 4
973997
};
974998

975999
_ = diff_with_notifier(repository, CommitDiffLoaderOptions::new(), notifier).unwrap();
9761000
let c = calls.lock();
977-
assert_eq!(c.len(), 4);
978-
assert_eq!(c.get(0).unwrap(), &LoadStatus::New);
1001+
assert_eq!(c.first().unwrap(), &LoadStatus::New);
9791002
assert_eq!(c.get(1).unwrap(), &LoadStatus::Diff(0, 10));
980-
assert_eq!(c.get(2).unwrap(), &LoadStatus::Diff(3, 10));
981-
assert_eq!(c.get(3).unwrap(), &LoadStatus::Diff(6, 10));
1003+
assert!(matches!(c.last().unwrap(), &LoadStatus::Diff(_, 10)));
9821004
});
9831005
}
9841006

@@ -993,18 +1015,16 @@ mod tests {
9931015
let calls = Arc::new(Mutex::new(Vec::new()));
9941016
let notifier_calls = Arc::clone(&calls);
9951017
let notifier = move |status| {
996-
eprintln!("{:?}", status);
9971018
let mut c = notifier_calls.lock();
9981019
c.push(status);
999-
return c.len() == 3;
1020+
c.len() == 3
10001021
};
10011022

10021023
_ = diff_with_notifier(repository, CommitDiffLoaderOptions::new().copies(true), notifier).unwrap();
10031024
let c = calls.lock();
1004-
assert_eq!(c.len(), 3);
1005-
assert_eq!(c.get(0).unwrap(), &LoadStatus::New);
1025+
assert_eq!(c.first().unwrap(), &LoadStatus::New);
10061026
assert_eq!(c.get(1).unwrap(), &LoadStatus::QuickDiff(0, 10));
1007-
assert_eq!(c.get(2).unwrap(), &LoadStatus::QuickDiff(3, 10));
1027+
assert!(matches!(c.last().unwrap(), &LoadStatus::QuickDiff(_, 10)));
10081028
});
10091029
}
10101030

@@ -1020,19 +1040,17 @@ mod tests {
10201040
let notifier_calls = Arc::clone(&calls);
10211041
let notifier = move |status| {
10221042
let mut c = notifier_calls.lock();
1043+
let rtn = status == LoadStatus::CompleteQuickDiff;
10231044
c.push(status);
1024-
return c.len() == 6;
1045+
rtn
10251046
};
10261047

10271048
_ = diff_with_notifier(repository, CommitDiffLoaderOptions::new().copies(true), notifier).unwrap();
10281049
let c = calls.lock();
1029-
assert_eq!(c.len(), 6);
1030-
assert_eq!(c.get(0).unwrap(), &LoadStatus::New);
1050+
assert_eq!(c.first().unwrap(), &LoadStatus::New);
10311051
assert_eq!(c.get(1).unwrap(), &LoadStatus::QuickDiff(0, 10));
1032-
assert_eq!(c.get(2).unwrap(), &LoadStatus::QuickDiff(3, 10));
1033-
assert_eq!(c.get(3).unwrap(), &LoadStatus::QuickDiff(6, 10));
1034-
assert_eq!(c.get(4).unwrap(), &LoadStatus::QuickDiff(9, 10));
1035-
assert_eq!(c.get(5).unwrap(), &LoadStatus::CompleteQuickDiff);
1052+
assert!(matches!(c.get(2).unwrap(), &LoadStatus::QuickDiff(_, 10)));
1053+
assert_eq!(c.last().unwrap(), &LoadStatus::CompleteQuickDiff);
10361054
});
10371055
}
10381056
}

0 commit comments

Comments
 (0)