Compare commits

..

4 Commits

Author SHA1 Message Date
e984d7324c wip: test coverage for
* sheet navigation
* column sizing
* quit
2024-12-28 10:53:59 -05:00
52d1909868 wip: add test for cell deletion 2024-12-28 10:53:59 -05:00
c5cbc1e75c wip: test coverage for copy paste 2024-12-28 10:53:59 -05:00
704f9f7746 feat: clear char queue on Esc 2024-12-28 10:51:21 -05:00
2 changed files with 80 additions and 6 deletions

View File

@ -652,6 +652,7 @@ impl<'ws> Workspace<'ws> {
match key.code {
KeyCode::Esc => {
self.state.reset_n_prefix();
self.state.char_queue.clear();
}
KeyCode::Char(d) if d.is_ascii_digit() => {
self.handle_numeric_prefix(d);
@ -727,12 +728,6 @@ impl<'ws> Workspace<'ws> {
Ok(())
})?;
}
KeyCode::Char('s')
if key.modifiers == KeyModifiers::HYPER
|| key.modifiers == KeyModifiers::SUPER =>
{
self.save_file()?;
}
KeyCode::Char('l') if key.modifiers == KeyModifiers::CONTROL => {
self.run_with_prefix(|ws: &mut Workspace<'_>| -> Result<()> {
let Address { row: _, col } = &ws.book.location;

View File

@ -563,3 +563,82 @@ fn test_traditional_copy_paste_rendered() {
"3",
);
}
#[test]
fn test_clear_cell() {
let mut ws =
Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook");
ws.book.edit_current_cell("foo")
.expect("failed to edit cell");
ws.book.evaluate();
assert_eq!("foo", ws.book.get_current_cell_contents().expect("failed to get cell contents"));
InputScript::default()
.add_char('d')
.run(&mut ws)
.expect("Failed to run input script");
assert_eq!("", ws.book.get_current_cell_contents().expect("failed to get cell contents"));
}
#[test]
fn test_clear_cell_all() {
let mut ws =
Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook");
ws.book.edit_current_cell("foo")
.expect("failed to edit cell");
ws.book.evaluate();
assert_eq!("foo", ws.book.get_current_cell_contents().expect("failed to get cell contents"));
InputScript::default()
.add_char('D')
.run(&mut ws)
.expect("Failed to run input script");
assert_eq!("", ws.book.get_current_cell_contents().expect("failed to get cell contents"));
}
#[test]
fn test_sheet_navigation() {
let mut ws =
Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook");
ws.book.new_sheet(Some("sheet 2")).expect("Failed to set sheet name");
ws.book.new_sheet(Some("sheet 3")).expect("Failed to set sheet name");
ws.book.new_sheet(Some("sheet 4")).expect("Failed to set sheet name");
InputScript::default()
.add_modified_char('n', KeyModifiers::CONTROL)
.add_modified_char('n', KeyModifiers::CONTROL)
.run(&mut ws)
.expect("Failed to run input script");
assert_eq!("sheet 3", ws.book.get_sheet_name().expect("Failed to get sheet name"));
InputScript::default()
.add_modified_char('p', KeyModifiers::CONTROL)
.run(&mut ws)
.expect("Failed to run input script");
assert_eq!("sheet 2", ws.book.get_sheet_name().expect("Failed to get sheet name"));
}
#[test]
fn test_sheet_column_sizing() {
let mut ws =
Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook");
InputScript::default()
.add_char('3')
.add_modified_char('l', KeyModifiers::CONTROL)
.run(&mut ws)
.expect("Failed to run input script");
assert_eq!(28, ws.book.get_col_size(1).expect("Failed to get column size"));
InputScript::default()
.add_char('1')
.add_modified_char('h', KeyModifiers::CONTROL)
.run(&mut ws)
.expect("Failed to run input script");
assert_eq!(27, ws.book.get_col_size(1).expect("Failed to get column size"));
}
#[test]
fn test_quit() {
let mut ws =
Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook");
let result = InputScript::default()
.add_char('q')
.run(&mut ws)
.expect("Failed to run input script");
assert!(result.is_some());
}