Lines
62.07 %
Functions
88.89 %
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-0 rows: the CL string natives (CONCATENATE, PRINC-TO-STRING,
//! FORMAT) and the rewritten string sample, pinned at today's values with the
//! SBCL value next to each row. SN-1..SN-4 flip them.
#[path = "persist/rows.rs"]
mod persist;
use persist::{Row, assert_pinned, row};
const NO_CONCATENATE: &str = "err: Undefined symbol: CONCATENATE";
const NO_PRINC: &str = "err: Undefined symbol: PRINC-TO-STRING";
const NO_PRIN1: &str = "err: Undefined symbol: PRIN1-TO-STRING";
const NO_FORMAT: &str = "err: Undefined symbol: FORMAT";
const NO_DATE: &str = "err: Undefined symbol: TRANSACTION-DATE";
struct Case {
label: &'static str,
units: &'static [&'static str],
pinned: &'static [&'static str],
}
const fn case(
) -> Case {
Case {
label,
units,
pinned,
const MAKE_GREETING: &str =
"(defun make-greeting (name) (concatenate 'string \"Hello, \" name \"!\"))";
const FORMAT_AMOUNT: &str = "(defun format-amount (amount currency) \
(concatenate 'string (princ-to-string amount) \" \" currency))";
const SPLIT_CSV: &str = "(defun split->csv (s) (format nil \"~{~a~^,~}\" \
(list (split-account-id s) (split-amount s) (split-commodity-id s))))";
const PRINT_SPLIT: &str = "(defun print-split (s) (print (concatenate 'string \" \" \
(split-account-id s) \" \" (format-amount (split-amount s) (split-commodity-id s)))))";
const PRINT_TX: &str = "(defun print-transaction (tx) \
(print (format nil \"~a: ~a\" (transaction-date tx) (transaction-note tx))) \
(mapc #'print-split (split:list-for-transaction tx)))";
const CONCATENATE_CASES: &[Case] = &[
// SBCL "Hello, Ray!"
case(
"S1",
&["(concatenate 'string \"Hello, \" \"Ray\" \"!\")"],
&[NO_CONCATENATE],
),
"S2",
&[
"(let ((s (if (< (entity-count) 1) \"Ray\" \"Bob\"))) (concatenate 'string \"Hello, \" s \"!\"))",
],
// SBCL "ab"
"S3",
&["(concatenate 'string \"a\" nil \"b\")"],
// SBCL TYPE-ERROR at run time
case("S4", &["(concatenate 'string \"a\" 1)"], &[NO_CONCATENATE]),
// SBCL ""
case("S5", &["(concatenate 'string)"], &[NO_CONCATENATE]),
// SBCL (#\a #\b)
"S6",
&["(concatenate 'list \"a\" \"b\")"],
];
const PRINC_CASES: &[Case] = &[
// SBCL "5"
case("P1", &["(princ-to-string 5)"], &[NO_PRINC]),
// SBCL "1/2"
case("P2", &["(princ-to-string 1/2)"], &[NO_PRINC]),
// SBCL "K"
case("P3", &["(princ-to-string :k)"], &[NO_PRINC]),
// SBCL "NIL"
case("P4", &["(princ-to-string nil)"], &[NO_PRINC]),
// SBCL "(1 a B C NIL T)"
"P5",
&["(princ-to-string (list 1 \"a\" :b 'c nil t))"],
&[NO_PRINC],
// SBCL "x"
case("P6", &["(princ-to-string \"x\")"], &[NO_PRINC]),
// SBCL "0"
case("P7", &["(princ-to-string (entity-count))"], &[NO_PRINC]),
// SBCL "\"x\"": PRIN1 stays out of the plan
case("P8", &["(prin1-to-string \"x\")"], &[NO_PRIN1]),
// SBCL "#<FUNCTION (LAMBDA () ...)>"
case("P9", &["(princ-to-string (lambda () 1))"], &[NO_PRINC]),
const FORMAT_CASES: &[Case] = &[
// SBCL "1/2 USD"
case("F1", &["(format nil \"~a ~a\" 1/2 \"USD\")"], &[NO_FORMAT]),
// SBCL "a,1,B"
"F2",
&["(format nil \"~{~a~^,~}\" (list \"a\" 1 :b))"],
&[NO_FORMAT],
// SBCL "3 items" and a newline
case("F3", &["(format nil \"~d items~%\" 3)"], &[NO_FORMAT]),
// SBCL "A=1, B=2"
"F4",
&["(format nil \"~{~a=~a~^, ~}\" (list :a 1 :b 2))"],
case("F5", &["(format nil \"~a\" (entity-count))"], &[NO_FORMAT]),
case("F6", &["(format nil \"~{~a~^,~}\" nil)"], &[NO_FORMAT]),
// SBCL "~"
case("F7", &["(format nil \"~~\")"], &[NO_FORMAT]),
// SBCL FORMAT-ERROR at run time
case("F8", &["(format nil \"~a\")"], &[NO_FORMAT]),
// SBCL "\"x\""
case("F9", &["(format nil \"~s\" \"x\")"], &[NO_FORMAT]),
// SBCL "0,2"
"F10",
&["(format nil \"~{~a~^,~}\" (list (entity-count) 2))"],
// SBCL "x|7"
case("F11", &["(format nil \"~A|~D\" \"x\" 7)"], &[NO_FORMAT]),
// SBCL "1"
"F12",
&["(let ((c \"~a\")) (format nil c 1))"],
"F13",
&["(format nil \"~{~a=~a~^, ~}\" (list :a 1 :b))"],
case("F14", &["(format nil \"x\" 1 2)"], &[NO_FORMAT]),
// SBCL prints 1 and returns NIL
case("F15", &["(format t \"~a\" 1)"], &[NO_FORMAT]),
const SAMPLE_CASES: &[Case] = &[
// SBCL "Hello, World!"
"SA1",
&[MAKE_GREETING, "(make-greeting \"World\")"],
&["make-greeting", NO_CONCATENATE],
// SBCL "25/2 USD"
"SA2",
&[FORMAT_AMOUNT, "(format-amount 25/2 \"USD\")"],
&["format-amount", NO_CONCATENATE],
// SBCL "acc-1,25/2,cur-1" for a split of acc-1, 25/2 and cur-1; lazy as SA4
case("SA3", &[SPLIT_CSV], &["split->csv"]),
// SBCL prints "<date>: Lunch" then the two split lines; the defuns compile
// lazily, so only a call (db test, SN-4) meets the missing names
"SA4",
&[PRINT_SPLIT, PRINT_TX],
&["print-split", "print-transaction"],
// SBCL has no such function; the accessor is the SN-3 addition
case("TD", &["(transaction-date 1)"], &[NO_DATE]),
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 concatenate_rows_read_as_pinned() {
assert_pinned(&rows(CONCATENATE_CASES), &pinned(CONCATENATE_CASES));
fn princ_rows_read_as_pinned() {
assert_pinned(&rows(PRINC_CASES), &pinned(PRINC_CASES));
fn format_rows_read_as_pinned() {
assert_pinned(&rows(FORMAT_CASES), &pinned(FORMAT_CASES));
fn sample_rows_read_as_pinned() {
assert_pinned(&rows(SAMPLE_CASES), &pinned(SAMPLE_CASES));