Merge branch 'fix-explore-panic' into overhaul_config

This commit is contained in:
Reilly Wood 2024-06-05 19:43:57 -07:00
commit 88f99f0b5d
2 changed files with 9 additions and 10 deletions

View File

@ -28,11 +28,10 @@ struct Cursor {
impl Cursor { impl Cursor {
/// Constructor to create a new Cursor /// Constructor to create a new Cursor
pub fn new(size: usize) -> Result<Self> { pub fn new(size: usize) -> Self {
if size == 0 { // In theory we should not be able to create a cursor with size 0, but in practice
bail!("Size cannot be zero"); // it's easier to allow that for empty lists etc. instead of propagating errors
} Cursor { position: 0, size }
Ok(Cursor { position: 0, size })
} }
/// The max position the cursor can be at /// The max position the cursor can be at
@ -88,7 +87,7 @@ mod tests {
#[test] #[test]
fn test_cursor_set_position() { fn test_cursor_set_position() {
// from 0 to 9 // from 0 to 9
let mut cursor = Cursor::new(10).unwrap(); let mut cursor = Cursor::new(10);
cursor.set_position(5); cursor.set_position(5);
assert_eq!(cursor.position, 5); assert_eq!(cursor.position, 5);
@ -99,7 +98,7 @@ mod tests {
#[test] #[test]
fn test_cursor_move_forward() { fn test_cursor_move_forward() {
// from 0 to 9 // from 0 to 9
let mut cursor = Cursor::new(10).unwrap(); let mut cursor = Cursor::new(10);
assert_eq!(cursor.position, 0); assert_eq!(cursor.position, 0);
cursor.move_forward(3); cursor.move_forward(3);
assert_eq!(cursor.position, 3); assert_eq!(cursor.position, 3);
@ -111,7 +110,7 @@ mod tests {
#[test] #[test]
fn test_cursor_move_backward() { fn test_cursor_move_backward() {
// from 0 to 9 // from 0 to 9
let mut cursor = Cursor::new(10).unwrap(); let mut cursor = Cursor::new(10);
cursor.move_backward(3); cursor.move_backward(3);
assert_eq!(cursor.position, 0); assert_eq!(cursor.position, 0);

View File

@ -42,8 +42,8 @@ impl WindowCursor {
} }
Ok(Self { Ok(Self {
view: Cursor::new(view_size)?, view: Cursor::new(view_size),
window: Cursor::new(window_size)?, window: Cursor::new(window_size),
}) })
} }