use super::*;
#[test]
fn insert_session_undoes_as_one_unit() {
let mut e = Editor::new(Buffer::from_text("hello\n"));
e.feed_text("A world"); e.feed(crate::editor::Key::Esc);
assert_eq!(e.buf().text().to_string(), "hello world\n");
e.feed_text("u");
assert_eq!(e.buf().text().to_string(), "hello\n");
e.feed(crate::editor::Key::CtrlR);
assert_eq!(e.buf().text().to_string(), "hello world\n");
}
#[test]
fn change_op_holds_one_undo_unit() {
let mut e = Editor::new(Buffer::from_text("say [old] now\n"));
e.feed_text("w"); e.feed_text("ci["); e.feed_text("new");
e.feed(crate::editor::Key::Esc);
assert_eq!(e.buf().text().to_string(), "say [new] now\n");
e.feed_text("u"); assert_eq!(e.buf().text().to_string(), "say [old] now\n");
}
#[test]
fn n_repeats_search_and_wraps() {
let mut e = Editor::new(Buffer::from_text("foo bar\nfoo baz\n"));
e.feed_text("/foo\r"); assert_eq!(e.head(), 8);
e.feed_text("n"); assert_eq!(e.head(), 0);
e.feed_text("N"); assert_eq!(e.head(), 8);
}
#[test]
fn edit_after_undo_forks_and_ctrlr_redoes_last_branch() {
let mut e = Editor::new(Buffer::from_text("ab\n"));
e.feed_text("rx"); e.feed_text("u");
e.feed_text("ry"); e.feed_text("u"); e.feed(crate::editor::Key::CtrlR); assert_eq!(e.buf().text().to_string(), "yb\n");
e.feed(crate::editor::Key::CtrlR);
assert_eq!(e.buf().text().to_string(), "yb\n");
}
#[test]
fn readonly_buffers_refuse_undo() {
let mut e = Editor::new(Buffer::from_text("x\n"));
e.buf_mut().readonly = true;
e.feed_text("u");
assert!(e.message.contains("readonly"));
assert_eq!(e.buf().text().to_string(), "x\n");
}