Lines
52.17 %
Functions
85.71 %
Branches
100 %
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
// Cranelift backend refuses to run under Miri.
#![cfg(not(miri))]
//! PERSIST SN-P rows: CL's `&key ((:keyword var) default)` lambda-list form
//! in DEFUN, LAMBDA, LABELS and DEFMACRO. Each SBCL value is next to its row.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, assert_pinned_wide, row};
struct Case {
label: &'static str,
units: &'static [&'static str],
pinned: &'static [&'static str],
}
const fn case(
) -> Case {
Case {
label,
units,
pinned,
const CASES: &[Case] = &[
// SBCL (1 5)
case(
"K1",
&["(defun f (&key ((:a x) 1)) x)", "(list (f) (f :a 5))"],
&["f", "(1 5)"],
),
// SBCL (7 7 3): mixed with a plain &key, &optional and &rest
"K2",
&[
"(defun f (o &optional (p 7) &key ((:a x) 1) (b 2)) (list p x b))",
"(f 0 7 :a 7 :b 3)",
],
&["f", "(7 7 3)"],
// SBCL (5 (:A 5))
"K3",
&["(defun f (&rest r &key ((:a x) 1)) (list x r))", "(f :a 5)"],
&["f", "(5 (:a 5))"],
// SBCL (5 2)
"K4",
"(defun f (&key ((:a x) 1) (b 2)) (list x b))",
"(f :b 2 :a 5)",
&["f", "(5 2)"],
// SBCL (0 5): no default is NIL
"K5",
&["(defun f (&key ((:a x))) (or x 0))", "(list (f) (f :a 5))"],
&["f", "(0 5)"],
// SBCL 5
"K6",
&["(funcall (lambda (&key ((:a x) 1)) x) :a 5)"],
&["5"],
"K8",
&["(defmacro m (&key ((:a x) 1)) x)", "(list (m) (m :a 5))"],
&["m", "(1 5)"],
// SBCL 6: a store to the renamed variable
"K16",
&["(defun f (&key ((:a x) 1)) (setf x (+ x 1)) x)", "(f :a 5)"],
&["f", "6"],
// SBCL 6
"K17",
&["(funcall (lambda (&key ((:a x) 1)) (setf x (+ x 1)) x) :a 5)"],
&["6"],
// SBCL 3: a macro-time lambda reads the renamed variable
"K18",
"(defmacro m () (funcall (lambda () (funcall (lambda (&key ((:a x) 1)) x) :a 3))))",
"(m)",
&["m", "3"],
// SBCL (1 5): the plain form is unchanged
"K15",
&["(defun f (&key (a 1)) a)", "(list (f) (f :a 5))"],
];
const ERROR_CASES: &[Case] = &[
// SBCL (1 5); LABELS takes no lambda-list keywords at all
"K7",
&["(labels ((g (&key ((:a x) 1)) x)) (list (g) (g :a 5)))"],
&["err: Compile error: LABELS: lambda list keywords not supported in this context"],
// SBCL error: :x is not the keyword of (:a x)
"K9",
&["(defun f (&key ((:a x) 1)) x)", "(f :x 5)"],
&["f", "err: Compile error: unknown keyword argument :X"],
// SBCL error: the two parameters answer to :a
"K10",
&["(defun f (&key ((:a x) 1) ((:a y) 2)) (list x y))"],
&["err: Compile error: DEFUN: duplicate keyword 'a'"],
// SBCL error: plain A is the keyword :a too
"K11",
&["(defun f (&key a ((:a x) 2)) (list a x))"],
// SBCL error: the variable is duplicated
"K12",
&["(defun f (&key ((:a x) 1) ((:b x) 2)) x)"],
&["err: Compile error: DEFUN: duplicate parameter 'x'"],
// SBCL accepts any symbol as the keyword name, (f 'a 5) gives 5; we require a keyword
"K13",
&["(defun f (&key ((a x) 1)) x)"],
&["err: Compile error: DEFUN: &key parameter must be (:keyword var), got (A X)"],
// SBCL accepts a supplied-p variable; nomiscript has none in any lambda list
"K14",
&["(defun f (&key ((:a x) 1 p)) (list x p))"],
"err: Compile error: DEFUN: &key parameter must be ((:keyword var) default), got ((:A X) 1 P)",
fn rows(cases: &[Case]) -> Vec<Row> {
cases.iter().map(|c| row(c.label, c.units)).collect()
fn pinned(cases: &[Case]) -> Vec<(&'static str, &'static [&'static str])> {
cases.iter().map(|c| (c.label, c.pinned)).collect()
#[test]
fn key_keyword_rows_read_as_pinned() {
assert_pinned(&rows(CASES), &pinned(CASES));
fn key_keyword_error_rows_read_as_pinned() {
assert_pinned_wide(&rows(ERROR_CASES), &pinned(ERROR_CASES), 120);