#[allow(clippy::duplicate_mod)]
#[path = "fixtures/mod.rs"]
mod fixtures;
#[allow(clippy::duplicate_mod)]
#[path = "helpers.rs"]
mod helpers;
#[test]
#[cfg(not(feature = "authentication"))]
fn test_empty_command_does_nothing() {
let mut shell = helpers::create_test_shell();
shell.io_mut().clear_output();
helpers::press_enter(&mut shell);
let output = shell.io_mut().output();
helpers::assert_prompt(&output, "@/>");
helpers::assert_contains_none(&output, &["Error", "Command"]);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_backspace_sequence() {
let mut shell = helpers::create_test_shell();
helpers::type_input(&mut shell, "test");
shell.io_mut().clear_output();
helpers::press_backspace(&mut shell);
let output = shell.io_mut().output();
helpers::assert_contains_ansi(&output, "\x08"); helpers::assert_contains_ansi(&output, " "); helpers::assert_contains_ansi(&output, "\x08"); }
#[test]
#[cfg(not(feature = "authentication"))]
fn test_backspace_until_empty() {
let mut shell = helpers::create_test_shell();
helpers::type_input(&mut shell, "test");
helpers::press_backspace_n(&mut shell, 4);
shell.io_mut().clear_output();
helpers::press_enter(&mut shell);
let output = shell.io_mut().output();
helpers::assert_prompt(&output, "@/>");
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_backspace_at_start() {
let mut shell = helpers::create_test_shell();
shell.process_char('\x08').unwrap();
let output = helpers::execute_command(&mut shell, "echo ok");
assert!(output.contains("ok"));
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_backspace_boundary() {
let mut shell = helpers::create_test_shell();
helpers::type_input(&mut shell, "wrong");
for _ in 0..5 {
shell.process_char('\x08').unwrap();
}
shell.process_char('\x08').unwrap();
shell.process_char('\x08').unwrap();
let output = helpers::execute_command(&mut shell, "echo correct");
assert!(output.contains("correct"));
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_backspace_editing() {
let mut shell = helpers::create_test_shell();
helpers::type_input(&mut shell, "echox");
shell.process_char('\x08').unwrap(); helpers::type_input(&mut shell, " test");
shell.io_mut().clear_output();
shell.process_char('\n').unwrap();
let output = shell.io_mut().output();
assert!(output.contains("test"), "Backspace editing should work");
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_double_esc_clears_buffer() {
let mut shell = helpers::create_test_shell();
helpers::type_input(&mut shell, "echo test");
let output_before = shell.io_mut().output();
assert!(output_before.contains("echo test"));
shell.io_mut().clear_output();
shell.process_char('\x1b').unwrap();
shell.process_char('\x1b').unwrap();
let clear_output = shell.io_mut().output();
helpers::assert_contains_ansi(&clear_output, "\r");
helpers::assert_contains_ansi(&clear_output, "\x1b[K");
shell.io_mut().clear_output();
shell.process_char('\n').unwrap();
let output = shell.io_mut().output();
helpers::assert_contains_none(&output, &["test"]);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_double_esc_clears_and_shows_prompt() {
let mut shell = helpers::create_test_shell();
helpers::type_input(&mut shell, "some command");
shell.io_mut().clear_output();
helpers::press_double_esc(&mut shell);
let output = shell.io_mut().output();
helpers::assert_contains_ansi(&output, "\r"); helpers::assert_contains_ansi(&output, "\x1b[K"); helpers::assert_prompt(&output, "@/>");
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_buffer_overflow_emits_bell() {
let mut shell = helpers::create_test_shell();
let long_input = "a".repeat(128);
for c in long_input.chars() {
shell.process_char(c).unwrap();
}
shell.io_mut().clear_output();
shell.process_char('x').unwrap();
let output = shell.io_mut().output();
assert!(
output.contains('\x07'),
"Should emit bell character on buffer full"
);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_bell_on_buffer_overflow() {
let mut shell = helpers::create_test_shell();
helpers::type_input(&mut shell, &"a".repeat(128));
shell.io_mut().clear_output();
helpers::type_input(&mut shell, "x");
let output = shell.io_mut().output();
assert_eq!(
helpers::count_char(&output, '\x07'),
1,
"Should emit exactly one bell character"
);
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_prompt_format() {
let mut shell = helpers::create_test_shell();
shell.io_mut().clear_output();
helpers::press_enter(&mut shell);
let output = shell.io_mut().output();
helpers::assert_prompt(&output, "@/>");
}
#[test]
#[cfg(not(feature = "authentication"))]
fn test_prompt_updates_with_navigation() {
let mut shell = helpers::create_test_shell();
helpers::execute_command(&mut shell, "system");
shell.io_mut().clear_output();
helpers::press_enter(&mut shell);
let output = shell.io_mut().output();
helpers::assert_prompt(&output, "@/system>");
}