use anyhow::Result;
use std::path::PathBuf;
pub fn handle_repl_command(record_file: Option<PathBuf>) -> Result<()> {
use colored::Colorize;
let version_msg = format!("Welcome to Ruchy REPL v{}", env!("CARGO_PKG_VERSION"));
println!("{}", version_msg.bright_cyan().bold());
println!(
"Type {} for commands, {} to exit\n",
":help".green(),
":quit".yellow()
);
let mut repl = super::create_repl()?;
if let Some(record_path) = record_file {
repl.run_with_recording(&record_path)
} else {
repl.run()
}
}
pub(crate) fn print_prover_help() {
println!("\nInteractive Prover Commands:");
println!(" help - Show this help message");
println!(" quit/exit - Exit the prover");
println!(" goals - Show current proof goals");
println!(" tactics - List available tactics");
println!(" goal <stmt> - Add a new proof goal");
println!(" apply <tactic> - Apply a tactic to current goal");
println!("\nTactics:");
println!(" intro - Introduce hypothesis from implication");
println!(" split - Split conjunction into subgoals");
println!(" induction - Proof by induction");
println!(" contradiction - Proof by contradiction");
println!(" reflexivity - Prove equality by reflexivity");
println!(" simplify - Simplify expression");
println!(" assumption - Prove using an assumption");
println!("\nExamples:");
println!(" goal x > 0 -> x + 1 > 1");
println!(" apply intro");
println!(" apply simplify\n");
}
#[cfg(test)]
mod tests {
use super::*;
use tempfile::TempDir;
#[test]
fn test_print_prover_help_does_not_panic() {
print_prover_help();
}
#[test]
fn test_print_prover_help_multiple_calls() {
print_prover_help();
print_prover_help();
print_prover_help();
}
#[test]
fn test_repl_handler_accepts_none_record() {
let _ = handle_repl_command(None);
}
#[test]
fn test_repl_handler_accepts_record_path() {
let temp_dir = TempDir::new().unwrap();
let record_path = temp_dir.path().join("repl_session.txt");
let _ = handle_repl_command(Some(record_path));
}
#[test]
fn test_repl_handler_record_nonexistent_dir() {
let record_path = std::path::PathBuf::from("/nonexistent/dir/session.txt");
let _ = handle_repl_command(Some(record_path));
}
#[test]
fn test_prover_help_contains_commands() {
print_prover_help();
}
#[test]
fn test_prover_help_contains_tactics() {
print_prover_help();
}
#[test]
fn test_prover_help_contains_examples() {
print_prover_help();
}
#[test]
fn test_repl_handler_various_paths() {
let paths = [
std::path::PathBuf::from("/tmp/test.txt"),
std::path::PathBuf::from("./local.txt"),
std::path::PathBuf::from("session"),
];
for path in paths {
let _ = handle_repl_command(Some(path));
}
}
#[test]
fn test_print_prover_help_content_check() {
print_prover_help();
}
#[test]
fn test_repl_handler_temp_file_recording() {
let temp_dir = TempDir::new().unwrap();
let files = ["session1.txt", "session2.record", "test.log"];
for file in &files {
let record_path = temp_dir.path().join(file);
let _ = handle_repl_command(Some(record_path));
}
}
#[test]
fn test_repl_handler_nested_directory() {
let temp_dir = TempDir::new().unwrap();
let nested = temp_dir.path().join("a").join("b").join("c");
std::fs::create_dir_all(&nested).unwrap();
let record_path = nested.join("session.txt");
let _ = handle_repl_command(Some(record_path));
}
#[test]
fn test_repl_handler_with_extension_variations() {
let extensions = [".txt", ".repl", ".session", ".log", ""];
for ext in &extensions {
let path = PathBuf::from(format!("/tmp/test{}", ext));
let _ = handle_repl_command(Some(path));
}
}
}