wip: InputScript constructor helper

This commit is contained in:
Jeremy Wall 2025-01-07 19:02:42 -05:00
parent c3ab2b72de
commit b38af78ad7

View File

@ -60,6 +60,10 @@ impl InputScript {
} }
} }
fn script() -> InputScript {
InputScript::default()
}
fn construct_key_event(code: KeyCode) -> Event { fn construct_key_event(code: KeyCode) -> Event {
construct_modified_key_event(code, KeyModifiers::empty()) construct_modified_key_event(code, KeyModifiers::empty())
} }
@ -260,7 +264,7 @@ fn test_input_navitation_enter_key() {
let mut ws = new_workspace(); let mut ws = new_workspace();
let row = ws.book.location.row; let row = ws.book.location.row;
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.enter() .enter()
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle enter key"); .expect("Failed to handle enter key");
@ -272,7 +276,7 @@ fn test_input_navitation_tab_key() {
let mut ws = new_workspace(); let mut ws = new_workspace();
let col = dbg!(ws.book.location.col); let col = dbg!(ws.book.location.col);
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.tab() .tab()
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle enter key"); .expect("Failed to handle enter key");
@ -284,12 +288,12 @@ fn test_input_navitation_shift_enter_key() {
let mut ws = new_workspace(); let mut ws = new_workspace();
let row = ws.book.location.row; let row = ws.book.location.row;
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.enter() .enter()
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle enter key"); .expect("Failed to handle enter key");
assert_eq!(row + 1, ws.book.location.row); assert_eq!(row + 1, ws.book.location.row);
InputScript::default() script()
.event(construct_modified_key_event( .event(construct_modified_key_event(
KeyCode::Enter, KeyCode::Enter,
KeyModifiers::SHIFT, KeyModifiers::SHIFT,
@ -304,12 +308,12 @@ fn test_input_navitation_shift_tab_key() {
let mut ws = new_workspace(); let mut ws = new_workspace();
let col = dbg!(ws.book.location.col); let col = dbg!(ws.book.location.col);
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.tab() .tab()
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle enter key"); .expect("Failed to handle enter key");
assert_eq!(col + 1, ws.book.location.col); assert_eq!(col + 1, ws.book.location.col);
InputScript::default() script()
.event(construct_modified_key_event( .event(construct_modified_key_event(
KeyCode::Tab, KeyCode::Tab,
KeyModifiers::SHIFT, KeyModifiers::SHIFT,
@ -323,13 +327,13 @@ macro_rules! assert_help_dialog {
($exit : expr) => {{ ($exit : expr) => {{
let mut ws = new_workspace(); let mut ws = new_workspace();
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.char('i') .char('i')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle 'i' key"); .expect("Failed to handle 'i' key");
assert_eq!(Some(&Modality::CellEdit), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::CellEdit), ws.state.modality_stack.last());
let edit_help = ws.render_help_text(); let edit_help = ws.render_help_text();
InputScript::default() script()
.alt('h') .alt('h')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle 'alt-h' key event"); .expect("Failed to handle 'alt-h' key event");
@ -342,22 +346,22 @@ macro_rules! assert_help_dialog {
#[test] #[test]
fn test_edit_mode_help_keycode_esc() { fn test_edit_mode_help_keycode_esc() {
assert_help_dialog!(InputScript::default().esc()); assert_help_dialog!(script().esc());
} }
#[test] #[test]
fn test_edit_mode_help_keycode_enter() { fn test_edit_mode_help_keycode_enter() {
assert_help_dialog!(InputScript::default().enter()); assert_help_dialog!(script().enter());
} }
#[test] #[test]
fn test_edit_mode_help_keycode_q() { fn test_edit_mode_help_keycode_q() {
assert_help_dialog!(InputScript::default().char('q')); assert_help_dialog!(script().char('q'));
} }
#[test] #[test]
fn test_edit_mode_help_keycode_alt_h() { fn test_edit_mode_help_keycode_alt_h() {
assert_help_dialog!(InputScript::default().alt('h')); assert_help_dialog!(script().alt('h'));
} }
#[test] #[test]
@ -365,7 +369,7 @@ fn test_navigation_mode_help_keycode() {
let mut ws = new_workspace(); let mut ws = new_workspace();
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
let help_text = ws.render_help_text(); let help_text = ws.render_help_text();
InputScript::default() script()
.alt('h') .alt('h')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle 'alt-h' key event"); .expect("Failed to handle 'alt-h' key event");
@ -377,13 +381,13 @@ fn test_navigation_mode_help_keycode() {
fn test_command_mode_help_keycode() { fn test_command_mode_help_keycode() {
let mut ws = new_workspace(); let mut ws = new_workspace();
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.char(':') .char(':')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle ':' key"); .expect("Failed to handle ':' key");
assert_eq!(Some(&Modality::Command), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Command), ws.state.modality_stack.last());
let edit_help = ws.render_help_text(); let edit_help = ws.render_help_text();
InputScript::default() script()
.alt('h') .alt('h')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle 'alt-h' key event"); .expect("Failed to handle 'alt-h' key event");
@ -395,12 +399,12 @@ fn test_command_mode_help_keycode() {
fn test_edit_mode_esc_keycode() { fn test_edit_mode_esc_keycode() {
let mut ws = new_workspace(); let mut ws = new_workspace();
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.char('i') .char('i')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle 'i' key"); .expect("Failed to handle 'i' key");
assert_eq!(Some(&Modality::CellEdit), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::CellEdit), ws.state.modality_stack.last());
InputScript::default() script()
.char('a') .char('a')
.esc() .esc()
.run(&mut ws) .run(&mut ws)
@ -424,7 +428,7 @@ fn test_navigation_numeric_prefix() {
ws.book ws.book
.new_sheet(Some("Sheet3")) .new_sheet(Some("Sheet3"))
.expect("failed to create sheet3"); .expect("failed to create sheet3");
InputScript::default() script()
.char('2') .char('2')
.char('3') .char('3')
.char('9') .char('9')
@ -443,7 +447,7 @@ fn test_navigation_numeric_prefix_cancel() {
ws.book ws.book
.new_sheet(Some("Sheet3")) .new_sheet(Some("Sheet3"))
.expect("failed to create sheet3"); .expect("failed to create sheet3");
InputScript::default() script()
.char('2') .char('2')
.char('3') .char('3')
.char('9') .char('9')
@ -463,12 +467,12 @@ fn test_navigation_tab_next_numeric_prefix() {
ws.book ws.book
.new_sheet(Some("Sheet3")) .new_sheet(Some("Sheet3"))
.expect("failed to create sheet3"); .expect("failed to create sheet3");
InputScript::default() script()
.char('2') .char('2')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle '2' key event"); .expect("Failed to handle '2' key event");
assert_eq!(2, ws.state.get_n_prefix()); assert_eq!(2, ws.state.get_n_prefix());
InputScript::default() script()
.ctrl('n') .ctrl('n')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle 'Ctrl-n' key event"); .expect("Failed to handle 'Ctrl-n' key event");
@ -477,7 +481,7 @@ fn test_navigation_tab_next_numeric_prefix() {
ws.book.get_sheet_name().expect("Failed to get sheet name") ws.book.get_sheet_name().expect("Failed to get sheet name")
); );
assert_eq!(1, ws.state.get_n_prefix()); assert_eq!(1, ws.state.get_n_prefix());
InputScript::default() script()
.ctrl('n') .ctrl('n')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle 'Ctrl-n' key event"); .expect("Failed to handle 'Ctrl-n' key event");
@ -496,7 +500,7 @@ fn test_range_copy() {
.move_to(&Address { row: 1, col: 1 }) .move_to(&Address { row: 1, col: 1 })
.expect("Failed to move to row"); .expect("Failed to move to row");
let original_loc = ws.book.location.clone(); let original_loc = ws.book.location.clone();
InputScript::default() script()
.ctrl('r') .ctrl('r')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle 'Ctrl-r' key event"); .expect("Failed to handle 'Ctrl-r' key event");
@ -508,7 +512,7 @@ fn test_range_copy() {
assert!(ws.state.range_select.start.is_none()); assert!(ws.state.range_select.start.is_none());
assert!(ws.state.range_select.end.is_none()); assert!(ws.state.range_select.end.is_none());
InputScript::default() script()
.char('l') .char('l')
.char(' ') .char(' ')
.run(&mut ws) .run(&mut ws)
@ -518,7 +522,7 @@ fn test_range_copy() {
ws.state.range_select.start ws.state.range_select.start
); );
InputScript::default() script()
.char('j') .char('j')
.char(' ') .char(' ')
.run(&mut ws) .run(&mut ws)
@ -539,7 +543,7 @@ fn test_range_copy() {
let original_loc_2 = ws.book.location.clone(); let original_loc_2 = ws.book.location.clone();
assert_eq!(Address { row: 5, col: 5 }, original_loc_2); assert_eq!(Address { row: 5, col: 5 }, original_loc_2);
InputScript::default() script()
.char('v') .char('v')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle 'v' key event"); .expect("Failed to handle 'v' key event");
@ -551,7 +555,7 @@ fn test_range_copy() {
assert!(ws.state.range_select.start.is_some()); assert!(ws.state.range_select.start.is_some());
assert!(ws.state.range_select.end.is_none()); assert!(ws.state.range_select.end.is_none());
InputScript::default() script()
.char('h') .char('h')
.char(' ') .char(' ')
.run(&mut ws) .run(&mut ws)
@ -561,7 +565,7 @@ fn test_range_copy() {
ws.state.range_select.start ws.state.range_select.start
); );
InputScript::default() script()
.char('k') .char('k')
.char(' ') .char(' ')
.run(&mut ws) .run(&mut ws)
@ -581,12 +585,12 @@ fn test_range_copy() {
fn test_range_copy_mode_from_edit_mode() { fn test_range_copy_mode_from_edit_mode() {
let mut ws = new_workspace(); let mut ws = new_workspace();
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.char('e') .char('e')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle 'e' key event"); .expect("Failed to handle 'e' key event");
assert_eq!(Some(&Modality::CellEdit), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::CellEdit), ws.state.modality_stack.last());
InputScript::default() script()
.ctrl('r') .ctrl('r')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle 'Ctrl-r' key event"); .expect("Failed to handle 'Ctrl-r' key event");
@ -597,13 +601,13 @@ fn test_range_copy_mode_from_edit_mode() {
fn test_gg_movement() { fn test_gg_movement() {
let mut ws = new_workspace(); let mut ws = new_workspace();
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.char('j') .char('j')
.char('j') .char('j')
.run(&mut ws) .run(&mut ws)
.expect("failed to handle event sequence"); .expect("failed to handle event sequence");
assert_eq!(ws.book.location, Address { row: 3, col: 1 }); assert_eq!(ws.book.location, Address { row: 3, col: 1 });
InputScript::default() script()
.char('l') .char('l')
.char('g') .char('g')
.char('g') .char('g')
@ -616,14 +620,14 @@ fn test_gg_movement() {
fn test_h_j_k_l_movement() { fn test_h_j_k_l_movement() {
let mut ws = new_workspace(); let mut ws = new_workspace();
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.char('2') .char('2')
.char('j') .char('j')
.char('l') .char('l')
.run(&mut ws) .run(&mut ws)
.expect("failed to handle event sequence"); .expect("failed to handle event sequence");
assert_eq!(ws.book.location, Address { row: 3, col: 2 }); assert_eq!(ws.book.location, Address { row: 3, col: 2 });
InputScript::default() script()
.char('h') .char('h')
.char('2') .char('2')
.char('k') .char('k')
@ -644,7 +648,7 @@ macro_rules! assert_copy_paste {
}; };
($c: expr, $p: expr, $source: expr, $expected: expr) => {{ ($c: expr, $p: expr, $source: expr, $expected: expr) => {{
let mut ws = new_workspace(); let mut ws = new_workspace();
InputScript::default() script()
.char('j') .char('j')
.char('l') .char('l')
.run(&mut ws) .run(&mut ws)
@ -653,7 +657,7 @@ macro_rules! assert_copy_paste {
.edit_current_cell($source) .edit_current_cell($source)
.expect("Failed to edit cell"); .expect("Failed to edit cell");
ws.book.evaluate(); ws.book.evaluate();
InputScript::default() script()
.event($c) .event($c)
.char('l') .char('l')
.char('j') .char('j')
@ -719,7 +723,7 @@ fn test_clear_cell() {
.get_current_cell_contents() .get_current_cell_contents()
.expect("failed to get cell contents") .expect("failed to get cell contents")
); );
InputScript::default() script()
.char('d') .char('d')
.run(&mut ws) .run(&mut ws)
.expect("Failed to run input script"); .expect("Failed to run input script");
@ -744,7 +748,7 @@ fn test_clear_cell_all() {
.get_current_cell_contents() .get_current_cell_contents()
.expect("failed to get cell contents") .expect("failed to get cell contents")
); );
InputScript::default() script()
.char('D') .char('D')
.run(&mut ws) .run(&mut ws)
.expect("Failed to run input script"); .expect("Failed to run input script");
@ -768,7 +772,7 @@ fn test_sheet_navigation() {
ws.book ws.book
.new_sheet(Some("sheet 4")) .new_sheet(Some("sheet 4"))
.expect("Failed to set sheet name"); .expect("Failed to set sheet name");
InputScript::default() script()
.ctrl('n') .ctrl('n')
.ctrl('n') .ctrl('n')
.run(&mut ws) .run(&mut ws)
@ -777,7 +781,7 @@ fn test_sheet_navigation() {
"sheet 3", "sheet 3",
ws.book.get_sheet_name().expect("Failed to get sheet name") ws.book.get_sheet_name().expect("Failed to get sheet name")
); );
InputScript::default() script()
.ctrl('p') .ctrl('p')
.run(&mut ws) .run(&mut ws)
.expect("Failed to run input script"); .expect("Failed to run input script");
@ -790,7 +794,7 @@ fn test_sheet_navigation() {
#[test] #[test]
fn test_sheet_column_sizing() { fn test_sheet_column_sizing() {
let mut ws = new_workspace(); let mut ws = new_workspace();
InputScript::default() script()
.char('3') .char('3')
.ctrl('l') .ctrl('l')
.run(&mut ws) .run(&mut ws)
@ -799,7 +803,7 @@ fn test_sheet_column_sizing() {
28, 28,
ws.book.get_col_size(1).expect("Failed to get column size") ws.book.get_col_size(1).expect("Failed to get column size")
); );
InputScript::default() script()
.char('1') .char('1')
.ctrl('h') .ctrl('h')
.run(&mut ws) .run(&mut ws)
@ -814,7 +818,7 @@ fn test_sheet_column_sizing() {
fn test_quit() { fn test_quit() {
let mut ws = let mut ws =
Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook"); Workspace::new_empty("en", "America/New_York").expect("Failed to get empty workbook");
let result = InputScript::default() let result = script()
.char('q') .char('q')
.run(&mut ws) .run(&mut ws)
.expect("Failed to run input script"); .expect("Failed to run input script");
@ -834,7 +838,7 @@ fn test_cell_replace() {
.expect("failed to get cell contents") .expect("failed to get cell contents")
.as_str() .as_str()
); );
InputScript::default() script()
.char('s') .char('s')
.char('b') .char('b')
.char('a') .char('a')
@ -855,7 +859,7 @@ macro_rules! assert_command_finish {
($script : expr) => { ($script : expr) => {
let mut ws = new_workspace(); let mut ws = new_workspace();
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.char(':') .char(':')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle ':' key"); .expect("Failed to handle ':' key");
@ -867,12 +871,12 @@ macro_rules! assert_command_finish {
#[test] #[test]
fn test_command_mode_esc() { fn test_command_mode_esc() {
assert_command_finish!(InputScript::default().esc()); assert_command_finish!(script().esc());
} }
#[test] #[test]
fn test_command_mode_enter() { fn test_command_mode_enter() {
assert_command_finish!(InputScript::default().enter()); assert_command_finish!(script().enter());
} }
#[test] #[test]
@ -882,7 +886,7 @@ fn test_edit_mode_paste() {
ws.state.range_select.start = Some(Address { row: 1, col: 1 }); ws.state.range_select.start = Some(Address { row: 1, col: 1 });
ws.state.range_select.end = Some(Address { row: 2, col: 2 }); ws.state.range_select.end = Some(Address { row: 2, col: 2 });
dbg!(ws.selected_range_to_string()); dbg!(ws.selected_range_to_string());
InputScript::default() script()
.char('e') .char('e')
.ctrl('p') .ctrl('p')
.run(&mut ws) .run(&mut ws)
@ -895,30 +899,30 @@ fn test_edit_mode_paste() {
fn test_range_select_esc() { fn test_range_select_esc() {
let mut ws = new_workspace(); let mut ws = new_workspace();
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.char('v') .char('v')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle script"); .expect("Failed to handle script");
assert_eq!(Some(&Modality::RangeSelect), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::RangeSelect), ws.state.modality_stack.last());
InputScript::default() script()
.esc() .esc()
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle script"); .expect("Failed to handle script");
assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::Navigate), ws.state.modality_stack.last());
InputScript::default() script()
.char('v') .char('v')
.chars("123") .chars("123")
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle script"); .expect("Failed to handle script");
assert_eq!(Some(&Modality::RangeSelect), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::RangeSelect), ws.state.modality_stack.last());
assert_eq!(3, ws.state.numeric_prefix.len()); assert_eq!(3, ws.state.numeric_prefix.len());
InputScript::default() script()
.esc() .esc()
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle script"); .expect("Failed to handle script");
assert_eq!(Some(&Modality::RangeSelect), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::RangeSelect), ws.state.modality_stack.last());
assert_eq!(0, ws.state.numeric_prefix.len()); assert_eq!(0, ws.state.numeric_prefix.len());
InputScript::default() script()
.esc() .esc()
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle script"); .expect("Failed to handle script");
@ -949,7 +953,7 @@ macro_rules! assert_range_clear {
.get_cell_addr_contents(&second_corner) .get_cell_addr_contents(&second_corner)
.expect("failed to get cell contents") .expect("failed to get cell contents")
); );
InputScript::default() script()
.char('v') .char('v')
.run(&mut ws) .run(&mut ws)
.expect("Failed to handle script"); .expect("Failed to handle script");
@ -973,7 +977,7 @@ macro_rules! assert_range_clear {
#[test] #[test]
fn test_range_select_clear_upper_d() { fn test_range_select_clear_upper_d() {
assert_range_clear!(InputScript::default() assert_range_clear!(script()
.char('j') .char('j')
.char('l') .char('l')
.char('D')); .char('D'));
@ -984,10 +988,10 @@ fn test_range_select_movement() {
let mut ws = new_workspace(); let mut ws = new_workspace();
ws.book.new_sheet(Some("s2")).expect("Unable create s2 sheet"); ws.book.new_sheet(Some("s2")).expect("Unable create s2 sheet");
ws.book.new_sheet(Some("s3")).expect("Unable create s3 sheet"); ws.book.new_sheet(Some("s3")).expect("Unable create s3 sheet");
InputScript::default().ctrl('r').run(&mut ws) script().ctrl('r').run(&mut ws)
.expect("failed to run script"); .expect("failed to run script");
assert_eq!(Some(&Modality::RangeSelect), ws.state.modality_stack.last()); assert_eq!(Some(&Modality::RangeSelect), ws.state.modality_stack.last());
InputScript::default() script()
.char('3') .char('3')
.char('j') .char('j')
.char('3') .char('3')
@ -1000,12 +1004,12 @@ fn test_range_select_movement() {
.expect("failed to run script"); .expect("failed to run script");
assert_eq!(&Address { row: 3, col: 3 }, &ws.book.location); assert_eq!(&Address { row: 3, col: 3 }, &ws.book.location);
assert_eq!(0, ws.book.current_sheet); assert_eq!(0, ws.book.current_sheet);
InputScript::default() script()
.ctrl('n') .ctrl('n')
.run(&mut ws) .run(&mut ws)
.expect("Unable to run script"); .expect("Unable to run script");
assert_eq!(1, ws.book.current_sheet); assert_eq!(1, ws.book.current_sheet);
InputScript::default() script()
.ctrl('p') .ctrl('p')
.run(&mut ws) .run(&mut ws)
.expect("Unable to run script"); .expect("Unable to run script");
@ -1014,7 +1018,7 @@ fn test_range_select_movement() {
#[test] #[test]
fn test_range_select_clear_lower_d() { fn test_range_select_clear_lower_d() {
assert_range_clear!(InputScript::default() assert_range_clear!(script()
.char('j') .char('j')
.char('l') .char('l')
.char('d')); .char('d'));
@ -1028,7 +1032,7 @@ macro_rules! assert_range_copy {
ws.book.update_cell(&top_left_addr, "top_left").expect("Failed to update top left"); ws.book.update_cell(&top_left_addr, "top_left").expect("Failed to update top left");
ws.book.update_cell(&bot_right_addr, "bot_right").expect("Failed to update top left"); ws.book.update_cell(&bot_right_addr, "bot_right").expect("Failed to update top left");
assert!(ws.state.clipboard.is_none()); assert!(ws.state.clipboard.is_none());
InputScript::default() script()
.ctrl('r') .ctrl('r')
.char('j') .char('j')
.char('l') .char('l')
@ -1036,7 +1040,7 @@ macro_rules! assert_range_copy {
.run(&mut ws) .run(&mut ws)
.expect("failed to run script"); .expect("failed to run script");
assert_eq!(&top_left_addr, ws.state.range_select.start.as_ref().expect("Didn't find a start of range")); assert_eq!(&top_left_addr, ws.state.range_select.start.as_ref().expect("Didn't find a start of range"));
InputScript::default() script()
.char('2') .char('2')
.char('j') .char('j')
.char('2') .char('2')
@ -1069,22 +1073,22 @@ macro_rules! assert_range_copy {
#[test] #[test]
fn test_range_select_copy_c() { fn test_range_select_copy_c() {
assert_range_copy!(InputScript::default().ctrl('c')); assert_range_copy!(script().ctrl('c'));
} }
#[test] #[test]
fn test_range_select_copy_y() { fn test_range_select_copy_y() {
assert_range_copy!(InputScript::default().char('y')); assert_range_copy!(script().char('y'));
} }
#[test] #[test]
fn test_range_select_copy_capital_y() { fn test_range_select_copy_capital_y() {
assert_range_copy!(InputScript::default().char('Y')); assert_range_copy!(script().char('Y'));
} }
#[test] #[test]
fn test_range_select_copy_capital_c() { fn test_range_select_copy_capital_c() {
assert_range_copy!(InputScript::default().ctrl('C')); assert_range_copy!(script().ctrl('C'));
} }
#[test] #[test]
@ -1092,7 +1096,7 @@ fn test_extend_to_range() {
let mut ws = new_workspace(); let mut ws = new_workspace();
ws.book.edit_current_cell("=B1+1").expect("Failed to edit cell"); ws.book.edit_current_cell("=B1+1").expect("Failed to edit cell");
ws.book.evaluate(); ws.book.evaluate();
InputScript::default() script()
.char('v') .char('v')
.char('j') .char('j')
.char('x') .char('x')