use crate::action::Action;
use crate::editor::{Editor, Mode};
#[allow(async_fn_in_trait)]
pub trait EditorTestExt {
fn test_cursor_position(&self) -> (usize, usize);
fn test_mode(&self) -> Mode;
async fn test_execute_action(&mut self, action: Action) -> anyhow::Result<()>;
fn test_buffer_contents(&self) -> String;
fn test_line_contents(&self, line: usize) -> Option<String>;
fn test_line_count(&self) -> usize;
fn test_is_insert(&self) -> bool;
fn test_is_normal(&self) -> bool;
fn test_is_visual(&self) -> bool;
fn test_viewport_top(&self) -> usize;
async fn test_type_text(&mut self, text: &str) -> anyhow::Result<()>;
fn test_current_line(&self) -> Option<String>;
}
impl EditorTestExt for Editor {
fn test_cursor_position(&self) -> (usize, usize) {
(self.test_cursor_x(), self.test_buffer_line())
}
fn test_mode(&self) -> Mode {
self.test_mode()
}
async fn test_execute_action(&mut self, action: Action) -> anyhow::Result<()> {
self.apply_action_core(&action)?;
Ok(())
}
fn test_buffer_contents(&self) -> String {
self.test_current_buffer().contents()
}
fn test_line_contents(&self, line: usize) -> Option<String> {
self.test_current_buffer().get(line)
}
fn test_line_count(&self) -> usize {
self.test_current_buffer().len()
}
fn test_is_insert(&self) -> bool {
self.test_is_insert()
}
fn test_is_normal(&self) -> bool {
self.test_is_normal()
}
fn test_is_visual(&self) -> bool {
matches!(self.test_mode(), Mode::Visual)
}
fn test_viewport_top(&self) -> usize {
self.test_vtop()
}
async fn test_type_text(&mut self, text: &str) -> anyhow::Result<()> {
if !self.test_is_insert() {
self.test_execute_action(Action::EnterMode(Mode::Insert))
.await?;
}
for ch in text.chars() {
self.test_execute_action(Action::InsertCharAtCursor(ch))
.await?;
}
Ok(())
}
fn test_current_line(&self) -> Option<String> {
self.test_current_line_contents()
}
}