Lines
90.91 %
Functions
60 %
Branches
100 %
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
// Cranelift backend refuses to run under Miri.
#![cfg(not(miri))]
//! `BEGIN` is not a form: a user macro of that name is an ordinary macro,
//! never read as a `PROGN` by divergence or arm classification.
use nms::interpreter::Interpreter;
use scripting::nomiscript::{Number, Value};
fn eval_last(src: &str) -> Value {
let mut interp = Interpreter::new(false).unwrap();
let results = interp
.eval(src)
.unwrap_or_else(|e| panic!("eval {src:?}: {e}"));
results
.into_iter()
.next_back()
.unwrap_or_else(|| panic!("eval {src:?} produced no value"))
}
#[test]
fn a_begin_macro_hiding_a_return_from_does_not_end_the_block() {
assert_eq!(
eval_last(r#"(defmacro begin (&rest body) 7) (block b (begin (return-from b 1)) "s")"#),
Value::String("s".to_string())
);
fn a_begin_macro_ending_in_nil_is_not_a_nil_arm() {
eval_last(
r#"(defmacro begin (&rest body) 7) (if (> (entity-count) 2) 5 (begin (print "y") nil))"#
),
Value::Number(Number::Index(7))