Skip to content

Commit b51e5d7

Browse files
committed
a few more tests
1 parent 23d2eef commit b51e5d7

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/edit_mode/vi/mod.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ mod test {
268268
#[allow(non_snake_case)]
269269
mod integration {
270270
use super::*;
271-
use crate::{Editor, ReedlineEvent, UndoBehavior};
271+
use crate::{Reedline, ReedlineEvent};
272272
use pretty_assertions::assert_eq;
273273
use rstest::rstest;
274274

@@ -279,7 +279,7 @@ mod test {
279279
ReedlineEvent::Multiple(events) => {
280280
events.into_iter().flat_map(unwrap_edits).collect()
281281
}
282-
other => panic!("unexpected event ${other}"),
282+
other => panic!("unexpected event {other:#?}"),
283283
}
284284
}
285285

@@ -292,9 +292,16 @@ mod test {
292292
"^", "dw", "P", "P", "b",
293293
// run the actual test, and it should put us back where we started.
294294
"dw", "dw", "P"])]
295-
#[case::edit_ddu(&["dd", "u"])]
295+
#[case::edit_dd_u(&["dd", "u"])]
296+
// not actually a no-op because it adds a newline, but we .trim_end()
297+
#[case::edit_dd_p(&["dd", "p"])]
298+
#[case::edit_dd_P_uu(&["dd", "P", "u", "u"])]
299+
// FIXME: this happens on the second line, so doesn't actually delete two lines
300+
// I can't work out how to use "k" to go to the line above because it generates an
301+
// UntilFound([MenuUp, Up]) event, and I'm not sure how to handle that.
302+
#[case::edit_d2d_p(&["d2d", "p"])]
296303
fn sum_to_zero(#[case] commands: &[&str]) {
297-
let initial_input = "the quick brown fox jumps over the lazy dog";
304+
let initial_input = "the quick brown fox\njumps over the lazy dog";
298305
let keybindings = default_vi_normal_keybindings();
299306
let mut vi = Vi {
300307
insert_keybindings: default_vi_insert_keybindings(),
@@ -303,21 +310,18 @@ mod test {
303310
..Default::default()
304311
};
305312

306-
let mut editor = Editor::default();
307-
editor.set_buffer(initial_input.to_string(), UndoBehavior::CreateUndoPoint);
313+
let mut reedline = Reedline::create();
314+
reedline.run_edit_commands(&[EditCommand::InsertString(initial_input.into())]);
308315

309316
for command in commands {
310317
let command: Vec<char> = command.chars().collect();
311318
let parsed = parse(&mut command.iter().peekable());
312319
let commands = unwrap_edits(parsed.to_reedline_event(&mut vi));
313-
// FIXME: use run_edit_commands() instead
314-
for command in commands {
315-
editor.run_edit_command(&command)
316-
}
320+
321+
reedline.run_edit_commands(&commands)
317322
}
318323

319-
// FIXME: use Engine::current_buffer_contents()
320-
assert_eq!(initial_input, editor.get_buffer());
324+
assert_eq!(initial_input, reedline.current_buffer_contents().trim_end());
321325
}
322326
}
323327
}

0 commit comments

Comments
 (0)