fn test_IR_EXPR_023_exec_function_call() {
let out = transpile_main(r#"exec("ls -la");"#);
assert!(out.contains("eval"), "Expected eval for exec() in:\n{out}");
}
#[test]
fn test_IR_EXPR_024_stdlib_function_call() {
let out = transpile_full(
r#"
fn main() {
string_trim(" hello ");
}
"#,
);
assert!(
out.contains("rash_string_trim"),
"Expected rash_string_trim in:\n{out}"
);
}
#[test]
fn test_IR_EXPR_025_non_stdlib_function_call() {
let out = transpile_full(
r#"
fn main() {
my_custom_fn("arg1");
}
fn my_custom_fn(s: &str) {}
"#,
);
assert!(
out.contains("my_custom_fn"),
"Expected my_custom_fn in:\n{out}"
);
}
#[test]
fn test_IR_EXPR_026_variable_expr() {
let out = transpile_full(
r#"
fn main() {
let greeting = "hi";
echo(greeting);
}
fn echo(msg: &str) {}
"#,
);
assert!(
out.contains("$greeting") || out.contains("\"$greeting\""),
"Expected $greeting reference in:\n{out}"
);
}
#[test]
fn test_IR_EXPR_027_literal_string() {
let out = transpile_main(r#"let name = "Alice";"#);
assert!(out.contains("Alice"), "Expected Alice in output:\n{out}");
}
#[test]
fn test_IR_EXPR_028_literal_integer() {
let out = transpile_main("let count = 99;");
assert!(out.contains("99"), "Expected 99 in output:\n{out}");
}
#[test]
fn test_IR_EXPR_029_literal_bool() {
let out = transpile_main("let flag = true;");
assert!(
out.contains("1") || out.contains("true"),
"Expected boolean true representation in:\n{out}"
);
}
#[test]
fn test_IR_EXPR_030_if_expr_as_condition() {
let out = transpile_full(
r#"
fn main() {
let a = 5;
let b = 10;
if a < b {
echo("less");
} else {
echo("not less");
}
}
fn echo(msg: &str) {}
"#,
);
assert!(out.contains("if"), "Expected if in:\n{out}");
assert!(out.contains("then"), "Expected then in:\n{out}");
assert!(out.contains("else"), "Expected else in:\n{out}");
assert!(out.contains("fi"), "Expected fi in:\n{out}");
}
#[test]
fn test_IR_EXPR_031_index_expr() {
let out = transpile_full(
r#"
fn main() {
let arr = [10, 20, 30];
let first = arr[0];
}
"#,
);
assert!(
out.contains("arr_0"),
"Expected arr_0 for array index in:\n{out}"
);
}
#[test]
fn test_IR_EXPR_032_format_concat_via_println() {
let out = transpile_full(
r#"
fn main() {
let name = "World";
println!("Hello {}", name);
}
"#,
);
assert!(
out.contains("echo") || out.contains("printf"),
"Expected echo or printf for println! in:\n{out}"
);
assert!(
out.contains("Hello") || out.contains("hello"),
"Expected Hello in output:\n{out}"
);
}
#[test]
fn test_IR_EXPR_033_nested_arithmetic() {
let out = transpile_full("fn main() { let a = 1; let b = 2; let c = 3; let x = (a + b) * c; }");
assert!(
out.contains("$(("),
"Expected arithmetic expansion in:\n{out}"
);
}
#[test]
fn test_IR_EXPR_034_multiple_binary_ops() {
let out = transpile_full(
r#"
fn main() {
let x = 10;
let y = 5;
let a = x + y;
let p = 20;
let q = 3;
let b = p - q;
let c = a * b;
}
"#,
);
assert!(
out.contains("$(("),
"Expected arithmetic expansion in:\n{out}"
);
}
#[test]
fn test_IR_EXPR_035_exec_effects_curl() {
let out = transpile_main(r#"exec("curl http://example.com");"#);
assert!(out.contains("eval"), "Expected eval for exec() in:\n{out}");
}
#[test]
fn test_IR_EXPR_036_method_call_expr() {
let result = crate::transpile(
r#"
fn main() {
let s = "hello";
let t = s.len();
}
"#,
&Config::default(),
);
assert!(
result.is_ok(),
"Method call should not cause transpile failure"
);
}
#[test]
fn test_IR_EXPR_037_div_by_zero_literal() {
let result = crate::transpile(
"fn main() { let a = 10; let b = 0; let x = a / b; }",
&Config::default(),
);
assert!(result.is_ok(), "Division by zero should still transpile");
}
#[test]
fn test_IR_EXPR_038_chained_shift() {
let out = transpile_full(
"fn main() { let a = 1; let b = 2; let c = 3; let x = a << b; let y = x << c; }",
);
assert!(out.contains("<<"), "Expected << operator in:\n{out}");
}
#[test]
fn test_IR_EXPR_039_comparison_in_while() {
let out = transpile_full(
r#"
fn main() {
let mut i = 0;
while i < 10 {
i = i + 1;
}
}
"#,
);
assert!(out.contains("while"), "Expected while in:\n{out}");
assert!(
out.contains("-lt"),
"Expected -lt in while condition:\n{out}"
);
}
#[test]
fn test_IR_EXPR_040_literal_bool_false() {
let out = transpile_main("let flag = false;");
assert!(
out.contains("0") || out.contains("false"),
"Expected boolean false representation in:\n{out}"
);
}