use std::process::Command;
fn ilo() -> Command {
Command::new(env!("CARGO_BIN_EXE_ilo"))
}
fn run(engine: &str, src: &str, entry: &str) -> String {
let out = ilo()
.args([src, engine, entry])
.output()
.expect("failed to run ilo");
assert!(
out.status.success(),
"ilo {engine} failed for `{src}`: stderr={}",
String::from_utf8_lossy(&out.stderr)
);
String::from_utf8_lossy(&out.stdout).trim().to_string()
}
const APPEND_NON_REBIND_PRESERVES_XS: &str = "f>L n;xs=[1,2,3];ys=+=xs 99;xs";
#[test]
fn append_non_rebind_preserves_xs_tree() {
assert_eq!(
run("--run-tree", APPEND_NON_REBIND_PRESERVES_XS, "f"),
"[1, 2, 3]"
);
}
#[test]
fn append_non_rebind_preserves_xs_vm() {
assert_eq!(
run("--run-vm", APPEND_NON_REBIND_PRESERVES_XS, "f"),
"[1, 2, 3]"
);
}
#[test]
#[cfg(feature = "cranelift")]
fn append_non_rebind_preserves_xs_cranelift() {
assert_eq!(
run("--run-cranelift", APPEND_NON_REBIND_PRESERVES_XS, "f"),
"[1, 2, 3]"
);
}
const APPEND_NON_REBIND_YS_GETS_NEW_ITEM: &str = "f>L n;xs=[1,2,3];ys=+=xs 99;ys";
#[test]
fn append_non_rebind_ys_gets_new_item_tree() {
assert_eq!(
run("--run-tree", APPEND_NON_REBIND_YS_GETS_NEW_ITEM, "f"),
"[1, 2, 3, 99]"
);
}
#[test]
fn append_non_rebind_ys_gets_new_item_vm() {
assert_eq!(
run("--run-vm", APPEND_NON_REBIND_YS_GETS_NEW_ITEM, "f"),
"[1, 2, 3, 99]"
);
}
#[test]
#[cfg(feature = "cranelift")]
fn append_non_rebind_ys_gets_new_item_cranelift() {
assert_eq!(
run("--run-cranelift", APPEND_NON_REBIND_YS_GETS_NEW_ITEM, "f"),
"[1, 2, 3, 99]"
);
}
const APPEND_NON_REBIND_BOTH_VISIBLE: &str =
"f>t;xs=[1,2,3];ys=+=xs 99;fmt \"{};{}\" (len xs) (len ys)";
#[test]
fn append_non_rebind_both_visible_tree() {
assert_eq!(
run("--run-tree", APPEND_NON_REBIND_BOTH_VISIBLE, "f"),
"3;4"
);
}
#[test]
fn append_non_rebind_both_visible_vm() {
assert_eq!(run("--run-vm", APPEND_NON_REBIND_BOTH_VISIBLE, "f"), "3;4");
}
#[test]
#[cfg(feature = "cranelift")]
fn append_non_rebind_both_visible_cranelift() {
assert_eq!(
run("--run-cranelift", APPEND_NON_REBIND_BOTH_VISIBLE, "f"),
"3;4"
);
}
const APPEND_REBIND_ACCUMULATOR: &str = "f>n;xs=[];@i 0..100{xs=+=xs i};len xs";
#[test]
fn append_rebind_accumulator_tree() {
assert_eq!(run("--run-tree", APPEND_REBIND_ACCUMULATOR, "f"), "100");
}
#[test]
fn append_rebind_accumulator_vm() {
assert_eq!(run("--run-vm", APPEND_REBIND_ACCUMULATOR, "f"), "100");
}
#[test]
#[cfg(feature = "cranelift")]
fn append_rebind_accumulator_cranelift() {
assert_eq!(
run("--run-cranelift", APPEND_REBIND_ACCUMULATOR, "f"),
"100"
);
}
const APPEND_NON_REBIND_TEXT: &str =
"f>t;xs=[\"a\",\"b\"];ys=+=xs \"c\";fmt \"{}|{}\" (cat xs \"\") (cat ys \"\")";
#[test]
fn append_non_rebind_text_tree() {
assert_eq!(run("--run-tree", APPEND_NON_REBIND_TEXT, "f"), "ab|abc");
}
#[test]
fn append_non_rebind_text_vm() {
assert_eq!(run("--run-vm", APPEND_NON_REBIND_TEXT, "f"), "ab|abc");
}
#[test]
#[cfg(feature = "cranelift")]
fn append_non_rebind_text_cranelift() {
assert_eq!(
run("--run-cranelift", APPEND_NON_REBIND_TEXT, "f"),
"ab|abc"
);
}
const APPEND_NON_REBIND_RC_GT_1: &str = "\
ident xs:L n>L n;xs\n\
f>L n;xs=[1,2,3];keep=ident xs;ys=+=xs 99;xs\n\
";
#[test]
fn append_non_rebind_rc_gt_1_tree() {
assert_eq!(
run("--run-tree", APPEND_NON_REBIND_RC_GT_1, "f"),
"[1, 2, 3]"
);
}
#[test]
fn append_non_rebind_rc_gt_1_vm() {
assert_eq!(run("--run-vm", APPEND_NON_REBIND_RC_GT_1, "f"), "[1, 2, 3]");
}
#[test]
#[cfg(feature = "cranelift")]
fn append_non_rebind_rc_gt_1_cranelift() {
assert_eq!(
run("--run-cranelift", APPEND_NON_REBIND_RC_GT_1, "f"),
"[1, 2, 3]"
);
}
const MSET_NON_REBIND_PRESERVES_M: &str = "f>n;m=mset mmap \"a\" 1;m2=mset m \"b\" 2;len (mkeys m)";
#[test]
fn mset_non_rebind_preserves_m_tree() {
assert_eq!(run("--run-tree", MSET_NON_REBIND_PRESERVES_M, "f"), "1");
}
#[test]
fn mset_non_rebind_preserves_m_vm() {
assert_eq!(run("--run-vm", MSET_NON_REBIND_PRESERVES_M, "f"), "1");
}
#[test]
#[cfg(feature = "cranelift")]
fn mset_non_rebind_preserves_m_cranelift() {
assert_eq!(
run("--run-cranelift", MSET_NON_REBIND_PRESERVES_M, "f"),
"1"
);
}
const MSET_NON_REBIND_M2_GETS_NEW_ENTRY: &str =
"f>n;m=mset mmap \"a\" 1;m2=mset m \"b\" 2;len (mkeys m2)";
#[test]
fn mset_non_rebind_m2_gets_new_entry_tree() {
assert_eq!(
run("--run-tree", MSET_NON_REBIND_M2_GETS_NEW_ENTRY, "f"),
"2"
);
}
#[test]
fn mset_non_rebind_m2_gets_new_entry_vm() {
assert_eq!(run("--run-vm", MSET_NON_REBIND_M2_GETS_NEW_ENTRY, "f"), "2");
}
#[test]
#[cfg(feature = "cranelift")]
fn mset_non_rebind_m2_gets_new_entry_cranelift() {
assert_eq!(
run("--run-cranelift", MSET_NON_REBIND_M2_GETS_NEW_ENTRY, "f"),
"2"
);
}
const MSET_NON_REBIND_TEXT_PRESERVES_M: &str = "\
f>t;m=mset mmap \"a\" \"first\";m2=mset m \"b\" \"second\";mget m \"a\" ?? \"miss\"\n\
";
#[test]
fn mset_non_rebind_text_preserves_m_tree() {
assert_eq!(
run("--run-tree", MSET_NON_REBIND_TEXT_PRESERVES_M, "f"),
"first"
);
}
#[test]
fn mset_non_rebind_text_preserves_m_vm() {
assert_eq!(
run("--run-vm", MSET_NON_REBIND_TEXT_PRESERVES_M, "f"),
"first"
);
}
#[test]
#[cfg(feature = "cranelift")]
fn mset_non_rebind_text_preserves_m_cranelift() {
assert_eq!(
run("--run-cranelift", MSET_NON_REBIND_TEXT_PRESERVES_M, "f"),
"first"
);
}