use super::*;
#[test]
fn window_edit_is_visible_and_drainable_through_slot_handle() {
use hjkl_buffer::{Edit, Position};
let mut app = App::new(None, false, None, None).unwrap();
seed_buffer(&mut app, "hello\nworld");
let _ = app.slots()[0].take_dirty();
let _ = app.slots()[0].take_content_edits();
let _ = app.slots()[0].take_content_reset();
app.active_editor_mut().mutate_edit(Edit::InsertStr {
at: Position::new(0, 0),
text: "X".to_string(),
});
assert_eq!(
app.slots()[0].buffer().as_string(),
"Xhello\nworld",
"edit via the window editor must be visible through the slot handle"
);
assert_eq!(
app.active_editor().buffer().as_string(),
app.slots()[0].buffer().as_string(),
"window editor and slot handle must agree — they share one Buffer"
);
assert!(
app.slots()[0].take_dirty(),
"slot handle's take_dirty must see the window editor's edit"
);
assert!(
!app.slots()[0].take_dirty(),
"take_dirty is a one-shot drain — a second call must return false"
);
let edits = app.slots()[0].take_content_edits();
assert!(
!edits.is_empty(),
"slot handle's take_content_edits must see the window editor's edit"
);
assert!(
app.slots()[0].take_content_edits().is_empty(),
"take_content_edits is a one-shot drain — a second call must be empty"
);
}
#[test]
fn slot_handle_edit_is_visible_through_window_editor() {
use hjkl_engine::BufferEdit;
let mut app = App::new(None, false, None, None).unwrap();
seed_buffer(&mut app, "before");
BufferEdit::replace_all(app.slots_mut()[0].buffer_mut(), "after");
assert_eq!(
app.active_editor().buffer().as_string(),
"after",
"an edit made through the slot handle must be visible through the \
focused window's editor (same shared Buffer)"
);
app.slots_mut()[0]
.buffer_mut()
.set_pending_content_reset(true);
assert!(
app.slots()[0].take_content_reset(),
"content-reset signalled via the slot handle must drain as true"
);
assert!(
!app.slots()[0].take_content_reset(),
"take_content_reset is a one-shot drain — a second call must be false"
);
}