use super::*;
#[test]
fn paste_dismisses_open_completion_popup() {
let mut app = App::new(None, false, None, None).unwrap();
seed_buffer(&mut app, "fn foo");
hjkl_vim_tui::handle_key(app.active_editor_mut(), key(KeyCode::Char('i')));
app.sync_after_engine_mutation();
assert_eq!(app.active_editor().vim_mode(), VimMode::Insert);
let items = vec![make_completion_item("hello"), make_completion_item("world")];
app.completion = Some(crate::completion::Completion::new(0, 0, items));
assert!(app.completion.is_some(), "precondition: popup must be open");
app.handle_paste("pasted text".to_string());
assert!(
app.completion.is_none(),
"paste must dismiss the open completion popup"
);
let line = hjkl_buffer::rope_line_str(&app.active_editor().buffer().rope(), 0);
assert!(
line.contains("pasted text"),
"paste must still insert the text, got: {line:?}"
);
}
#[test]
fn paste_with_no_popup_open_is_unaffected() {
let mut app = App::new(None, false, None, None).unwrap();
seed_buffer(&mut app, "");
hjkl_vim_tui::handle_key(app.active_editor_mut(), key(KeyCode::Char('i')));
app.sync_after_engine_mutation();
app.handle_paste("hi".to_string());
assert!(app.completion.is_none());
let line = hjkl_buffer::rope_line_str(&app.active_editor().buffer().rope(), 0);
assert_eq!(line, "hi");
}
#[test]
fn record_macro_with_paste_replays_the_paste() {
let mut app = App::new(None, false, None, None).unwrap();
seed_buffer(&mut app, "line0\nline1\nline2");
app.active_editor_mut().jump_cursor(0, 0);
app.sync_viewport_from_editor();
macro_key_seq(&mut app, &[ck('q'), ck('a')]);
assert!(app.active_editor().is_recording_macro());
macro_key_seq(&mut app, &[ck('i')]);
assert_eq!(app.active_editor().vim_mode(), VimMode::Insert);
app.handle_paste("XX".to_string());
macro_key_seq(&mut app, &[key(KeyCode::Esc), ck('j'), ck('0'), ck('q')]);
assert!(
!app.active_editor().is_recording_macro(),
"recording must stop after the second q"
);
assert_eq!(
hjkl_buffer::rope_line_str(&app.active_editor().buffer().rope(), 0),
"XXline0",
"recording itself must apply the paste"
);
assert_eq!(app.active_editor().cursor(), (1, 0));
macro_key_seq(&mut app, &[ck('@'), ck('a')]);
assert!(!app.active_editor().is_replaying_macro());
assert_eq!(
hjkl_buffer::rope_line_str(&app.active_editor().buffer().rope(), 1),
"XXline1",
"@a replay must reproduce the paste that happened during recording"
);
}
#[test]
fn paste_outside_recording_does_not_start_a_recording() {
let mut app = App::new(None, false, None, None).unwrap();
seed_buffer(&mut app, "");
hjkl_vim_tui::handle_key(app.active_editor_mut(), key(KeyCode::Char('i')));
app.sync_after_engine_mutation();
app.handle_paste("hi".to_string());
assert!(!app.active_editor().is_recording_macro());
}