let untracked_files = BTreeSet::from_iter([
"untracked_0.rs".to_string(),
"untracked_1.rs".to_string(),
"untracked_2.rs".to_string(),
]);
state.cursor.selection = Some(cursor::Selection::UntrackedFile {
ix: 0,
path: "untracked_1.rs".to_string(),
});
let task = reindex_selection(
&mut state.cursor,
&mut state.files,
&untracked_files,
changed_files,
log,
);
assert!(state.cursor.selection.is_some());
assert_matches!(
state.cursor.selection.as_ref().unwrap(),
libflorescence::cursor::Selection::UntrackedFile { ix, path }
if *ix == 1 && path == "untracked_1.rs"
);
assert!(task.is_none());
assert_eq!(state.files.diffs_cache.inner.len(), 1);
assert_matches!(
state.files.diffs_cache.inner.peek(&file::Id {
path: "untracked_1.rs".to_string(),
file_kind: file::Kind::Untracked
}),
Some(file::Diff::Loading)
);
// Clear the cache for next test case
state.files.diffs_cache.inner.clear();
// _________________________________________________________________________
// Case: untracked file selection not present after refresh
state.cursor.selection = Some(cursor::Selection::UntrackedFile {
ix: 0,
path: "untracked_gone.rs".to_string(),
});
let task = reindex_selection(
&mut state.cursor,
&mut state.files,
&untracked_files,
changed_files,
log,
);
assert!(state.cursor.selection.is_none());
assert!(task.is_none());
assert!(state.files.diffs_cache.inner.is_empty());
// _________________________________________________________________________
// Case: changed file selection present after refresh, index is decreased,
// file has diffs with contents
let changed_files = repo::ChangedFiles::from_iter([
(
"changed_0.rs".to_string(),
BTreeSet::from_iter([repo::ChangedFileDiff::Add]),
),
("changed_1.rs".to_string(), BTreeSet::new()),
("changed_2.rs".to_string(), BTreeSet::new()),
]);
state.cursor.selection = Some(cursor::Selection::ChangedFile {
ix: 1,
path: "changed_0.rs".to_string(),
});
let task = reindex_selection(
&mut state.cursor,
&mut state.files,
&untracked_files,
&changed_files,
log,
);
assert!(state.cursor.selection.is_some());
assert_matches!(
state.cursor.selection.as_ref().unwrap(),
libflorescence::cursor::Selection::ChangedFile { ix, path }
if *ix == 0 && path == "changed_0.rs"
);
assert!(task.is_none());
assert_eq!(state.files.diffs_cache.inner.len(), 1);
assert_matches!(
state.files.diffs_cache.inner.peek(&file::Id {
path: "changed_0.rs".to_string(),
file_kind: file::Kind::Changed
}),
Some(file::Diff::Loading)
);
// Clear the cache for next test case
state.files.diffs_cache.inner.clear();
// _________________________________________________________________________
// Case: changed file selection present after refresh, index is the same,
// but file has no diffs with contents
state.cursor.selection = Some(cursor::Selection::ChangedFile {
ix: 1,
path: "changed_1.rs".to_string(),
});
let task = reindex_selection(
&mut state.cursor,
&mut state.files,
&untracked_files,
&changed_files,
log,
);
assert!(state.cursor.selection.is_some());
assert_matches!(
state.cursor.selection.as_ref().unwrap(),
libflorescence::cursor::Selection::ChangedFile { ix, path }
if *ix == 1 && path == "changed_1.rs"
);
assert!(task.is_none());
assert!(state.files.diffs_cache.inner.is_empty());
// _________________________________________________________________________
// Case: changed file selection not present after refresh
state.cursor.selection = Some(cursor::Selection::ChangedFile {
ix: 0,
path: "changed_gone.rs".to_string(),
});
let task = reindex_selection(
&mut state.cursor,
&mut state.files,
&untracked_files,
&changed_files,
log,
);
assert!(state.cursor.selection.is_none());
assert!(task.is_none());
assert!(state.files.diffs_cache.inner.is_empty());
// _________________________________________________________________________
// Case: log selection present after refresh
let change_hash = |bytes: &[u8]| {
let mut hasher = pijul::pristine::Hasher::default();
hasher.update(bytes);
hasher.finish()
};
let change_hash_0 = change_hash(&[0]);
let change_hash_1 = change_hash(&[1]);
let change_hash_2 = change_hash(&[2]);
let log = vec![
repo::LogEntry {
hash: change_hash_0,
message: "".to_string(),
file_paths: vec![],
},
repo::LogEntry {
hash: change_hash_1,
message: "".to_string(),
file_paths: vec![],
},
repo::LogEntry {
hash: change_hash_2,
message: "".to_string(),
file_paths: vec![],
},
];
state.cursor.selection = Some(cursor::Selection::LogChange {
ix: 0,
hash: change_hash_2,
message: "".to_string(),
diffs: None,
file: None,
});
let task = reindex_selection(
&mut state.cursor,
&mut state.files,
&untracked_files,
&changed_files,
&log,
);
assert!(state.cursor.selection.is_some());
assert_matches!(
state.cursor.selection.as_ref().unwrap(),
libflorescence::cursor::Selection::LogChange { ix, hash, .. }
if *ix == 2 && *hash == change_hash_2
);
assert!(task.is_some());
assert!(state.files.diffs_cache.inner.is_empty());
// _________________________________________________________________________
// Case: log selection not present after refresh
state.cursor.selection = Some(cursor::Selection::UntrackedFile {
ix: 0,
path: "log_gone.rs".to_string(),
});
let task = reindex_selection(
&mut state.cursor,
&mut state.files,
&untracked_files,
&changed_files,
&log,
);
assert!(state.cursor.selection.is_none());
assert!(task.is_none());
assert!(state.files.diffs_cache.inner.is_empty());
}