#![allow(missing_docs)]
use std::fs;
use tempfile::NamedTempFile;
fn write_and_check(code: &str) {
let temp_file = NamedTempFile::new().unwrap();
fs::write(temp_file.path(), code).unwrap();
let mut cmd = assert_cmd::cargo::cargo_bin_cmd!("ruchy");
cmd.arg("check").arg(temp_file.path()).assert().success();
}
#[test]
fn test_parser_089_ref_param_with_match() {
let code = r#"
use std::process::Command;
pub fun check_command(command: &str) -> bool {
let result = Command::new("which").arg(command).output();
match result {
Ok(output) => output.status.success(),
Err(_) => false,
}
}
"#;
write_and_check(code);
}
#[test]
fn test_parser_089_ref_param_no_match_works() {
let code = r#"
use std::process::Command;
pub fun test(command: &str) -> bool {
let result = Command::new("which").arg(command).output();
true
}
"#;
write_and_check(code);
}
#[test]
fn test_parser_089_match_no_ref_param_works() {
let code = r#"
use std::process::Command;
pub fun test() -> bool {
let result = Command::new("which").arg("test").output();
match result {
Ok(output) => output.status.success(),
Err(_) => false,
}
}
"#;
write_and_check(code);
}
#[test]
fn test_parser_089_multiple_ref_params_with_match() {
let code = r#"
pub fun check_two(first: &str, second: &str) -> bool {
let result = match first {
"ok" => true,
_ => false,
};
match second {
"valid" => result,
_ => false,
}
}
"#;
write_and_check(code);
}
#[test]
fn test_parser_089_nested_match_with_ref_param() {
let code = r#"
pub fun nested_check(input: &str) -> i32 {
match input {
"a" => match "x" {
"x" => 1,
_ => 2,
},
_ => 3,
}
}
"#;
write_and_check(code);
}
#[test]
fn test_parser_089_issue_73_full_reproduction() {
let code = r#"
use std::process::Command;
pub fun check_command(command: &str) -> bool {
let result = Command::new("which")
.arg(command)
.output();
match result {
Ok(output) => output.status.success(),
Err(_) => false,
}
}
pub fun validate_dependencies(deps: Vec<String>) -> bool {
let mut all_present = true;
for dep in deps {
let exists = check_command(&dep);
if !exists {
println!("Missing dependency: {}", dep);
all_present = false;
} else {
println!("Found dependency: {}", dep);
}
}
all_present
}
"#;
write_and_check(code);
}
#[test]
fn test_parser_089_mut_ref_param_with_match() {
let code = r"
pub fun modify_and_check(value: &mut i32) -> bool {
*value += 1;
match *value {
1 => true,
_ => false,
}
}
";
write_and_check(code);
}
#[test]
fn test_parser_089_mixed_params_with_match() {
let code = r#"
pub fun mixed(owned: String, borrowed: &str, number: i32) -> bool {
match borrowed {
"test" => number > 0,
_ => false,
}
}
"#;
write_and_check(code);
}