use yufmath::cli::interactive::InteractiveSession;
#[test]
fn test_interactive_session_creation() {
let session = InteractiveSession::new();
}
#[test]
fn test_help_command() {
let mut session = InteractiveSession::new();
let result = session.process_command("help").unwrap();
assert!(result.contains("Yufmath 交互式计算器帮助"));
assert!(result.contains("基本命令"));
assert!(result.contains("数学运算"));
let result = session.process_command("?").unwrap();
assert!(result.contains("Yufmath 交互式计算器帮助"));
}
#[test]
fn test_quit_commands() {
let mut session = InteractiveSession::new();
let result = session.process_command("quit").unwrap();
assert_eq!(result, "再见!");
let result = session.process_command("exit").unwrap();
assert_eq!(result, "再见!");
let result = session.process_command("q").unwrap();
assert_eq!(result, "再见!");
}
#[test]
fn test_clear_command() {
let mut session = InteractiveSession::new();
let result = session.process_command("clear").unwrap();
assert_eq!(result, "变量已清空");
}
#[test]
fn test_variables_command() {
let mut session = InteractiveSession::new();
let result = session.process_command("vars").unwrap();
assert_eq!(result, "没有定义变量");
let result = session.process_command("variables").unwrap();
assert_eq!(result, "没有定义变量");
}
#[test]
fn test_verbose_command() {
let mut session = InteractiveSession::new();
let result = session.process_command("verbose").unwrap();
assert!(result.contains("详细模式"));
let result = session.process_command("verbose").unwrap();
assert!(result.contains("详细模式"));
}
#[test]
fn test_format_commands() {
let mut session = InteractiveSession::new();
let result = session.process_command("format standard").unwrap();
assert!(result.contains("输出格式已设置为"));
let result = session.process_command("format latex").unwrap();
assert!(result.contains("输出格式已设置为"));
let result = session.process_command("format mathml").unwrap();
assert!(result.contains("输出格式已设置为"));
let result = session.process_command("format invalid").unwrap();
assert!(result.contains("无效的格式类型"));
}
#[test]
fn test_precision_commands() {
let mut session = InteractiveSession::new();
let result = session.process_command("precision 10").unwrap();
assert!(result.contains("数值精度已设置为: 10"));
let result = session.process_command("precision abc").unwrap();
assert!(result.contains("无效的精度值"));
let result = session.process_command("precision -5").unwrap();
assert!(result.contains("无效的精度值"));
}
#[test]
fn test_empty_input() {
let mut session = InteractiveSession::new();
let result = session.process_command("").unwrap();
assert_eq!(result, "");
let result = session.process_command(" ").unwrap();
assert_eq!(result, "");
}
#[test]
fn test_assignment_parsing() {
let mut session = InteractiveSession::new();
let result = session.process_command("x = 5");
assert!(result.is_err());
}
#[test]
fn test_mathematical_expressions() {
let mut session = InteractiveSession::new();
let result = session.process_command("2 + 3");
assert!(result.is_err());
let result = session.process_command("x^2 + 2*x + 1");
assert!(result.is_err());
}
#[test]
fn test_case_insensitive_commands() {
let mut session = InteractiveSession::new();
let result1 = session.process_command("HELP").unwrap();
let result2 = session.process_command("help").unwrap();
assert_eq!(result1, result2);
let result1 = session.process_command("QUIT").unwrap();
let result2 = session.process_command("quit").unwrap();
assert_eq!(result1, result2);
}
#[cfg(test)]
mod integration_tests {
use super::*;
#[test]
fn test_session_workflow() {
let mut session = InteractiveSession::new();
let help_result = session.process_command("help").unwrap();
assert!(help_result.contains("帮助"));
let format_result = session.process_command("format latex").unwrap();
assert!(format_result.contains("LaTeX"));
let precision_result = session.process_command("precision 15").unwrap();
assert!(precision_result.contains("15"));
let verbose_result = session.process_command("verbose").unwrap();
assert!(verbose_result.contains("详细模式"));
let vars_result = session.process_command("vars").unwrap();
assert_eq!(vars_result, "没有定义变量");
let clear_result = session.process_command("clear").unwrap();
assert_eq!(clear_result, "变量已清空");
}
}