Lines
100 %
Functions
Branches
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
// Cranelift backend refuses to run under Miri.
#![cfg(not(miri))]
//! `#'x` reads as `(FUNCTION x)` exactly as `'x` reads as `(QUOTE x)` (plan L2-4).
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, row};
fn whole(label: &'static str, forms: &[&str]) -> Row {
row(label, &[&forms.join(" ")])
}
fn rows() -> Vec<Row> {
vec![
whole(
"R4b",
&[
"(defun f (a) (+ a 1)) (labels ((f (a) (* a 10))) (list (funcall #'f 2) (funcall 'f 2)))",
],
),
whole("car", &["(mapcar #'car (list (list 1 2) (list 3 4)))"]),
whole("lambda", &["(funcall #'(lambda (x) (* x 2)) 4)"]),
whole("apply", &["(apply #'+ (list 1 2))"]),
whole("undefined", &["#'undefined-fn"]),
whole("undefined-long", &["(function undefined-fn)"]),
whole("quoted", &["'#'f"]),
whole("alone", &["#'"]),
whole("dangling", &["(#')"]),
whole("hash", &["#t"]),
"car-long",
&["(mapcar (function car) (list (list 1 2) (list 3 4)))"],
whole("apply-long", &["(apply (function +) (list 1 2))"]),
whole("funcall", &["(funcall #'+ 1 2)"]),
whole("fold", &["(fold #'+ 0 (list 1 2 3))"]),
whole("map", &["(map #'car (list (list 1 2) (list 3 4)))"]),
"filter",
&["(list (filter #'not (list 1 nil 2)) (filter 'not (list 1 nil 2)))"],
"host",
&["(list (funcall #'entity-count) (funcall 'entity-count))"],
whole("scalar", &["(funcall (function index->scalar) 1)"]),
whole("if", &["#'if"]),
whole("when-long", &["(function when)"]),
"quoted-car",
&["(mapcar 'car (list (list 1 2) (list 3 4)))"],
]
const NO_DEF: &str = "err: Compile error: 'UNDEFINED-FN' has no functio";
#[test]
fn sharp_quote_reads_as_function() {
assert_pinned(
&rows(),
("R4b", &["(20 3)"]),
("car", &["(1 3)"]),
("lambda", &["8"]),
("apply", &["3"]),
("undefined", &[NO_DEF]),
("undefined-long", &[NO_DEF]),
("quoted", &["(function f)"]),
(
"alone",
&["err: error: in function designator | 1 | #' | ^"],
"dangling",
&["err: error: in function designator | 1 | (#') | ^"],
"hash",
&["err: error: #t is not nomiscript syntax; use t | "],
("car-long", &["(1 3)"]),
("apply-long", &["3"]),
("funcall", &["3"]),
("fold", &["6"]),
("map", &["(1 3)"]),
("filter", &["((nil) (nil))"]),
("host", &["(0 0)"]),
("scalar", &["1/1"]),
("if", &["err: Compile error: IF is a special operator, not"]),
"when-long",
&["err: Compile error: WHEN is a macro, not a functi"],
("quoted-car", &["(1 3)"]),
);