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
//! `#'x` reads as `(FUNCTION x)` exactly as `'x` reads as `(QUOTE x)` (plan L2-4).
6

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

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

            
12
21
fn whole(label: &'static str, forms: &[&str]) -> Row {
13
21
    row(label, &[&forms.join(" ")])
14
21
}
15

            
16
1
fn rows() -> Vec<Row> {
17
1
    vec![
18
1
        whole(
19
1
            "R4b",
20
1
            &[
21
1
                "(defun f (a) (+ a 1)) (labels ((f (a) (* a 10))) (list (funcall #'f 2) (funcall 'f 2)))",
22
1
            ],
23
1
        ),
24
1
        whole("car", &["(mapcar #'car (list (list 1 2) (list 3 4)))"]),
25
1
        whole("lambda", &["(funcall #'(lambda (x) (* x 2)) 4)"]),
26
1
        whole("apply", &["(apply #'+ (list 1 2))"]),
27
1
        whole("undefined", &["#'undefined-fn"]),
28
1
        whole("undefined-long", &["(function undefined-fn)"]),
29
1
        whole("quoted", &["'#'f"]),
30
1
        whole("alone", &["#'"]),
31
1
        whole("dangling", &["(#')"]),
32
1
        whole("hash", &["#t"]),
33
1
        whole(
34
1
            "car-long",
35
1
            &["(mapcar (function car) (list (list 1 2) (list 3 4)))"],
36
1
        ),
37
1
        whole("apply-long", &["(apply (function +) (list 1 2))"]),
38
1
        whole("funcall", &["(funcall #'+ 1 2)"]),
39
1
        whole("fold", &["(fold #'+ 0 (list 1 2 3))"]),
40
1
        whole("map", &["(map #'car (list (list 1 2) (list 3 4)))"]),
41
1
        whole(
42
1
            "filter",
43
1
            &["(list (filter #'not (list 1 nil 2)) (filter 'not (list 1 nil 2)))"],
44
1
        ),
45
1
        whole(
46
1
            "host",
47
1
            &["(list (funcall #'entity-count) (funcall 'entity-count))"],
48
1
        ),
49
1
        whole("scalar", &["(funcall (function index->scalar) 1)"]),
50
1
        whole("if", &["#'if"]),
51
1
        whole("when-long", &["(function when)"]),
52
1
        whole(
53
1
            "quoted-car",
54
1
            &["(mapcar 'car (list (list 1 2) (list 3 4)))"],
55
1
        ),
56
    ]
57
1
}
58

            
59
const NO_DEF: &str = "err: Compile error: 'UNDEFINED-FN' has no functio";
60

            
61
#[test]
62
1
fn sharp_quote_reads_as_function() {
63
1
    assert_pinned(
64
1
        &rows(),
65
1
        &[
66
1
            ("R4b", &["(20 3)"]),
67
1
            ("car", &["(1 3)"]),
68
1
            ("lambda", &["8"]),
69
1
            ("apply", &["3"]),
70
1
            ("undefined", &[NO_DEF]),
71
1
            ("undefined-long", &[NO_DEF]),
72
1
            ("quoted", &["(function f)"]),
73
1
            (
74
1
                "alone",
75
1
                &["err: error: in function designator | 1 | #' | ^"],
76
1
            ),
77
1
            (
78
1
                "dangling",
79
1
                &["err: error: in function designator | 1 | (#') | ^"],
80
1
            ),
81
1
            (
82
1
                "hash",
83
1
                &["err: error: #t is not nomiscript syntax; use t | "],
84
1
            ),
85
1
            ("car-long", &["(1 3)"]),
86
1
            ("apply-long", &["3"]),
87
1
            ("funcall", &["3"]),
88
1
            ("fold", &["6"]),
89
1
            ("map", &["(1 3)"]),
90
1
            ("filter", &["((nil) (nil))"]),
91
1
            ("host", &["(0 0)"]),
92
1
            ("scalar", &["1/1"]),
93
1
            ("if", &["err: Compile error: IF is a special operator, not"]),
94
1
            (
95
1
                "when-long",
96
1
                &["err: Compile error: WHEN is a macro, not a functi"],
97
1
            ),
98
1
            ("quoted-car", &["(1 3)"]),
99
1
        ],
100
1
    );
101
1
}