#![cfg(any(
not(any(
feature = "parser_tests",
feature = "analyzer_tests",
feature = "codegen_tests",
feature = "interpreter_tests",
feature = "conformance_tests",
feature = "integration_tests",
)),
feature = "analyzer_tests",
))]
#[path = "common/test_utils.rs"]
mod test_utils;
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_println_simple_string() {
let code = r#"
pub fn greet() {
println("Hello, World!")
}
"#;
let generated = test_utils::compile_single_result(code).expect("Compilation failed");
assert!(
generated.contains("println!(\"Hello, World!\")"),
"Should generate println! macro. Generated:\n{}",
generated
);
}
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_println_with_format() {
let code = r#"
pub fn log_value(x: int) {
println("Value: {}", x)
}
"#;
let generated = test_utils::compile_single_result(code).expect("Compilation failed");
assert!(
generated.contains("println!(\"Value: {}\", x)"),
"Should generate println! with format args. Generated:\n{}",
generated
);
}
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_println_multiple_args() {
let code = r#"
pub fn log_pair(a: int, b: int) {
println("Values: {} and {}", a, b)
}
"#;
let generated = test_utils::compile_single_result(code).expect("Compilation failed");
assert!(
generated.contains("println!(\"Values: {} and {}\", a, b)"),
"Should generate println! with multiple args. Generated:\n{}",
generated
);
}
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_println_with_string_variable() {
let code = r#"
pub fn display(message: string) {
println("Message: {}", message)
}
"#;
let generated = test_utils::compile_single_result(code).expect("Compilation failed");
assert!(
generated.contains("println!(\"Message: {}\", message)"),
"Should generate println! with string var. Generated:\n{}",
generated
);
}
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_println_in_if_statement() {
let code = r#"
pub fn check(x: int) {
if x > 0 {
println("Positive: {}", x)
} else {
println("Non-positive")
}
}
"#;
let generated = test_utils::compile_single_result(code).expect("Compilation failed");
assert!(
generated.contains("println!(\"Positive: {}\", x)"),
"Should generate println! in if block. Generated:\n{}",
generated
);
assert!(
generated.contains("println!(\"Non-positive\")"),
"Should generate println! in else block. Generated:\n{}",
generated
);
}
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_println_with_expression() {
let code = r#"
pub fn calc(x: int, y: int) {
println("Sum: {}", x + y)
}
"#;
let generated = test_utils::compile_single_result(code).expect("Compilation failed");
assert!(
generated.contains("println!(\"Sum: {}\", x + y)"),
"Should generate println! with expression. Generated:\n{}",
generated
);
}
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_println_with_method_call() {
let code = r#"
pub fn show_length(text: string) {
println("Length: {}", text.len())
}
"#;
let generated = test_utils::compile_single_result(code).expect("Compilation failed");
assert!(
generated.contains("println!(\"Length: {}\", text.len())"),
"Should generate println! with method call. Generated:\n{}",
generated
);
}
#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_println_keeps_existing_macro_syntax() {
let code = r#"
pub fn test() {
println!("With macro!")
}
"#;
let generated = test_utils::compile_single_result(code).expect("Compilation failed");
assert!(
generated.contains("println!(\"With macro!\")"),
"Should preserve existing println! syntax. Generated:\n{}",
generated
);
}