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
//! PERSIST rows: a LABELS function is named by its own name wherever it shows.
6

            
7
use nms::interpreter::Interpreter;
8

            
9
const LABELS_M: &str = "(labels ((m (x) (+ x 1))) (defun kd (y) (m y)))";
10

            
11
1
fn after(units: &[&str], last: &str) -> Result<String, String> {
12
1
    let mut interp = Interpreter::new(false).expect("interpreter");
13
1
    for unit in units {
14
1
        interp.eval(unit).expect("setup");
15
    }
16
1
    interp
17
1
        .eval(last)
18
        .map(|_| String::new())
19
1
        .map_err(|e| e.to_string())
20
1
}
21

            
22
#[test]
23
1
fn a_function_made_in_labels_is_named_by_its_name() {
24
1
    let mut interp = Interpreter::new(false).expect("interpreter");
25
1
    interp.eval(LABELS_M).expect("defines");
26
1
    let values = interp.eval("(describe 'kd)").expect("describes");
27
1
    let text = format!("{values:?}");
28
1
    assert!(text.contains("(LAMBDA (Y) (M Y))"), "{text}");
29
1
    assert!(!text.contains("(LABELS"), "{text}");
30
1
}
31

            
32
#[test]
33
1
fn a_function_designator_of_a_labels_function_outside_its_form_names_it() {
34
1
    let error = after(
35
1
        &["(defmacro m (x) `(* ,x 2))"],
36
1
        "(let ((f (labels ((m (x) (+ x 1))) (lambda (y) (funcall (function m) y))))) (funcall f 10))",
37
1
    )
38
1
    .expect_err("refused");
39
1
    assert_eq!(
40
1
        error,
41
1
        "Compile error: M: a LABELS function does not outlive its form; a function or lambda that calls it cannot be used outside; not supported yet"
42
    );
43
1
}