mirror of
https://github.com/alexpasmantier/television.git
synced 2025-07-29 14:21:43 +00:00
fix(history): short-circuit add_entry
when history size is zero
Fixes #646
This commit is contained in:
parent
4b84a12320
commit
07853f0700
@ -80,6 +80,9 @@ impl History {
|
|||||||
|
|
||||||
/// Add a new history entry, if it's not a duplicate.
|
/// Add a new history entry, if it's not a duplicate.
|
||||||
pub fn add_entry(&mut self, query: String, channel: String) -> Result<()> {
|
pub fn add_entry(&mut self, query: String, channel: String) -> Result<()> {
|
||||||
|
if self.max_size == 0 {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
// Don't add empty queries
|
// Don't add empty queries
|
||||||
if query.trim().is_empty() {
|
if query.trim().is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
@ -734,4 +737,19 @@ mod tests {
|
|||||||
// Calling get_next without any previous navigation should return None
|
// Calling get_next without any previous navigation should return None
|
||||||
assert!(hist.get_next_entry().is_none());
|
assert!(hist.get_next_entry().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add_entry_with_history_size_zero() {
|
||||||
|
let dir = tempdir().expect("failed to create tempdir");
|
||||||
|
let mut hist = History::new(0, "files", false, dir.path());
|
||||||
|
|
||||||
|
// Adding an entry should not change the history
|
||||||
|
hist.add_entry("file1".into(), "files".into()).unwrap();
|
||||||
|
assert!(hist.is_empty());
|
||||||
|
assert_eq!(hist.len(), 0);
|
||||||
|
|
||||||
|
// Navigation should return None
|
||||||
|
assert!(hist.get_previous_entry().is_none());
|
||||||
|
assert!(hist.get_next_entry().is_none());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user