#![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/08-methods")
.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_008_01_to_string_method() {
let temp_file = std::env::temp_dir().join("langcomp_008_01_to_string.ruchy");
std::fs::write(
&temp_file,
r"
let num = 42
let text = num.to_string()
println(text)
",
)
.unwrap();
ruchy_cmd()
.arg("run")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("42"));
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_008_01_string_trim_method() {
let temp_file = std::env::temp_dir().join("langcomp_008_01_trim.ruchy");
std::fs::write(
&temp_file,
r#"
let text = " hello "
let trimmed = text.trim()
println(trimmed)
"#,
)
.unwrap();
ruchy_cmd()
.arg("run")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("hello"));
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_008_01_string_replace_method() {
let temp_file = std::env::temp_dir().join("langcomp_008_01_replace.ruchy");
std::fs::write(
&temp_file,
r#"
let text = "hello world"
let replaced = text.replace("world", "Ruchy")
println(replaced)
"#,
)
.unwrap();
ruchy_cmd()
.arg("run")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("hello Ruchy"));
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_008_01_string_methods_example_file() {
let example = example_path("01_string_methods.ruchy");
validate_with_15_tools(&example);
ruchy_cmd()
.arg("run")
.arg(&example)
.assert()
.success()
.stdout(predicate::str::contains("HELLO WORLD"))
.stdout(predicate::str::contains("hello Ruchy"));
}
#[test]
fn test_langcomp_008_02_array_first_method() {
let temp_file = std::env::temp_dir().join("langcomp_008_02_first.ruchy");
std::fs::write(
&temp_file,
r"
let numbers = [1, 2, 3, 4, 5]
let first = numbers.first()
println(first)
",
)
.unwrap();
ruchy_cmd().arg("run").arg(&temp_file).assert().success();
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_008_02_array_last_method() {
let temp_file = std::env::temp_dir().join("langcomp_008_02_last.ruchy");
std::fs::write(
&temp_file,
r"
let numbers = [1, 2, 3, 4, 5]
let last = numbers.last()
println(last)
",
)
.unwrap();
ruchy_cmd().arg("run").arg(&temp_file).assert().success();
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_008_02_array_methods_example_file() {
let example = example_path("02_array_methods.ruchy");
validate_with_15_tools(&example);
ruchy_cmd().arg("run").arg(&example).assert().success();
}
#[test]
fn test_langcomp_008_03_integer_abs_method() {
let temp_file = std::env::temp_dir().join("langcomp_008_03_abs.ruchy");
std::fs::write(
&temp_file,
r"
let negative = -42i32
let positive = negative.abs()
println(positive)
",
)
.unwrap();
ruchy_cmd()
.arg("run")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("42"));
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_008_03_integer_pow_method() {
let temp_file = std::env::temp_dir().join("langcomp_008_03_pow.ruchy");
std::fs::write(
&temp_file,
r"
let base = 2i32
let result = base.pow(3)
println(result)
",
)
.unwrap();
ruchy_cmd()
.arg("run")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("8"));
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_008_03_integer_methods_example_file() {
let example = example_path("03_integer_methods.ruchy");
validate_with_15_tools(&example);
ruchy_cmd()
.arg("run")
.arg(&example)
.assert()
.success()
.stdout(predicate::str::contains("42"));
}
#[test]
fn test_langcomp_008_04_string_method_chaining() {
let temp_file = std::env::temp_dir().join("langcomp_008_04_chain.ruchy");
std::fs::write(
&temp_file,
r#"
let text = " hello world "
let result = text.trim().replace("world", "Ruchy")
println(result)
"#,
)
.unwrap();
ruchy_cmd()
.arg("run")
.arg(&temp_file)
.assert()
.success()
.stdout(predicate::str::contains("hello Ruchy"));
std::fs::remove_file(&temp_file).ok();
}
#[test]
fn test_langcomp_008_04_chaining_methods_example_file() {
let example = example_path("04_chaining_methods.ruchy");
validate_with_15_tools(&example);
ruchy_cmd()
.arg("run")
.arg(&example)
.assert()
.success()
.stdout(predicate::str::contains("hello Ruchy"));
}