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))]
//! PERSIST rows with their Common Lisp values: the struct predicates and
//! accessors run the effects of their operand once, whatever the operand is.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, row};
const PT: &str = "(defstruct pt x)";
const N: &str = "(defvar *n* 0)";
fn rows() -> Vec<Row> {
vec![
row("O1", &[PT, "(pt-p (entity-count))"]),
row("O2", &[PT, "(let ((n (entity-count))) (if (pt-p n) 1 2))"]),
row(
"O3",
&[
PT,
"(defun kind (x) (if (pt-p x) 1 2))",
"(kind (entity-count))",
],
),
"O4",
"(defun kx (x) (if (pt-p x) (pt-x x) x))",
"(kx (+ 1 (entity-count)))",
"O5",
&[PT, N, "(pt-p (progn (setf *n* 5) (entity-count)))", "*n*"],
"O6",
N,
"(progn (setf (pt-x (make-pt :x (setf *n* 5))) 3) *n*)",
"O7",
"(defvar *p* (make-pt :x 1))",
"(defun pick () (setf *n* 5) *p*)",
"(progn (setf (pt-x (pick)) 3) *n*)",
"O8",
"(let ((p (make-pt :x 1))) (progn (setf (pt-x (progn (setf *n* 5) p)) 3) *n*))",
"O9",
"(defun raw () (make-pt :x (setf *n* 9)))",
"(pt-x (raw))",
"*n*",
"O10",
"(pt-x (make-pt :x 3))",
"(let ((p (make-pt :x 1))) (setf (pt-x p) 4) (pt-x p))",
]
}
/// CL: O1 nil, O2 2, O3 2, O4 1, O5 nil then *n* 5, O6 5, O7 5, O8 5, O9 9
/// then 9, O10 3 then 4.
const CL: &[(&str, &[&str])] = &[
("O1", &["pt", "nil"]),
("O2", &["pt", "2"]),
("O3", &["pt", "kind", "2"]),
("O4", &["pt", "kx", "1"]),
("O5", &["pt", "-", "nil", "5"]),
("O6", &["pt", "-", "5"]),
("O7", &["pt", "-", "-", "pick", "5"]),
("O8", &["pt", "-", "5"]),
("O9", &["pt", "-", "raw", "9", "9"]),
("O10", &["pt", "3", "4"]),
];
#[test]
fn every_row_reads_as_common_lisp() {
assert_pinned(&rows(), CL);