This commit is contained in:
2026-01-21 17:05:30 +01:00
commit 67322381c3
59 changed files with 10421 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
use super::harness::*;
#[test]
fn if_then_true() {
expect_int("1 if 42 then", 42);
}
#[test]
fn if_then_false() {
let f = run("0 if 42 then");
assert!(f.stack().is_empty());
}
#[test]
fn if_then_with_base() {
expect_int("100 0 if 50 + then", 100);
}
#[test]
fn if_else_true() {
expect_int("1 if 42 else 99 then", 42);
}
#[test]
fn if_else_false() {
expect_int("0 if 42 else 99 then", 99);
}
#[test]
fn nested_tt() {
expect_int("1 if 1 if 100 else 200 then else 300 then", 100);
}
#[test]
fn nested_tf() {
expect_int("1 if 0 if 100 else 200 then else 300 then", 200);
}
#[test]
fn nested_f() {
expect_int("0 if 1 if 100 else 200 then else 300 then", 300);
}
#[test]
fn if_with_computation() {
expect_int("3 2 gt if 42 else 99 then", 42);
}
#[test]
fn missing_then() {
expect_error("1 if 42", "missing 'then'");
}
#[test]
fn deeply_nested() {
expect_int("1 if 1 if 1 if 42 then then then", 42);
}
#[test]
fn chained_conditionals() {
// First if leaves nothing, second if runs
let f = run("0 if 1 then 1 if 42 then");
assert_eq!(stack_int(&f), 42);
}