use revue::widget::form::rich_text_editor::RichTextEditor;
use revue::widget::form::rich_text_editor::undo::MAX_UNDO_HISTORY;
#[test]
fn test_max_undo_history_value() {
assert_eq!(MAX_UNDO_HISTORY, 100);
}
#[test]
fn test_undo_empty() {
let mut editor = RichTextEditor::new();
editor.undo();
assert_eq!(editor.get_content(), "");
}
#[test]
fn test_undo_insert_char() {
let mut editor = RichTextEditor::new();
editor.insert_char('a');
editor.insert_char('b');
assert_eq!(editor.get_content(), "ab");
editor.undo();
assert_eq!(editor.get_content(), "a");
}
#[test]
fn test_undo_multiple() {
let mut editor = RichTextEditor::new();
editor.insert_str("hello");
editor.undo();
editor.undo();
editor.undo();
editor.undo();
editor.undo();
assert_eq!(editor.get_content(), "");
}
#[test]
fn test_undo_then_redo() {
let mut editor = RichTextEditor::new();
editor.insert_str("hi");
editor.undo();
assert_eq!(editor.get_content(), "h");
editor.redo();
assert_eq!(editor.get_content(), "hi");
}
#[test]
fn test_undo_newline() {
let mut editor = RichTextEditor::new();
editor.insert_char('a');
editor.insert_char('\n');
editor.insert_char('b');
assert_eq!(editor.block_count(), 2);
editor.undo();
assert_eq!(editor.block_count(), 2);
}
#[test]
fn test_undo_delete_char_before() {
let mut editor = RichTextEditor::new().content("hello");
editor.move_end();
editor.delete_char_before();
assert_eq!(editor.get_content(), "hell");
editor.undo();
assert_eq!(editor.get_content(), "hello");
}
#[test]
fn test_undo_clears_redo() {
let mut editor = RichTextEditor::new();
editor.insert_str("ab");
editor.undo();
editor.insert_str("c");
editor.redo();
assert_eq!(editor.get_content(), "ac");
}
#[test]
fn test_redo_empty() {
let mut editor = RichTextEditor::new();
editor.redo();
assert_eq!(editor.get_content(), "");
}
#[test]
fn test_redo_after_undo() {
let mut editor = RichTextEditor::new();
editor.insert_str("test");
editor.undo();
editor.undo();
editor.undo();
editor.undo();
editor.redo();
assert_eq!(editor.get_content(), "t");
}
#[test]
fn test_redo_multiple() {
let mut editor = RichTextEditor::new();
editor.insert_str("hi");
editor.undo();
editor.undo();
editor.redo();
editor.redo();
assert_eq!(editor.get_content(), "hi");
}
#[test]
fn test_redo_newline() {
let mut editor = RichTextEditor::new();
editor.insert_char('a');
editor.insert_char('\n');
editor.undo();
assert_eq!(editor.block_count(), 1);
editor.redo();
assert_eq!(editor.block_count(), 2);
}
#[test]
fn test_redo_delete_char() {
let mut editor = RichTextEditor::new().content("ab");
editor.delete_char_at();
assert_eq!(editor.get_content(), "b");
editor.undo();
assert_eq!(editor.get_content(), "ab");
editor.redo();
assert_eq!(editor.get_content(), "b");
}
#[test]
fn test_undo_redo_undo_cycle() {
let mut editor = RichTextEditor::new();
editor.insert_str("xyz");
editor.undo();
editor.redo();
editor.undo();
assert_eq!(editor.get_content(), "xy");
}
#[test]
fn test_multiple_operations_undo_redo() {
let mut editor = RichTextEditor::new();
editor.insert_char('a');
editor.insert_char('b');
editor.insert_char('c');
editor.undo();
editor.redo();
editor.undo();
editor.undo();
editor.redo();
editor.redo();
assert_eq!(editor.get_content(), "abc");
}
#[test]
fn test_undo_history_limit() {
let mut editor = RichTextEditor::new();
for _ in 0..MAX_UNDO_HISTORY + 10 {
editor.insert_char('x');
}
editor.undo();
editor.undo();
}
#[test]
fn test_undo_with_cursor_position() {
let mut editor = RichTextEditor::new();
editor.insert_str("hello");
editor.undo();
let pos = editor.cursor_position();
assert_eq!(pos, (0, 4));
}
#[test]
fn test_redo_with_cursor_position() {
let mut editor = RichTextEditor::new();
editor.insert_str("hi");
editor.undo();
editor.redo();
let pos = editor.cursor_position();
assert_eq!(pos, (0, 2));
}