use crate::ansi_processor::AnsiProcessor;
#[test]
fn test_clear_screen_detection() {
let mut processor = AnsiProcessor::new();
assert!(!processor.should_replace_content());
assert!(!processor.detect_full_screen_program());
processor.process_string("\x1b[2J");
assert!(processor.should_replace_content());
assert!(processor.detect_full_screen_program());
assert!(processor.use_screen_buffer);
}
#[test]
fn test_cursor_home_detection() {
let mut processor = AnsiProcessor::new();
assert!(!processor.should_replace_content());
processor.process_string("\x1b[1;1H");
assert!(processor.should_replace_content());
assert!(processor.terminal_state.full_screen_program_detected);
}
#[test]
fn test_alternate_screen_detection() {
let mut processor = AnsiProcessor::new();
assert!(!processor.alternate_screen_mode);
assert!(!processor.should_replace_content());
processor.process_string("\x1b[?1049h");
assert!(processor.alternate_screen_mode);
assert!(processor.should_replace_content());
assert!(processor.terminal_state.full_screen_program_detected);
}
#[test]
fn test_line_based_program() {
let mut processor = AnsiProcessor::new();
processor.process_string("Line 1\nLine 2\nLine 3\n");
assert!(!processor.should_replace_content());
assert!(!processor.terminal_state.full_screen_program_detected);
assert!(!processor.use_screen_buffer);
assert_eq!(processor.get_processed_text(), "Line 1\nLine 2\nLine 3\n");
}
#[test]
fn test_screen_content_vs_processed_text() {
let mut processor = AnsiProcessor::with_screen_size(10, 5);
processor.process_string("\x1b[2J\x1b[1;1HTop\x1b[3;1HMiddle\x1b[5;1HBottom");
assert!(processor.should_replace_content());
let screen_content = processor.get_screen_content();
assert!(screen_content.contains("Top"));
assert!(screen_content.contains("Middle"));
assert!(screen_content.contains("Bottom"));
let lines: Vec<&str> = screen_content.lines().collect();
assert_eq!(lines[0].trim(), "Top"); assert_eq!(lines[2].trim(), "Middle"); assert_eq!(lines[4].trim(), "Bottom"); }