use par_term::terminal::TerminalManager;
#[test]
fn test_terminal_creation() {
let result = TerminalManager::new(80, 24);
assert!(result.is_ok());
let terminal = result.unwrap();
assert_eq!(terminal.dimensions(), (80, 24));
}
#[test]
fn test_terminal_custom_dimensions() {
let terminal = TerminalManager::new(100, 30).unwrap();
assert_eq!(terminal.dimensions(), (100, 30));
}
#[test]
#[ignore] fn test_terminal_spawn_shell() {
let mut terminal = TerminalManager::new(80, 24).unwrap();
let result = terminal.spawn_shell();
assert!(result.is_ok());
assert!(terminal.is_running());
}
#[test]
#[ignore] fn test_terminal_write_string() {
let mut terminal = TerminalManager::new(80, 24).unwrap();
terminal.spawn_shell().unwrap();
let result = terminal.write_str("Hello, world!");
assert!(result.is_ok());
}
#[test]
#[ignore] fn test_terminal_write_bytes() {
let mut terminal = TerminalManager::new(80, 24).unwrap();
terminal.spawn_shell().unwrap();
let result = terminal.write(b"Hello, world!");
assert!(result.is_ok());
}
#[test]
fn test_terminal_content() {
let terminal = TerminalManager::new(80, 24).unwrap();
let content = terminal.content().unwrap();
let _ = content.len();
}
#[test]
#[ignore] fn test_terminal_ansi_sequences() {
let mut terminal = TerminalManager::new(80, 24).unwrap();
terminal.spawn_shell().unwrap();
let result = terminal.write(b"\x1b[1;32mGreen\x1b[0m");
assert!(result.is_ok());
}
#[test]
fn test_terminal_resize() {
let mut terminal = TerminalManager::new(80, 24).unwrap();
assert_eq!(terminal.dimensions(), (80, 24));
let result = terminal.resize(100, 30);
assert!(result.is_ok());
assert_eq!(terminal.dimensions(), (100, 30));
}
#[test]
fn test_terminal_pty_running() {
let terminal = TerminalManager::new(80, 24).unwrap();
assert!(!terminal.is_running());
}
#[test]
fn test_terminal_scrollback() {
let terminal = TerminalManager::new(80, 24).unwrap();
let scrollback = terminal.scrollback();
let _ = scrollback.len();
}
#[test]
#[ignore] fn test_terminal_multiple_writes() {
let mut terminal = TerminalManager::new(80, 24).unwrap();
terminal.spawn_shell().unwrap();
terminal.write_str("Line 1\r\n").unwrap();
terminal.write_str("Line 2\r\n").unwrap();
terminal.write_str("Line 3\r\n").unwrap();
let content = terminal.content().unwrap();
assert!(!content.is_empty());
}
#[test]
#[ignore] fn test_terminal_control_characters() {
let mut terminal = TerminalManager::new(80, 24).unwrap();
terminal.spawn_shell().unwrap();
terminal.write(b"\r").unwrap(); terminal.write(b"\n").unwrap(); terminal.write(b"\t").unwrap(); terminal.write(b"\x1b").unwrap();
let result = terminal.content();
assert!(result.is_ok());
}
#[test]
fn test_terminal_large_dimensions() {
let result = TerminalManager::new(200, 100);
assert!(result.is_ok());
let terminal = result.unwrap();
assert_eq!(terminal.dimensions(), (200, 100));
}
#[test]
fn test_terminal_minimal_dimensions() {
let result = TerminalManager::new(10, 5);
assert!(result.is_ok());
let terminal = result.unwrap();
assert_eq!(terminal.dimensions(), (10, 5));
}
#[test]
fn test_cursor_style_default() {
let terminal = TerminalManager::new(80, 24).unwrap();
use par_term_emu_core_rust::cursor::CursorStyle;
assert_eq!(terminal.cursor_style(), CursorStyle::BlinkingBlock);
}
#[test]
fn test_cursor_style_set_directly() {
let mut terminal = TerminalManager::new(80, 24).unwrap();
use par_term_emu_core_rust::cursor::CursorStyle;
terminal.set_cursor_style(CursorStyle::SteadyBlock);
assert_eq!(terminal.cursor_style(), CursorStyle::SteadyBlock);
terminal.set_cursor_style(CursorStyle::BlinkingUnderline);
assert_eq!(terminal.cursor_style(), CursorStyle::BlinkingUnderline);
terminal.set_cursor_style(CursorStyle::SteadyBar);
assert_eq!(terminal.cursor_style(), CursorStyle::SteadyBar);
}
#[test]
fn test_decscusr_escape_sequences() {
let terminal = TerminalManager::new(80, 24).unwrap();
use par_term_emu_core_rust::cursor::CursorStyle;
let term_arc = terminal.terminal();
let mut term = term_arc.lock();
term.process(b"\x1b[0 q");
assert_eq!(term.cursor().style, CursorStyle::BlinkingBlock);
term.process(b"\x1b[1 q");
assert_eq!(term.cursor().style, CursorStyle::BlinkingBlock);
term.process(b"\x1b[2 q");
assert_eq!(term.cursor().style, CursorStyle::SteadyBlock);
term.process(b"\x1b[3 q");
assert_eq!(term.cursor().style, CursorStyle::BlinkingUnderline);
term.process(b"\x1b[4 q");
assert_eq!(term.cursor().style, CursorStyle::SteadyUnderline);
term.process(b"\x1b[5 q");
assert_eq!(term.cursor().style, CursorStyle::BlinkingBar);
term.process(b"\x1b[6 q");
assert_eq!(term.cursor().style, CursorStyle::SteadyBar);
term.process(b"\x1b[ q");
assert_eq!(term.cursor().style, CursorStyle::BlinkingBlock);
}
#[test]
fn test_cursor_style_is_blinking() {
use par_term_emu_core_rust::cursor::CursorStyle;
fn is_blinking(style: CursorStyle) -> bool {
matches!(
style,
CursorStyle::BlinkingBlock | CursorStyle::BlinkingUnderline | CursorStyle::BlinkingBar
)
}
assert!(is_blinking(CursorStyle::BlinkingBlock));
assert!(is_blinking(CursorStyle::BlinkingUnderline));
assert!(is_blinking(CursorStyle::BlinkingBar));
assert!(!is_blinking(CursorStyle::SteadyBlock));
assert!(!is_blinking(CursorStyle::SteadyUnderline));
assert!(!is_blinking(CursorStyle::SteadyBar));
}