Lines
96.3 %
Functions
80 %
Branches
100 %
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
// Cranelift backend refuses to run under Miri.
#![cfg(not(miri))]
//! PERSIST rows: a LABELS function is named by its own name wherever it shows.
use nms::interpreter::Interpreter;
const LABELS_M: &str = "(labels ((m (x) (+ x 1))) (defun kd (y) (m y)))";
fn after(units: &[&str], last: &str) -> Result<String, String> {
let mut interp = Interpreter::new(false).expect("interpreter");
for unit in units {
interp.eval(unit).expect("setup");
}
interp
.eval(last)
.map(|_| String::new())
.map_err(|e| e.to_string())
#[test]
fn a_function_made_in_labels_is_named_by_its_name() {
interp.eval(LABELS_M).expect("defines");
let values = interp.eval("(describe 'kd)").expect("describes");
let text = format!("{values:?}");
assert!(text.contains("(LAMBDA (Y) (M Y))"), "{text}");
assert!(!text.contains("(LABELS"), "{text}");
fn a_function_designator_of_a_labels_function_outside_its_form_names_it() {
let error = after(
&["(defmacro m (x) `(* ,x 2))"],
"(let ((f (labels ((m (x) (+ x 1))) (lambda (y) (funcall (function m) y))))) (funcall f 10))",
)
.expect_err("refused");
assert_eq!(
error,
"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"
);