#[cfg(feature = "ruchy-ast")]
#[cfg(test)]
mod ruchy_standalone_tests {
use std::io::Write;
use tempfile::NamedTempFile;
#[test]
fn test_ruchy_parser_available() {
let simple_code = "42";
assert!(ruchy::is_valid_syntax(simple_code));
let mut parser = ruchy::Parser::new(simple_code);
let result = parser.parse();
assert!(result.is_ok());
}
#[test]
fn test_ruchy_function_parsing() {
let function_code = r#"
fun hello() -> String {
"Hello, World!"
}
"#;
assert!(ruchy::is_valid_syntax(function_code));
let mut parser = ruchy::Parser::new(function_code);
let ast = parser.parse();
assert!(ast.is_ok(), "Should parse valid Ruchy function");
let _expr = ast.unwrap();
}
#[test]
fn test_ruchy_parse_error_handling() {
let invalid_code = "fun broken_syntax(";
assert!(!ruchy::is_valid_syntax(invalid_code));
let error = ruchy::get_parse_error(invalid_code);
assert!(error.is_some());
assert!(!error.unwrap().is_empty());
}
#[test]
fn test_file_operations() -> Result<(), Box<dyn std::error::Error>> {
let ruchy_code = r#"
fun fibonacci(n: i32) -> i32 {
if n <= 1 {
n
} else {
fibonacci(n - 1) + fibonacci(n - 2)
}
}
"#;
let mut temp_file = NamedTempFile::new()?;
temp_file.write_all(ruchy_code.as_bytes())?;
let content = std::fs::read_to_string(temp_file.path())?;
assert!(content.contains("fibonacci"));
assert!(ruchy::is_valid_syntax(&content));
Ok(())
}
}
#[cfg(not(feature = "ruchy-ast"))]
#[cfg(test)]
mod ruchy_feature_disabled_tests {
#[test]
fn test_feature_disabled_message() {
println!("ruchy-ast feature is disabled - using fallback implementation");
assert!(true);
}
}