1
// Skipped under Miri: these tests compile+run wasm via wasmtime, whose
2
// Cranelift backend refuses to run under Miri.
3
#![cfg(not(miri))]
4

            
5
//! PERSIST rows with their Common Lisp values: the function operand of a
6
//! `FUNCALL` may be a conditional choosing between functions.
7

            
8
#[path = "persist/rows.rs"]
9
mod persist;
10

            
11
use persist::{Row, assert_pinned, row};
12

            
13
const TRUE: &str = "(> (entity-count) -1)";
14
const FALSE: &str = "(> (entity-count) 99)";
15

            
16
1
fn rows() -> Vec<Row> {
17
1
    vec![
18
1
        row(
19
1
            "F1",
20
1
            &[&format!(
21
1
                "(funcall (if {TRUE} (lambda () 1) (lambda () 2)))"
22
1
            )],
23
1
        ),
24
1
        row(
25
1
            "F2",
26
1
            &[&format!(
27
1
                "(funcall (cond ({FALSE} (lambda (x) x)) (t (lambda (x) (* x 2)))) 3)"
28
1
            )],
29
1
        ),
30
1
        row(
31
1
            "F3",
32
1
            &[
33
1
                &format!("(funcall (if {TRUE} (lambda () 1) (lambda () 2)))"),
34
1
                &format!("(funcall (if {FALSE} (lambda () 1) (lambda () 2)))"),
35
1
            ],
36
1
        ),
37
1
        row(
38
1
            "F4",
39
1
            &[&format!(
40
1
                "(funcall (if {TRUE} (lambda () 1) (lambda (x) 2)))"
41
1
            )],
42
1
        ),
43
1
        row(
44
1
            "F5",
45
1
            &[&format!(
46
1
                "(funcall (if {TRUE} (lambda () 1) (lambda () \"s\")))"
47
1
            )],
48
1
        ),
49
1
        row(
50
1
            "F6",
51
1
            &[&format!(
52
1
                "(let ((f (if {TRUE} (lambda () 1) (lambda () 2)))) (funcall f))"
53
1
            )],
54
1
        ),
55
1
        row(
56
1
            "F7",
57
1
            &[&format!(
58
1
                "(funcall (unless {FALSE} (lambda (x) (+ x 1))) 4)"
59
1
            )],
60
1
        ),
61
    ]
62
1
}
63

            
64
/// CL: F1 1, F2 6, F3 1 then 2, F4 1, F5 1, F6 1, F7 5. A conditional whose
65
/// arms differ in type, or that may be nil, is an any value, called with a
66
/// run-time check.
67
const ROWS: &[(&str, &[&str])] = &[
68
    ("F1", &["1"]),
69
    ("F2", &["6"]),
70
    ("F3", &["1", "2"]),
71
    ("F4", &["1"]),
72
    ("F5", &["1"]),
73
    ("F6", &["1"]),
74
    ("F7", &["5"]),
75
];
76

            
77
#[test]
78
1
fn every_row_reads_as_common_lisp() {
79
1
    assert_pinned(&rows(), ROWS);
80
1
}