use tailtales::lua_console::ConsoleLine;
use tailtales::state::TuiState;
fn get_console_text(console_line: &ConsoleLine) -> &str {
match console_line {
ConsoleLine::Stdout(msg) => msg,
ConsoleLine::Stderr(msg) => msg,
}
}
#[test]
fn test_lua_console_initialization_consistency() {
let mut state = TuiState::new().unwrap();
assert!(state.lua_console.output_history.is_empty());
state.ensure_lua_console_initialized();
assert!(!state.lua_console.output_history.is_empty());
assert!(get_console_text(&state.lua_console.output_history[0]).contains("Welcome to Lua REPL!"));
assert!(get_console_text(&state.lua_console.output_history[1]).contains("Supports multiline input"));
assert!(get_console_text(&state.lua_console.output_history[2]).contains("Use print() to output text"));
assert!(get_console_text(&state.lua_console.output_history[3]).contains("Press Esc to exit"));
assert!(get_console_text(&state.lua_console.output_history[4]).contains("Use ↑/↓ arrows"));
assert!(get_console_text(&state.lua_console.output_history[5]).contains("Press Tab for function"));
assert_eq!(get_console_text(&state.lua_console.output_history[6]), ""); }
#[test]
fn test_lua_console_initialization_idempotent() {
let mut state = TuiState::new().unwrap();
state.ensure_lua_console_initialized();
let first_count = state.lua_console.output_history.len();
state.ensure_lua_console_initialized();
let second_count = state.lua_console.output_history.len();
assert_eq!(first_count, second_count);
}
#[test]
fn test_lua_console_initialization_with_existing_content() {
let mut state = TuiState::new().unwrap();
state.lua_console.add_output("Some existing content".to_string(), state.visible_width);
let initial_count = state.lua_console.output_history.len();
state.ensure_lua_console_initialized();
let final_count = state.lua_console.output_history.len();
assert_eq!(initial_count, final_count);
assert_eq!(get_console_text(&state.lua_console.output_history[0]), "Some existing content");
}
#[test]
fn test_lua_console_initialization_via_set_mode() {
let mut state = TuiState::new().unwrap();
assert!(state.lua_console.output_history.is_empty());
state.set_mode("lua_repl");
assert!(!state.lua_console.output_history.is_empty());
assert!(get_console_text(&state.lua_console.output_history[0]).contains("Welcome to Lua REPL!"));
}