windjammer 0.48.0

A simple language inspired by Go, Ruby, and Elixir that transpiles to Rust - 80% of Rust's power with 20% of the complexity
Documentation
#![cfg(any(
    not(any(
        feature = "parser_tests",
        feature = "analyzer_tests",
        feature = "codegen_tests",
        feature = "interpreter_tests",
        feature = "conformance_tests",
        feature = "integration_tests",
    )),
    feature = "codegen_tests",
))]

#[path = "common/test_utils.rs"]
mod test_utils;

use std::fs;
/// TDD: Test that format! macro is passed through correctly to Rust
///
/// The format! macro is a Rust macro that should be passed through as-is.
/// Windjammer doesn't need to parse or understand it, just pass it to rustc.
use std::process::Command;
use tempfile::TempDir;

#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_format_macro_simple() {
    let source = r#"
fn test_format() -> string {
    let x = 42
    format!("The answer is {}", x)
}
"#;

    let temp_dir = TempDir::new().unwrap();
    let input_path = temp_dir.path().join("test_format.wj");
    let output_dir = temp_dir.path().join("build");
    fs::write(&input_path, source).unwrap();

    let output = Command::new(test_utils::wj_binary())
        .args([
            "build",
            input_path.to_str().unwrap(),
            "--no-cargo",
            "--output",
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute wj");

    assert!(
        output.status.success(),
        "Compilation failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let generated = fs::read_to_string(output_dir.join("test_format.rs"))
        .expect("Failed to read generated file");

    // Should contain format! macro as-is
    assert!(
        generated.contains("format!"),
        "Generated code should contain format! macro"
    );
    assert!(
        generated.contains(r#""The answer is {}""#),
        "Format string should be preserved"
    );
}

#[test]
#[cfg_attr(tarpaulin, ignore)]
fn test_format_macro_in_function_call() {
    let source = r#"
fn log_message(msg: string) {
    // Just a test function
}

fn test_format_in_call() {
    let score = 100
    log_message(format!("Score: {}", score))
}
"#;

    let temp_dir = TempDir::new().unwrap();
    let input_path = temp_dir.path().join("test_format_call.wj");
    let output_dir = temp_dir.path().join("build");
    fs::write(&input_path, source).unwrap();

    let output = Command::new(test_utils::wj_binary())
        .args([
            "build",
            input_path.to_str().unwrap(),
            "--no-cargo",
            "--output",
            output_dir.to_str().unwrap(),
        ])
        .output()
        .expect("Failed to execute wj");

    assert!(
        output.status.success(),
        "Compilation failed: {}",
        String::from_utf8_lossy(&output.stderr)
    );

    let generated = fs::read_to_string(output_dir.join("test_format_call.rs"))
        .expect("Failed to read generated file");

    println!("Generated code:\n{}", generated);

    // format!() should be extracted to a temp variable for safety (handles &str/String coercion)
    assert!(
        generated.contains("format!(") && generated.contains("log_message("),
        "format! should be used and log_message should be called"
    );
}