#![allow(missing_docs)]
use ruchy::quality::formatter::Formatter;
use ruchy::Parser;
#[test]
fn test_bug_031_function_call_corrupts_file() {
let code = r#"
fun main() {
println("Hello, World!")
}
"#;
let mut parser = Parser::new(code);
let ast = parser.parse().expect("Failed to parse");
let formatter = Formatter::new();
let result = formatter.format(&ast).expect("Failed to format");
assert!(
result.contains("println"),
"Formatted output should contain 'println'"
);
assert!(
result.contains("Hello, World!"),
"Formatted output should contain string literal"
);
assert!(
!result.contains("Call {"),
"Formatted output should NOT contain 'Call {{' (AST debug)"
);
assert!(
!result.contains("Expr {"),
"Formatted output should NOT contain 'Expr {{' (AST debug)"
);
assert!(
!result.contains("kind:"),
"Formatted output should NOT contain 'kind:' (AST debug)"
);
}
#[test]
fn test_bug_031_method_call_formatting() {
let code = r#"
fun example() {
let x = "test".to_uppercase()
}
"#;
let mut parser = Parser::new(code);
let ast = parser.parse().expect("Failed to parse");
let formatter = Formatter::new();
let result = formatter.format(&ast).expect("Failed to format");
assert!(
result.contains("to_uppercase"),
"Should contain method name"
);
assert!(
!result.contains("MethodCall {"),
"Should NOT contain 'MethodCall {{' (AST debug)"
);
}
#[test]
fn test_bug_031_for_loop_formatting() {
let code = r"
fun example() {
for i in range(0, 10) {
println(i)
}
}
";
let mut parser = Parser::new(code);
let ast = parser.parse().expect("Failed to parse");
let formatter = Formatter::new();
let result = formatter.format(&ast).expect("Failed to format");
assert!(result.contains("for"), "Should contain 'for' keyword");
assert!(result.contains("range"), "Should contain 'range' function");
assert!(
!result.contains("For {"),
"Should NOT contain 'For {{' (AST debug)"
);
}
#[test]
fn test_bug_031_assignment_formatting() {
let code = r#"
fun example() {
let x = 42
let y = "hello"
}
"#;
let mut parser = Parser::new(code);
let ast = parser.parse().expect("Failed to parse");
let formatter = Formatter::new();
let result = formatter.format(&ast).expect("Failed to format");
assert!(result.contains("let x"), "Should contain 'let x'");
assert!(result.contains("42"), "Should contain integer literal");
assert!(result.contains("hello"), "Should contain string literal");
assert!(
!result.contains("Assign {"),
"Should NOT contain 'Assign {{' (AST debug)"
);
}
#[test]
fn property_formatter_never_outputs_debug_format() {
let test_cases = vec![
"fun f() { println(\"test\") }",
"fun f() { let x = 1 }",
"fun f() { for i in range(0, 5) { println(i) } }",
"fun f() { if x { y } else { z } }",
"fun f() { x.method() }",
];
for code in test_cases {
let mut parser = Parser::new(code);
if let Ok(ast) = parser.parse() {
let formatter = Formatter::new();
if let Ok(result) = formatter.format(&ast) {
assert!(
!result.contains("Assign {"),
"Code: {code}\nFormatted output should not contain 'Assign {{' (AST debug)"
);
assert!(
!result.contains("Expr {"),
"Code: {code}\nFormatted output should not contain 'Expr {{' (AST debug)"
);
assert!(
!result.contains("Stmt {"),
"Code: {code}\nFormatted output should not contain 'Stmt {{' (AST debug)"
);
assert!(
!result.contains("kind:"),
"Code: {code}\nFormatted output should not contain 'kind:' field"
);
}
}
}
}