#![allow(missing_docs)]
use assert_cmd::Command;
fn ruchy_cmd() -> Command {
assert_cmd::cargo::cargo_bin_cmd!("ruchy")
}
#[test]
fn test_issue_39_match_with_if_else_in_arm() {
let code = r#"
enum Result {
Ok(i32),
Err(String)
}
fun test() {
match Result::Ok(42) {
Result::Ok(x) => {
if x > 0 {
println("positive")
} else {
println("negative")
}
},
Result::Err(msg) => println(msg)
}
}
test()
"#;
ruchy_cmd().arg("-e").arg(code).assert().success(); }
#[test]
#[ignore = "Box in enum variants not fully supported"]
fn test_issue_39_algorithm_w_lookup_pattern() {
let code = r#"
enum TypeEnv {
Empty,
Extend(String, Box<TypeEnv>)
}
enum InferResult {
Success,
Failure(String)
}
fun lookup(env: TypeEnv, name: String) -> InferResult {
match env {
TypeEnv::Empty => InferResult::Failure("Not found".to_string()),
TypeEnv::Extend(var, rest) => {
if var == name {
InferResult::Success
} else {
lookup(*rest, name)
}
}
}
}
fun main() {
let env = TypeEnv::Extend("x".to_string(), Box::new(TypeEnv::Empty));
let result = lookup(env, "x".to_string());
println("Done");
}
main();
"#;
ruchy_cmd().arg("-e").arg(code).assert().success();
}
#[test]
fn test_issue_39_match_with_nested_if_else_if() {
let code = r#"
enum Color {
RGB(i32, i32, i32)
}
fun classify(c: Color) {
match c {
Color::RGB(r, g, b) => {
if r > 200 {
println("bright red")
} else if g > 200 {
println("bright green")
} else if b > 200 {
println("bright blue")
} else {
println("dark")
}
}
}
}
classify(Color::RGB(255, 0, 0))
"#;
ruchy_cmd().arg("-e").arg(code).assert().success();
}