#![allow(deprecated)]
use assert_cmd::Command;
use predicates::prelude::*;
use std::path::PathBuf;
fn ruchy_cmd() -> Command {
Command::cargo_bin("ruchy").expect("Failed to find ruchy binary")
}
fn example_path(relative_path: &str) -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("examples/lang_comp/06-data-structures")
.join(relative_path)
}
fn validate_with_15_tools(example: &PathBuf) {
ruchy_cmd().arg("check").arg(example).assert().success();
ruchy_cmd().arg("transpile").arg(example).assert().success();
let code = std::fs::read_to_string(example).unwrap();
ruchy_cmd().arg("-e").arg(&code).assert().success();
ruchy_cmd().arg("lint").arg(example).assert().success();
let compile_output = std::env::temp_dir().join(format!(
"compile_test_{}_{}",
example.file_stem().unwrap().to_string_lossy(),
std::process::id()
));
ruchy_cmd()
.arg("compile")
.arg(example)
.arg("-o")
.arg(&compile_output)
.assert()
.success();
std::fs::remove_file(&compile_output).ok();
ruchy_cmd().arg("run").arg(example).assert().success();
ruchy_cmd().arg("coverage").arg(example).assert().success();
ruchy_cmd()
.arg("runtime")
.arg(example)
.arg("--bigo")
.assert()
.success();
ruchy_cmd().arg("ast").arg(example).assert().success();
let temp_file = std::env::temp_dir().join(format!(
"wasm_validation_test_{}_{}.ruchy",
example.file_stem().unwrap().to_string_lossy(),
std::process::id()
));
std::fs::write(&temp_file, "let x = 42\nprintln(x)").unwrap();
ruchy_cmd().arg("wasm").arg(&temp_file).assert().success();
std::fs::remove_file(&temp_file).ok();
ruchy_cmd()
.arg("provability")
.arg(example)
.assert()
.success();
ruchy_cmd()
.arg("property-tests")
.arg(example)
.arg("--cases")
.arg("100")
.assert()
.success();
ruchy_cmd()
.arg("mutations")
.arg(example)
.arg("--min-coverage")
.arg("0")
.arg("--timeout")
.arg("60")
.assert()
.success();
ruchy_cmd()
.arg("fuzz")
.arg(example)
.arg("--iterations")
.arg("10")
.assert()
.success();
ruchy_cmd().arg("notebook").arg(example).assert().success();
}
#[test]
fn test_langcomp_006_01_array_literal_creation() {
let temp_file = std::env::temp_dir().join("langcomp_006_01_array_literal.ruchy");
std::fs::write(
&temp_file,
r"
let numbers = [1, 2, 3, 4, 5]
println(numbers)
",
)
.unwrap();
ruchy_cmd()
.arg("run")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("[1, 2, 3, 4, 5]"));
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_006_01_array_indexing() {
let temp_file = std::env::temp_dir().join("langcomp_006_01_array_index.ruchy");
std::fs::write(
&temp_file,
r"
let numbers = [10, 20, 30]
let first = numbers[0]
println(first)
",
)
.unwrap();
ruchy_cmd()
.arg("run")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("10"));
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_006_01_arrays_example_file() {
let example = example_path("01_arrays.ruchy");
validate_with_15_tools(&example);
ruchy_cmd()
.arg("run")
.arg(&example)
.assert()
.success()
.stdout(predicate::str::contains("[1, 2, 3, 4, 5]"))
.stdout(predicate::str::contains("1"))
.stdout(predicate::str::contains("5"));
}
#[test]
fn test_langcomp_006_02_tuple_creation() {
let temp_file = std::env::temp_dir().join("langcomp_006_02_tuple_create.ruchy");
std::fs::write(
&temp_file,
r#"
let person = ("Alice", 30, true)
println(person)
"#,
)
.unwrap();
ruchy_cmd()
.arg("run")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("Alice"))
.stdout(predicate::str::contains("30"));
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_006_02_tuple_destructuring() {
let temp_file = std::env::temp_dir().join("langcomp_006_02_tuple_destruct.ruchy");
std::fs::write(
&temp_file,
r"
let point = (100, 200)
let (x, y) = point
println(x)
println(y)
",
)
.unwrap();
ruchy_cmd()
.arg("run")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("100"))
.stdout(predicate::str::contains("200"));
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_006_02_dictionaries_example_file() {
let example = example_path("02_dictionaries.ruchy");
validate_with_15_tools(&example);
ruchy_cmd()
.arg("run")
.arg(&example)
.assert()
.success()
.stdout(predicate::str::contains("Alice"))
.stdout(predicate::str::contains("30"));
}
#[test]
fn test_langcomp_006_03_tuples_example_file() {
let example = example_path("03_tuples.ruchy");
validate_with_15_tools(&example);
ruchy_cmd()
.arg("run")
.arg(&example)
.assert()
.success()
.stdout(predicate::str::contains("Alice"));
}
#[test]
fn test_langcomp_006_04_struct_creation() {
let temp_file = std::env::temp_dir().join("langcomp_006_04_struct_create.ruchy");
std::fs::write(
&temp_file,
r#"
struct Person {
name: String,
age: i32
}
let alice = Person { name: "Alice".to_string(), age: 30 }
println(alice.name)
println(alice.age)
"#,
)
.unwrap();
ruchy_cmd()
.arg("run")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("Alice"))
.stdout(predicate::str::contains("30"));
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_006_04_destructuring_example_file() {
let example = example_path("04_destructuring.ruchy");
validate_with_15_tools(&example);
ruchy_cmd()
.arg("run")
.arg(&example)
.assert()
.success()
.stdout(predicate::str::contains("100"))
.stdout(predicate::str::contains("200"));
}