From 69dff0c26c50c4fc8669bd9f072d3a2153816120 Mon Sep 17 00:00:00 2001 From: vasilito Date: Tue, 7 Jul 2026 12:50:00 +0300 Subject: [PATCH] W52: Tests for editor MarkAll, Close, BlockSave, InsertFile Add 4 unit tests covering the new W50 editor commands: - mark_all_selects_entire_buffer: verify selection covers the full buffer (start=0, end=buffer.len()) - close_clean_buffer_reopens_empty: verify Close on an unmodified buffer resets to an empty buffer - block_save_on_no_selection_shows_message: verify the "No selection" message when nothing is selected - insert_file_opens_insert_file_prompt: verify the mode switches to InsertFile prompt Tests: 1415 pass (was 1411), zero warnings. --- .../recipes/tui/tlc/source/src/editor/mod.rs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/local/recipes/tui/tlc/source/src/editor/mod.rs b/local/recipes/tui/tlc/source/src/editor/mod.rs index 3bea5c047f..126e2136d3 100644 --- a/local/recipes/tui/tlc/source/src/editor/mod.rs +++ b/local/recipes/tui/tlc/source/src/editor/mod.rs @@ -3873,5 +3873,45 @@ mod tests { e.push_goto_history(20); assert_eq!(e.goto_history, vec![10, 20]); } + + #[test] + fn mark_all_selects_entire_buffer() { + let mut e = make_empty(); + e.insert_str("hello world"); + // Dispatch MarkAll via the dispatcher. + let _ = e.dispatch_editor_cmd(crate::editor::menubar::EditorCmd::MarkAll); + let sel = e.cursor.selection(); + assert!(sel.is_some()); + let (start, end) = sel.unwrap(); + assert_eq!(start, 0); + assert_eq!(end, e.buffer.len()); + } + + #[test] + fn close_clean_buffer_reopens_empty() { + let mut e = make_empty(); + e.insert_str("hello"); + e.modified = false; + let _ = e.dispatch_editor_cmd(crate::editor::menubar::EditorCmd::Close); + // Should have reopened as an empty buffer. + assert_eq!(e.buffer.len(), 0); + assert!(!e.modified); + } + + #[test] + fn block_save_on_no_selection_shows_message() { + let mut e = make_empty(); + e.insert_str("hello"); + e.cursor.clear_selection(); + let _ = e.dispatch_editor_cmd(crate::editor::menubar::EditorCmd::BlockSave); + assert_eq!(e.message, Some("No selection".to_string())); + } + + #[test] + fn insert_file_opens_insert_file_prompt() { + let mut e = make_empty(); + let _ = e.dispatch_editor_cmd(crate::editor::menubar::EditorCmd::InsertFile); + assert!(e.mode.is_prompt()); + } }