use r2rust_core::environment::Environment; use r2rust_core::evaluator::evaluate; use r2rust_core::lexer::tokenize; use r2rust_core::parser::parse; #[cfg(test)] mod tests { use super::*; #[test] fn test_repl_evaluation_simple() { let input = "x <- 10 + 32"; let tokens = tokenize(input); let ast = parse(&tokens).expect("Failed to parse"); let mut env = Environment::new(); let result = evaluate(ast, &mut env).expect("Failed to evaluate"); assert_eq!(result, 42.0); assert_eq!(env.get("x"), Some(&42.0)); } #[test] fn test_repl_variable_usage() { let mut env = Environment::new(); // Assign a variable let input1 = "x <- 20"; let tokens1 = tokenize(input1); let ast1 = parse(&tokens1).expect("Failed to parse"); evaluate(ast1, &mut env).expect("Failed to evaluate"); // Use the variable in an expression let input2 = "y <- x + 22"; let tokens2 = tokenize(input2); let ast2 = parse(&tokens2).expect("Failed to parse"); let result2 = evaluate(ast2, &mut env).expect("Failed to evaluate"); assert_eq!(result2, 42.0); assert_eq!(env.get("y"), Some(&42.0)); } #[test] fn test_repl_help_command() { let help_command = "help"; assert_eq!(help_command.trim(), "help"); } }