use {
super::*,
crate::api::{BufferApi, ModeApi},
};
#[test]
fn test_new_creates_valid_runtime() {
let mut test = TestSessionRuntime::new();
let _runtime = test.runtime();
test.assert_mode_name("normal");
test.assert_mode_depth(1);
}
#[test]
fn test_with_buffer_creates_buffer_and_window() {
let test = TestSessionRuntime::with_buffer("hello world");
test.assert_buffer_content("hello world");
test.assert_window_count(1);
}
#[test]
fn test_mode_operations() {
let mut test = TestSessionRuntime::new();
let insert_mode = ModeId::new(ModuleId::new("test"), "insert");
test.with_runtime(|runtime| {
runtime.push_mode(insert_mode.clone(), crate::TransitionContext::new());
});
test.assert_mode(&insert_mode);
test.assert_mode_name("insert");
test.assert_mode_depth(2);
let changes = test.take_changes();
assert!(changes.mode_changed);
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[test]
fn test_buffer_operations() {
use crate::api::BufferApi;
let mut test = TestSessionRuntime::with_buffer("hello");
test.with_runtime(|runtime| {
if let Some(buffer_id) = runtime.active_buffer() {
runtime.insert_text(buffer_id, Position::new(0, 5), " world");
}
});
test.assert_buffer_content("hello world");
let changes = test.take_changes();
assert!(changes.buffer_modified);
}
#[test]
fn test_cursor_operations() {
let mut test = TestSessionRuntime::with_buffer("hello\nworld");
test.assert_cursor(0, 0);
test.windows.active_mut().unwrap().cursor = crate::CursorPosition::new(1, 3);
test.assert_cursor(1, 3);
}
#[test]
fn test_with_home_mode() {
let custom_mode = ModeId::new(ModuleId::new("custom"), "special");
let test = TestSessionRuntime::with_home_mode(custom_mode.clone());
test.assert_mode(&custom_mode);
}
#[test]
fn test_cursor_position_via_window() {
let mut test = TestSessionRuntime::with_buffer("hello\nworld");
let _buffer_id = test.active_buffer().expect("should have active buffer");
let window = test.windows.active().expect("should have active window");
assert_eq!((window.cursor.line, window.cursor.column), (0, 0));
test.windows.active_mut().unwrap().cursor = crate::CursorPosition::new(1, 3);
let window = test.windows.active().expect("should have active window");
assert_eq!((window.cursor.line, window.cursor.column), (1, 3));
let mut layout = crate::WindowLayout::empty();
layout.add(crate::Window::new()); assert!(layout.active().is_some()); assert_eq!(layout.active().unwrap().buffer_id, None); }
#[test]
fn test_buffer_line_len_api() {
use crate::api::BufferApi;
let mut test = TestSessionRuntime::with_buffer("hello\nworld!");
let buffer_id = test.active_buffer().expect("should have active buffer");
test.with_runtime(|runtime| {
assert_eq!(runtime.buffer_line_len(buffer_id, 0), Some(5)); assert_eq!(runtime.buffer_line_len(buffer_id, 1), Some(6));
assert!(runtime.buffer_line_len(buffer_id, 99).is_none());
let fake_id = BufferId::new();
assert!(runtime.buffer_line_len(fake_id, 0).is_none());
});
}
#[test]
fn test_register_api() {
use crate::api::{RegisterApi, RegisterContent};
let mut test = TestSessionRuntime::new();
test.with_runtime(|runtime| {
assert!(runtime.get_register(Some('z')).is_none());
runtime.set_register(None, RegisterContent::characterwise("hello"));
let content = runtime.get_register(None).expect("should have content");
assert_eq!(content.text, "hello");
assert!(content.is_characterwise());
runtime.set_register(Some('a'), RegisterContent::linewise("world\n"));
let content = runtime
.get_register(Some('a'))
.expect("should have content");
assert_eq!(content.text, "world\n");
assert!(content.is_linewise());
runtime.set_register(None, RegisterContent::linewise("replaced\n"));
let content = runtime.get_register(None).expect("should have content");
assert_eq!(content.text, "replaced\n");
assert!(content.is_linewise());
assert_eq!(runtime.get_register(Some('a')).unwrap().text, "world\n");
});
}
#[test]
fn test_assert_mode() {
let mode = ModeId::new(ModuleId::new("test"), "normal");
let test = TestSessionRuntime::new();
test.assert_mode(&mode); }
#[test]
fn test_assert_mode_name() {
let test = TestSessionRuntime::new();
test.assert_mode_name("normal"); }
#[test]
fn test_assert_mode_depth() {
let test = TestSessionRuntime::new();
test.assert_mode_depth(1); }
#[test]
fn test_assert_window_count_empty() {
let test = TestSessionRuntime::new();
test.assert_window_count(0); }
#[test]
fn test_assert_window_count_with_buffer() {
let test = TestSessionRuntime::with_buffer("hello");
test.assert_window_count(1);
}
#[test]
fn test_assert_line_count() {
let test = TestSessionRuntime::with_buffer("line1\nline2\nline3");
test.assert_line_count(3);
}
#[test]
fn test_assert_buffer_content() {
let test = TestSessionRuntime::with_buffer("hello world");
test.assert_buffer_content("hello world");
}
#[test]
fn test_assert_cursor_default() {
let test = TestSessionRuntime::with_buffer("hello");
test.assert_cursor(0, 0);
}
#[test]
fn test_current_mode_getter() {
let test = TestSessionRuntime::new();
assert_eq!(test.current_mode().name(), "normal");
}
#[test]
fn test_active_buffer_getter() {
let test = TestSessionRuntime::with_buffer("test");
assert!(test.active_buffer().is_some());
}
#[test]
fn test_active_buffer_none_when_no_buffer() {
let test = TestSessionRuntime::new();
assert!(test.active_buffer().is_none());
}
#[test]
fn test_cursor_position_getter() {
let test = TestSessionRuntime::with_buffer("hello");
assert_eq!(test.cursor_position(), Some(Position::new(0, 0)));
}
#[test]
fn test_cursor_position_none_when_no_window() {
let test = TestSessionRuntime::new();
assert!(test.cursor_position().is_none());
}
#[test]
fn test_buffer_content_getter() {
let test = TestSessionRuntime::with_buffer("hello world");
assert_eq!(test.buffer_content(), Some("hello world".to_string()));
}
#[test]
fn test_buffer_content_none_when_no_buffer() {
let test = TestSessionRuntime::new();
assert!(test.buffer_content().is_none());
}
#[test]
fn test_kernel_getter() {
let test = TestSessionRuntime::new();
let _kernel = test.kernel(); }
#[test]
fn test_session_getter() {
let test = TestSessionRuntime::new();
let session = test.session();
assert_eq!(session.id.as_usize(), 1);
}
#[test]
fn test_changes_getter() {
let test = TestSessionRuntime::new();
let changes = test.changes();
assert!(!changes.has_changes());
}
#[test]
fn test_take_changes_resets() {
let mut test = TestSessionRuntime::new();
let insert_mode = ModeId::new(ModuleId::new("test"), "insert");
test.with_runtime(|runtime| {
runtime.push_mode(insert_mode, crate::TransitionContext::new());
});
assert!(test.changes().mode_changed);
let changes = test.take_changes();
assert!(changes.mode_changed);
assert!(!test.changes().has_changes());
}
#[test]
fn test_runtime_method() {
let mut test = TestSessionRuntime::new();
let runtime = test.runtime();
assert_eq!(runtime.current_mode().name(), "normal");
}
#[test]
fn test_with_runtime_returns_value() {
let mut test = TestSessionRuntime::with_buffer("hello");
let line_count = test.with_runtime(|runtime| {
let buf = runtime.active_buffer().unwrap();
runtime.buffer_line_count(buf).unwrap()
});
assert_eq!(line_count, 1);
}
#[test]
fn test_default_impl() {
let test = TestSessionRuntime::default();
test.assert_mode_name("normal");
test.assert_mode_depth(1);
}
#[test]
fn test_buffer_manager_create() {
let test = TestSessionRuntime::new();
let mut test = test;
let buf_id = test.with_runtime(|runtime| {
use crate::api::BufferApi;
runtime.create_buffer(None, "test content")
});
let content = test.with_runtime(|runtime| {
use crate::api::BufferApi;
runtime.buffer_content(buf_id)
});
assert_eq!(content, Some("test content".to_string()));
}
#[test]
fn test_buffer_manager_list() {
let mut test = TestSessionRuntime::new();
test.with_runtime(|runtime| {
use crate::api::BufferApi;
runtime.create_buffer(None, "buf1");
runtime.create_buffer(None, "buf2");
});
let count = test.kernel().buffers.count();
assert!(count >= 2);
}
#[test]
fn test_with_home_mode_custom() {
let custom = ModeId::new(ModuleId::new("custom"), "special-mode");
let test = TestSessionRuntime::with_home_mode(custom.clone());
test.assert_mode(&custom);
test.assert_mode_name("special-mode");
}