#![allow(non_snake_case)]
use std::fs;
use tempfile::TempDir;
#[test]
fn test_defect_015_01_function_scope_string_accumulator_RED() {
let temp_dir = TempDir::new().unwrap();
let test_file = temp_dir.path().join("test.ruchy");
let ruchy_code = r#"
struct Process {
pid: i32,
name: String,
cpu_usage: f64,
}
fun format_process(proc: Process) -> String {
let formatted = "Process[PID=";
formatted = formatted + proc.pid.to_string();
formatted = formatted + ", name='";
formatted = formatted + proc.name;
formatted = formatted + "', CPU=";
formatted = formatted + proc.cpu_usage.to_string();
formatted = formatted + "%]";
formatted
}
let proc = Process { pid: 123, name: "test", cpu_usage: 45.5 };
let result = format_process(proc);
println(result);
"#;
fs::write(&test_file, ruchy_code).unwrap();
let output = assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("compile")
.arg(&test_file)
.output()
.unwrap();
if output.status.success() {
eprintln!("✅ GREEN: Test passes after fix applied");
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("E0308") || stderr.contains("E0369"),
"Expected E0308 or E0369 errors (mutable string not detected). Got:\n{stderr}"
);
eprintln!("✅ RED TEST: E0308/E0369 errors confirmed (as expected before fix)");
eprintln!("Error details:\n{stderr}");
}
}
#[test]
#[ignore = "transpiler defect 015 not fixed yet"]
fn test_defect_015_02_format_macro_returns_string_RED() {
let temp_dir = TempDir::new().unwrap();
let test_file = temp_dir.path().join("test.ruchy");
let ruchy_code = r#"
fun build_message(id: i32, name: String) -> String {
let msg = "ID: ";
msg = msg + id.to_string(); // After transpilation: format!("{}{}", msg, id.to_string())
msg = msg + ", Name: ";
msg = msg + name;
msg
}
let result = build_message(42, "test");
println(result);
"#;
fs::write(&test_file, ruchy_code).unwrap();
let output = assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("compile")
.arg(&test_file)
.output()
.unwrap();
if output.status.success() {
eprintln!("✅ GREEN: format!() pattern fixed");
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("E0308"),
"Expected E0308: format!() returns String, msg is &str. Got:\n{stderr}"
);
eprintln!("✅ RED TEST: format!() type mismatch confirmed");
}
}
#[test]
#[ignore = "transpiler defect 015 not fixed yet"]
fn test_defect_015_03_multiple_concatenations_RED() {
let temp_dir = TempDir::new().unwrap();
let test_file = temp_dir.path().join("test.ruchy");
let ruchy_code = r#"
fun build_long_string(a: String, b: String, c: String) -> String {
let result = "Start: ";
result = result + a;
result = result + ", Middle: ";
result = result + b;
result = result + ", End: ";
result = result + c;
result
}
let output = build_long_string("foo", "bar", "baz");
println(output);
"#;
fs::write(&test_file, ruchy_code).unwrap();
let output = assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("compile")
.arg(&test_file)
.output()
.unwrap();
if output.status.success() {
eprintln!("✅ GREEN: Multiple concatenations fixed");
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("E0308") || stderr.contains("E0369"),
"Expected type errors from multiple concatenations. Got:\n{stderr}"
);
eprintln!("✅ RED TEST: Multiple concatenation errors confirmed");
}
}
#[test]
fn test_defect_015_04_string_field_concatenation_RED() {
let temp_dir = TempDir::new().unwrap();
let test_file = temp_dir.path().join("test.ruchy");
let ruchy_code = r#"
struct Config {
name: String,
path: String,
}
fun format_config(cfg: Config) -> String {
let output = "Config: ";
output = output + cfg.name; // cfg.name is String
output = output + " at ";
output = output + cfg.path; // cfg.path is String
output
}
let config = Config { name: "test.conf", path: "/etc/test" };
let result = format_config(config);
println(result);
"#;
fs::write(&test_file, ruchy_code).unwrap();
let output = assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("compile")
.arg(&test_file)
.output()
.unwrap();
if output.status.success() {
eprintln!("✅ GREEN: String field concatenation fixed");
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("E0308"),
"Expected E0308: output is &str, cfg.name is String. Got:\n{stderr}"
);
eprintln!("✅ RED TEST: String field concatenation error confirmed");
}
}
#[test]
#[ignore = "transpiler defect 015 not fixed yet"]
fn test_defect_015_05_immutable_string_baseline() {
let temp_dir = TempDir::new().unwrap();
let test_file = temp_dir.path().join("test.ruchy");
let ruchy_code = r#"
fun get_message() -> String {
let msg = "Hello, World!"; // Immutable, never reassigned
msg.to_string() // Explicit conversion
}
let result = get_message();
println(result);
"#;
fs::write(&test_file, ruchy_code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("compile")
.arg(&test_file)
.assert()
.success();
}
#[test]
#[ignore = "transpiler defect 015 not fixed yet"]
fn test_defect_015_06_top_level_mutable_string_baseline() {
let temp_dir = TempDir::new().unwrap();
let test_file = temp_dir.path().join("test.ruchy");
let ruchy_code = r#"
let mut formatted = "Start";
formatted = formatted + " Middle";
formatted = formatted + " End";
println(formatted);
"#;
fs::write(&test_file, ruchy_code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("compile")
.arg(&test_file)
.assert()
.success();
}
#[test]
#[ignore = "transpiler defect 015 not fixed yet"]
fn test_defect_015_07_nested_block_string_accumulator_RED() {
let temp_dir = TempDir::new().unwrap();
let test_file = temp_dir.path().join("test.ruchy");
let ruchy_code = r#"
fun build_complex_message(x: i32) -> String {
if x > 0 {
let msg = "Positive: ";
msg = msg + x.to_string();
msg
} else {
let msg = "Negative: ";
msg = msg + x.to_string();
msg
}
}
let result = build_complex_message(42);
println(result);
"#;
fs::write(&test_file, ruchy_code).unwrap();
let output = assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("compile")
.arg(&test_file)
.output()
.unwrap();
if output.status.success() {
eprintln!("✅ GREEN: Nested block patterns fixed");
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("E0308") || stderr.contains("E0369"),
"Expected type errors in nested blocks. Got:\n{stderr}"
);
eprintln!("✅ RED TEST: Nested block string accumulator errors confirmed");
}
}
#[test]
#[ignore = "transpiler defect 015 not fixed yet"]
fn test_defect_015_08_method_call_concatenation_RED() {
let temp_dir = TempDir::new().unwrap();
let test_file = temp_dir.path().join("test.ruchy");
let ruchy_code = r#"
fun format_number(n: i32) -> String {
let output = "Number: ";
output = output + n.to_string();
output
}
let result = format_number(123);
println(result);
"#;
fs::write(&test_file, ruchy_code).unwrap();
let output = assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("compile")
.arg(&test_file)
.output()
.unwrap();
if output.status.success() {
eprintln!("✅ GREEN: Method call concatenation fixed");
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("E0308") || stderr.contains("E0369"),
"Expected type errors with method call results. Got:\n{stderr}"
);
eprintln!("✅ RED TEST: Method call concatenation errors confirmed");
}
}
#[test]
#[ignore = "transpiler defect 015 not fixed yet"]
fn test_defect_015_09_e0369_string_to_str_RED() {
let temp_dir = TempDir::new().unwrap();
let test_file = temp_dir.path().join("test.ruchy");
let ruchy_code = r#"
struct Data {
value: String,
}
fun format_data(d: Data) -> String {
let result = "Data: ";
result = result + d.value; // ❌ &str + String → E0369
result
}
let data = Data { value: "test" };
let output = format_data(data);
println(output);
"#;
fs::write(&test_file, ruchy_code).unwrap();
let output = assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("compile")
.arg(&test_file)
.output()
.unwrap();
if output.status.success() {
eprintln!("✅ GREEN: E0369 pattern fixed");
} else {
let stderr = String::from_utf8_lossy(&output.stderr);
assert!(
stderr.contains("E0369"),
"Expected E0369: cannot add String to &str. Got:\n{stderr}"
);
eprintln!("✅ RED TEST: E0369 (cannot add String to &str) confirmed");
}
}