1
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
2
// Cranelift backend refuses to run under Miri.
3
#![cfg(not(miri))]
4

            
5
//! `BEGIN` is not a form: a user macro of that name is an ordinary macro,
6
//! never read as a `PROGN` by divergence or arm classification.
7

            
8
use nms::interpreter::Interpreter;
9
use scripting::nomiscript::{Number, Value};
10

            
11
2
fn eval_last(src: &str) -> Value {
12
2
    let mut interp = Interpreter::new(false).unwrap();
13
2
    let results = interp
14
2
        .eval(src)
15
        .unwrap_or_else(|e| panic!("eval {src:?}: {e}"));
16
2
    results
17
2
        .into_iter()
18
2
        .next_back()
19
        .unwrap_or_else(|| panic!("eval {src:?} produced no value"))
20
2
}
21

            
22
#[test]
23
1
fn a_begin_macro_hiding_a_return_from_does_not_end_the_block() {
24
1
    assert_eq!(
25
1
        eval_last(r#"(defmacro begin (&rest body) 7) (block b (begin (return-from b 1)) "s")"#),
26
1
        Value::String("s".to_string())
27
    );
28
1
}
29

            
30
#[test]
31
1
fn a_begin_macro_ending_in_nil_is_not_a_nil_arm() {
32
1
    assert_eq!(
33
1
        eval_last(
34
1
            r#"(defmacro begin (&rest body) 7) (if (> (entity-count) 2) 5 (begin (print "y") nil))"#
35
1
        ),
36
1
        Value::Number(Number::Index(7))
37
    );
38
1
}