mirror of
https://github.com/sayanarijit/xplr.git
synced 2024-09-11 19:07:47 +03:00
Adds tests for the ScrollState calc_skipped_rows fn
This commit is contained in:
parent
87805509c5
commit
fd40de26e7
@ -110,3 +110,106 @@ fn now() -> OffsetDateTime {
|
||||
.ok()
|
||||
.unwrap_or_else(OffsetDateTime::now_utc)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_calc_skipped_rows_non_vimlike_scrolling() {
|
||||
let mut state = ScrollState {
|
||||
current_focus: 10,
|
||||
last_focus: Some(8),
|
||||
skipped_rows: 0,
|
||||
};
|
||||
|
||||
let height = 5;
|
||||
let total = 20;
|
||||
let vimlike_scrolling = false;
|
||||
|
||||
let result = state.calc_skipped_rows(height, total, vimlike_scrolling);
|
||||
assert_eq!(result, height * (state.current_focus / height.max(1)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_calc_skipped_rows_entered_directory() {
|
||||
let mut state = ScrollState {
|
||||
current_focus: 10,
|
||||
last_focus: None,
|
||||
skipped_rows: 0,
|
||||
};
|
||||
|
||||
let height = 5;
|
||||
let total = 20;
|
||||
let vimlike_scrolling = true;
|
||||
|
||||
let result = state.calc_skipped_rows(height, total, vimlike_scrolling);
|
||||
assert_eq!(result, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_calc_skipped_rows_top_of_directory() {
|
||||
let mut state = ScrollState {
|
||||
current_focus: 0,
|
||||
last_focus: Some(8),
|
||||
skipped_rows: 5,
|
||||
};
|
||||
|
||||
let height = 5;
|
||||
let total = 20;
|
||||
let vimlike_scrolling = true;
|
||||
|
||||
let result = state.calc_skipped_rows(height, total, vimlike_scrolling);
|
||||
assert_eq!(result, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_calc_skipped_rows_bottom_of_directory() {
|
||||
let mut state = ScrollState {
|
||||
current_focus: 19,
|
||||
last_focus: Some(18),
|
||||
skipped_rows: 15,
|
||||
};
|
||||
|
||||
let height = 5;
|
||||
let total = 20;
|
||||
let vimlike_scrolling = true;
|
||||
|
||||
let result = state.calc_skipped_rows(height, total, vimlike_scrolling);
|
||||
assert_eq!(result, 15);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_calc_skipped_rows_scrolling_down() {
|
||||
let mut state = ScrollState {
|
||||
current_focus: 12,
|
||||
last_focus: Some(10),
|
||||
skipped_rows: 10,
|
||||
};
|
||||
|
||||
let height = 5;
|
||||
let total = 20;
|
||||
let vimlike_scrolling = true;
|
||||
|
||||
let result = state.calc_skipped_rows(height, total, vimlike_scrolling);
|
||||
assert_eq!(result, 11);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_calc_skipped_rows_scrolling_up() {
|
||||
let mut state = ScrollState {
|
||||
current_focus: 8,
|
||||
last_focus: Some(10),
|
||||
skipped_rows: 10,
|
||||
};
|
||||
|
||||
let height = 5;
|
||||
let total = 20;
|
||||
let vimlike_scrolling = true;
|
||||
|
||||
let result = state.calc_skipped_rows(height, total, vimlike_scrolling);
|
||||
assert_eq!(result, 5);
|
||||
}
|
||||
|
||||
// Add more tests for other scenarios...
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user