Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add tests to history
  • Loading branch information
sholderbach committed Apr 10, 2021
commit 06bc1463eb79c6f53ae19dc2f9099788899868c3
33 changes: 33 additions & 0 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,36 @@ impl Index<usize> for History {
&self.entries[index]
}
}

#[cfg(test)]
mod tests {
use super::History;
#[test]
fn navigates_safely() {
let mut hist = History::default();
hist.append("test".to_string());
assert_eq!(hist.go_forward(), None); // On empty line nothing to move forward to
assert_eq!(hist.go_back().unwrap(), "test"); // Back to the entry
assert_eq!(hist.go_back(), None); // Nothing to move back to
assert_eq!(hist.go_forward(), None); // Forward out of history to editing line
}
#[test]
fn appends_only_unique() {
let mut hist = History::default();
hist.append("unique_old".to_string());
hist.append("test".to_string());
hist.append("test".to_string());
hist.append("unique".to_string());
assert_eq!(hist.entries().len(), 3);
assert_eq!(hist.go_back().unwrap(), "unique");
assert_eq!(hist.go_back().unwrap(), "test");
assert_eq!(hist.go_back().unwrap(), "unique_old");
assert_eq!(hist.go_back(), None);
}
#[test]
fn appends_no_empties() {
let mut hist = History::default();
hist.append("".to_string());
assert_eq!(hist.entries().len(), 0);
}
}