use std::fs;
use tishlang_bytecode::{compile, compile_unoptimized};
use tishlang_vm::run;
#[test]
fn break_continue_fixture_runs_on_vm() {
let path = format!(
"{}/../../tests/core/break_continue.tish",
env!("CARGO_MANIFEST_DIR")
);
let src = fs::read_to_string(&path).unwrap();
let prog = tishlang_parser::parse(&src).expect("parse");
let chunk = compile_unoptimized(&prog).expect("compile");
run(&chunk).expect("VM run");
}
#[test]
fn mutation_vm_ast_opt_without_peephole() {
let path = format!(
"{}/../../tests/core/mutation.tish",
env!("CARGO_MANIFEST_DIR")
);
let src = fs::read_to_string(&path).unwrap();
let mut prog = tishlang_parser::parse(&src).expect("parse");
tishlang_opt::optimize(&mut prog);
let chunk = compile_unoptimized(&prog).expect("compile");
run(&chunk).expect("VM");
}
#[test]
fn mutation_vm_ast_opt_with_peephole() {
let path = format!(
"{}/../../tests/core/mutation.tish",
env!("CARGO_MANIFEST_DIR")
);
let src = fs::read_to_string(&path).unwrap();
let mut prog = tishlang_parser::parse(&src).expect("parse");
tishlang_opt::optimize(&mut prog);
let chunk = compile(&prog).expect("compile");
run(&chunk).expect("VM");
}
#[test]
fn do_while_continue_does_not_crash_vm() {
let src = "let d = 0\n\
do {\n\
d = d + 1\n\
if (d === 2) { continue }\n\
} while (d < 5)\n";
let prog = tishlang_parser::parse(src).expect("parse");
run(&compile_unoptimized(&prog).expect("compile (unopt)")).expect("VM run unoptimized");
run(&compile(&prog).expect("compile (opt)")).expect("VM run optimized");
}