fn test_IRPAT_018_let_match_string_patterns() {
let code = r#"
fn main() {
let cmd = "start";
let result = match cmd {
"start" => 1,
"stop" => 2,
_ => 0,
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "String patterns: {out}");
}
#[test]
fn test_IRPAT_019_match_returns_integers_in_fn() {
let code = r#"
fn score(x: i32) -> i32 {
match x {
1 => 100,
2 => 200,
_ => 0,
}
}
fn main() {
let s = score(2);
}
"#;
let out = transpile_ok(code);
assert!(out.contains("score"), "Function score should exist: {out}");
}
#[test]
fn test_IRPAT_020_match_variable_binding_pattern() {
let code = r#"
fn main() {
let x = 5;
let result = match x {
n => n,
};
}
"#;
let result = transpile_result(code);
assert!(result.is_ok(), "Variable binding: {:?}", result.err());
}
#[test]
fn test_IRPAT_021_match_u32_literal_pattern() {
let code = r#"
fn main() {
let x = 42;
let result = match x {
42 => "found",
_ => "not found",
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "U32 pattern: {out}");
}
#[test]
fn test_IRPAT_022_no_range_patterns_uses_case() {
let code = r#"
fn main() {
let x = 1;
let result = match x {
1 => "one",
2 => "two",
_ => "other",
};
}
"#;
let out = transpile_ok(code);
assert!(
out.contains("case") || out.contains("result="),
"Case statement: {out}"
);
}
#[test]
fn test_IRPAT_023_range_patterns_uses_if_chain() {
let code = r#"
fn main() {
let x = 5;
let result = match x {
1..=3 => "low",
_ => "other",
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Range if-chain: {out}");
}
#[test]
fn test_IRPAT_024_match_bool_true_pattern() {
let code = r#"
fn main() {
let b = true;
let result = match b {
true => 1,
_ => 0,
};
}
"#;
let result = transpile_result(code);
assert!(result.is_ok(), "Bool true pattern: {:?}", result.err());
}
#[test]
fn test_IRPAT_025_standalone_range_match() {
let code = r#"
fn main() {
let x = 5;
match x {
1..=3 => println!("low"),
4..=6 => println!("mid"),
_ => println!("high"),
};
}
"#;
let out = transpile_ok(code);
assert!(
out.contains("low") || out.contains("mid") || out.contains("high"),
"Range match: {out}"
);
}
#[test]
fn test_IRPAT_026_range_match_in_function_context() {
let code = r#"
fn classify(n: i32) -> i32 {
match n {
0..=9 => 1,
10..=99 => 2,
_ => 3,
}
}
fn main() {
let c = classify(50);
}
"#;
let out = transpile_ok(code);
assert!(out.contains("classify"), "Function with range: {out}");
}
#[test]
fn test_IRPAT_027_multiple_range_patterns_for_let() {
let code = r#"
fn main() {
let x = 50;
let result = match x {
0..=9 => "single",
10..=99 => "double",
_ => "large",
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Multiple ranges: {out}");
}
#[test]
fn test_IRPAT_028_range_match_with_wildcard_fallback() {
let code = r#"
fn main() {
let x = 50;
let result = match x {
1..=10 => "range",
_ => "default",
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Wildcard in range: {out}");
}
#[test]
fn test_IRPAT_029_match_with_empty_block_arm() {
let code = r#"
fn main() {
let x = 1;
match x {
1 => {},
_ => {},
};
}
"#;
let result = transpile_result(code);
assert!(result.is_ok(), "Empty block arms: {:?}", result.err());
}
#[test]
fn test_IRPAT_030_let_if_multi_stmt_then_branch() {
let code = r#"
fn main() {
let x = 5;
let result = if x > 3 {
let tmp = 10;
tmp
} else {
0
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Multi-stmt if: {out}");
}
#[test]
fn test_IRPAT_031_fn_returning_range_match() {
let code = r#"
fn grade(score: i32) -> i32 {
match score {
90..=100 => 4,
80..=89 => 3,
70..=79 => 2,
_ => 1,
}
}
fn main() {
let g = grade(85);
}
"#;
let out = transpile_ok(code);
assert!(out.contains("grade"), "Grade function: {out}");
}
#[test]
fn test_IRPAT_032_match_i32_negative() {
let code = r#"
fn main() {
let x = -1;
let result = match x {
-1 => "neg_one",
0 => "zero",
_ => "other",
};
}
"#;
let result = transpile_result(code);
assert!(result.is_ok(), "Negative i32 match: {:?}", result.err());
}
#[test]
fn test_IRPAT_033_deeply_nested_if_else_expr() {
let code = r#"
fn main() {
let x = 5;
let result = if x > 10 {
"big"
} else if x > 5 {
"medium"
} else if x > 0 {
"small"
} else {
"zero"
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Deep if-else: {out}");
}
#[test]
fn test_IRPAT_034_fn_returning_if_expr() {
let code = r#"
fn pick(x: i32) -> i32 {
if x > 0 { 1 } else { 0 }
}
fn main() {
let p = pick(5);
}
"#;
let out = transpile_ok(code);
assert!(out.contains("pick"), "Function returning if expr: {out}");
}
#[test]
fn test_IRPAT_035_fn_returning_nested_if_expr() {
let code = r#"
fn classify(x: i32) -> i32 {
if x > 10 { 3 } else if x > 5 { 2 } else { 1 }
}
fn main() {
let c = classify(7);
}
"#;
let out = transpile_ok(code);
assert!(out.contains("classify"), "Nested if-expr return: {out}");
}
#[test]
fn test_IRPAT_036_match_multiple_guards() {
let code = r#"
fn main() {
let x = 5;
let result = match x {
n if n > 10 => "big",
n if n > 5 => "medium",
_ => "small",
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Multiple guards: {out}");
}
#[test]
fn test_IRPAT_037_match_mixed_range_and_literal() {
let code = r#"
fn main() {
let x = 5;
let result = match x {
1..=3 => "range",
5 => "five",
_ => "other",
};
}
"#;
let result = transpile_result(code);
assert!(result.is_ok(), "Mixed range/literal: {:?}", result.err());
}
#[test]
fn test_IRPAT_038_let_if_with_multi_stmt_else() {
let code = r#"
fn main() {
let x = 5;
let result = if x > 3 {
let a = 1;
a
} else {
let b = 2;
b
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Multi-stmt if-else: {out}");
}
#[test]
fn test_IRPAT_039_standalone_match_in_function_with_ranges() {
let code = r#"
fn process(n: i32) {
match n {
1..=10 => println!("low"),
_ => println!("high"),
};
}
fn main() {
process(5);
}
"#;
let out = transpile_ok(code);
assert!(out.contains("process"), "Standalone match fn: {out}");
}
#[test]
fn test_IRPAT_040_large_match_many_arms() {
let code = r#"
fn main() {
let x = 3;
let result = match x {
1 => "one",
2 => "two",
3 => "three",
4 => "four",
5 => "five",
_ => "other",
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Large match: {out}");
}
#[test]
fn test_IRPAT_041_let_if_expr_non_function_call_then() {
let code = r#"
fn main() {
let x = 5;
let result = if x > 3 { "big" } else { "small" };
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Simple if-expr: {out}");
}
#[test]
fn test_IRPAT_042_let_if_expr_non_function_call_else() {
let code = r#"
fn main() {
let flag = true;
let result = if flag { 1 } else { 0 };
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Bool if-expr: {out}");
}
#[test]
fn test_IRPAT_043_triple_nested_if_else_expr() {
let code = r#"
fn main() {
let x = 5;
let result = if x > 10 {
"very big"
} else if x > 7 {
"big"
} else if x > 3 {
"medium"
} else {
"small"
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Triple nested if: {out}");
}
#[test]
fn test_IRPAT_044_fn_return_simple_if_expr() {
let code = r#"
fn is_positive(n: i32) -> i32 {
if n > 0 { 1 } else { 0 }
}
fn main() {
let r = is_positive(5);
}
"#;
let out = transpile_ok(code);
assert!(out.contains("is_positive"), "Return if-expr: {out}");
}
#[test]
fn test_IRPAT_045_fn_return_triple_nested_if_expr() {
let code = r#"
fn tier(x: i32) -> i32 {
if x > 100 { 3 } else if x > 50 { 2 } else if x > 10 { 1 } else { 0 }
}
fn main() {
let t = tier(75);
}
"#;
let out = transpile_ok(code);
assert!(out.contains("tier"), "Triple nested return if: {out}");
}
#[test]
fn test_IRPAT_046_range_match_fn_wildcard_body() {
let code = r#"
fn bucket(n: i32) -> i32 {
match n {
0..=10 => 1,
11..=20 => 2,
_ => 0,
}
}
fn main() {
let b = bucket(15);
}
"#;
let out = transpile_ok(code);
assert!(out.contains("bucket"), "Range match fn wildcard: {out}");
}
#[test]
fn test_IRPAT_047_range_match_for_let_only_wildcard() {
let code = r#"
fn main() {
let x = 5;
let result = match x {
1..=3 => "low",
_ => "other",
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Range let wildcard: {out}");
}
#[test]
fn test_IRPAT_048_match_arm_multi_stmt_other_last() {
let code = r#"
fn main() {
let x = 1;
let result = match x {
1 => {
let tmp = 10;
let val = tmp;
val
},
_ => 0,
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Multi-stmt other last: {out}");
}
#[test]
fn test_IRPAT_049_exclusive_range_pattern() {
let code = r#"
fn main() {
let x = 5;
let result = match x {
1..10 => "single_digit",
_ => "other",
};
}
"#;
let result = transpile_result(code);
assert!(result.is_ok() || result.is_err(), "Exclusive range: handled");
}
#[test]
fn test_IRPAT_050_let_if_no_else_branch() {
let code = r#"
fn main() {
let x = 5;
if x > 3 {
let y = 1;
}
}
"#;
let out = transpile_ok(code);
assert!(out.contains("#!/bin/sh"), "No else: {out}");
}
#[test]
fn test_IRPAT_051_multi_stmt_return_last() {
let code = r#"
fn compute(x: i32) -> i32 {
let result = match x {
1 => {
let a = 10;
let b = 20;
return a
},
_ => 0,
};
result
}
fn main() {
let r = compute(1);
}
"#;
let result = transpile_result(code);
assert!(result.is_ok() || result.is_err(), "Multi return: handled");
}
#[test]
fn test_IRPAT_052_multi_stmt_if_last() {
let code = r#"
fn main() {
let x = 1;
let flag = true;
let result = match x {
1 => {
let tmp = 5;
let tmp2 = 6;
if flag {
"yes"
} else {
"no"
}
},
_ => "default",
};
}
"#;
let out = transpile_ok(code);
assert!(out.contains("result="), "Multi-stmt if last: {out}");
}