use assert_cmd::Command;
use std::fs;
use tempfile::tempdir;
fn ruchy_cmd() -> Command {
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
}
#[test]
fn test_issue_155_01_vec_repeat_basic() {
let dir = tempdir().unwrap();
let file_path = dir.path().join("test.ruchy");
fs::write(&file_path, "fun main() { let v = vec![0.0; 5]; }").unwrap();
let output_path = dir.path().join("output.rs");
ruchy_cmd()
.arg("transpile")
.arg(&file_path)
.arg("-o")
.arg(&output_path)
.assert()
.success();
let output = fs::read_to_string(&output_path).unwrap();
assert!(
output.contains("vec![0f64; 5]") || output.contains("vec![0.0; 5]"),
"Expected vec![0.0; 5] but got: {output}"
);
assert!(
!output.contains("vec![0f64, 5]") && !output.contains("vec![0.0, 5]"),
"Should NOT contain comma syntax: {output}"
);
}
#[test]
fn test_issue_155_02_vec_repeat_with_variable() {
let dir = tempdir().unwrap();
let file_path = dir.path().join("test.ruchy");
fs::write(
&file_path,
"fun main() { let n = 10; let v = vec![0.0; n]; }",
)
.unwrap();
let output_path = dir.path().join("output.rs");
ruchy_cmd()
.arg("transpile")
.arg(&file_path)
.arg("-o")
.arg(&output_path)
.assert()
.success();
let output = fs::read_to_string(&output_path).unwrap();
assert!(
output.contains("; n]") || output.contains("; n }"),
"Expected semicolon before variable n, but got: {output}"
);
}
#[test]
fn test_issue_155_03_nested_vec_repeat() {
let dir = tempdir().unwrap();
let file_path = dir.path().join("test.ruchy");
fs::write(
&file_path,
"fun main() { let n = 5; let m = 3; let matrix = vec![vec![0.0; n]; m]; }",
)
.unwrap();
let output_path = dir.path().join("output.rs");
ruchy_cmd()
.arg("transpile")
.arg(&file_path)
.arg("-o")
.arg(&output_path)
.assert()
.success();
let output = fs::read_to_string(&output_path).unwrap();
assert!(
output.contains("; n]") && output.contains("; m]"),
"Expected nested vec with semicolons, but got: {output}"
);
}
#[test]
fn test_issue_155_04_vec_element_list_still_works() {
let dir = tempdir().unwrap();
let file_path = dir.path().join("test.ruchy");
fs::write(&file_path, "fun main() { let v = vec![1, 2, 3]; }").unwrap();
let output_path = dir.path().join("output.rs");
ruchy_cmd()
.arg("transpile")
.arg(&file_path)
.arg("-o")
.arg(&output_path)
.assert()
.success();
let output = fs::read_to_string(&output_path).unwrap();
assert!(
output.contains("vec![1, 2, 3]") || output.contains("vec![1i64, 2i64, 3i64]"),
"Expected vec![1, 2, 3] with commas, but got: {output}"
);
}
#[test]
fn test_issue_155_05_vec_repeat_compiles() {
let dir = tempdir().unwrap();
let file_path = dir.path().join("test.ruchy");
fs::write(
&file_path,
r#"
fun main() {
let size = 128;
let a = vec![vec![0.0; size]; size];
println!("{}", a.len());
}
"#,
)
.unwrap();
let output_path = dir.path().join("output.rs");
ruchy_cmd()
.arg("transpile")
.arg(&file_path)
.arg("-o")
.arg(&output_path)
.assert()
.success();
let binary_path = dir.path().join("output_binary");
ruchy_cmd()
.arg("compile")
.arg(&file_path)
.arg("-o")
.arg(&binary_path)
.assert()
.success();
}
#[test]
fn test_issue_155_06_matmul_example() {
let dir = tempdir().unwrap();
let file_path = dir.path().join("matmul.ruchy");
fs::write(
&file_path,
r#"
fun matmul(a: Vec<Vec<f64>>, b: Vec<Vec<f64>>) -> Vec<Vec<f64>> {
let n = a.len();
let mut c = vec![vec![0.0; n]; n];
c
}
fun main() {
let size = 4;
let a = vec![vec![0.0; size]; size];
let b = vec![vec![0.0; size]; size];
let c = matmul(a, b);
println!("{}", c.len());
}
"#,
)
.unwrap();
let output_path = dir.path().join("output.rs");
ruchy_cmd()
.arg("transpile")
.arg(&file_path)
.arg("-o")
.arg(&output_path)
.assert()
.success();
let output = fs::read_to_string(&output_path).unwrap();
assert!(
output.contains("; n]") || output.contains("; size]"),
"Expected semicolon in vec repeat, but got: {output}"
);
assert!(
!output.contains("vec![vec![0f64, n], n]") && !output.contains("vec![vec![0.0, n], n]"),
"Should NOT have comma syntax bug: {output}"
);
}
#[test]
fn test_issue_155_07_single_element_vec() {
let dir = tempdir().unwrap();
let file_path = dir.path().join("test.ruchy");
fs::write(&file_path, "fun main() { let v = vec![42]; }").unwrap();
let output_path = dir.path().join("output.rs");
ruchy_cmd()
.arg("transpile")
.arg(&file_path)
.arg("-o")
.arg(&output_path)
.assert()
.success();
let output = fs::read_to_string(&output_path).unwrap();
assert!(
output.contains("vec![42]") || output.contains("vec![42i64]"),
"Single element vec should work: {output}"
);
}
#[test]
fn test_issue_155_08_empty_vec() {
let dir = tempdir().unwrap();
let file_path = dir.path().join("test.ruchy");
fs::write(&file_path, "fun main() { let v: Vec<i32> = vec![]; }").unwrap();
let output_path = dir.path().join("output.rs");
ruchy_cmd()
.arg("transpile")
.arg(&file_path)
.arg("-o")
.arg(&output_path)
.assert()
.success();
let output = fs::read_to_string(&output_path).unwrap();
assert!(
output.contains("vec![]") || output.contains("Vec::new()"),
"Empty vec should work: {output}"
);
}