#![allow(missing_docs)]
use std::fs;
use tempfile::NamedTempFile;
#[test]
fn test_parser_085_01_simple_function_pointer_type() {
let code = r"
fun run(f: fn()) {
f();
}
fun main() {}
";
let temp_file = NamedTempFile::new().unwrap();
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("check")
.arg(temp_file.path())
.assert()
.success();
}
#[test]
fn test_parser_085_02_function_pointer_with_params() {
let code = r"
fun apply(f: fn(i32), x: i32) {
f(x);
}
fun main() {}
";
let temp_file = NamedTempFile::new().unwrap();
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("check")
.arg(temp_file.path())
.assert()
.success();
}
#[test]
fn test_parser_085_03_function_pointer_with_return() {
let code = r"
fun transform(f: fn(i32) -> i32, x: i32) -> i32 {
f(x)
}
fun main() {}
";
let temp_file = NamedTempFile::new().unwrap();
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("check")
.arg(temp_file.path())
.assert()
.success();
}
#[test]
fn test_parser_085_04_function_pointer_multiple_params() {
let code = r"
fun combine(f: fn(i32, i32) -> i32, a: i32, b: i32) -> i32 {
f(a, b)
}
fun main() {}
";
let temp_file = NamedTempFile::new().unwrap();
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("check")
.arg(temp_file.path())
.assert()
.success();
}
#[test]
fn test_parser_085_05_call_function_pointer() {
let code = r#"
fun hello() {
println!("Hello");
}
fun run_test(test_fn: fn(), passed: &mut i32) {
test_fn();
*passed += 1;
}
fun main() {
let mut count = 0;
run_test(hello, &mut count);
println!("Count: {}", count);
}
"#;
let temp_file = NamedTempFile::new().unwrap();
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("check")
.arg(temp_file.path())
.assert()
.success();
}
#[test]
fn test_parser_085_06_ruchy_005_blocker_reproduction() {
let code = r#"
fun test_compare_versions_equal() {
println!("TEST: compare_versions - equal versions");
}
fun run_test(test_fn: fn(), passed: &mut i32, failed: &mut i32) {
test_fn();
*passed += 1;
}
fun main() {
let mut passed = 0;
let mut failed = 0;
run_test(test_compare_versions_equal, &mut passed, &mut failed);
println!("Passed: {}", passed);
}
"#;
let temp_file = NamedTempFile::new().unwrap();
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("check")
.arg(temp_file.path())
.assert()
.success();
}
#[test]
fn test_parser_085_07_transpile_function_pointer() {
let code = r"
fun apply(f: fn(i32) -> i32, value: i32) -> i32 {
f(value)
}
fun main() {}
";
let temp_file = NamedTempFile::new().unwrap();
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("transpile")
.arg(temp_file.path())
.assert()
.success();
}
#[test]
fn test_parser_085_08_eval_function_pointer() {
let code = r#"
fun double(x: i32) -> i32 {
x * 2
}
fun apply_op(f: fn(i32) -> i32, value: i32) -> i32 {
f(value)
}
fun main() {
let result = apply_op(double, 5);
println!("{}", result);
}
"#;
let temp_file = NamedTempFile::new().unwrap();
fs::write(&temp_file, code).unwrap();
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
.arg("-e")
.arg(code)
.assert()
.success()
.stdout(predicates::str::contains("10"));
}