1
use super::*;
2

            
3
2
async fn assert_reader_error(form: &str, message: &str) {
4
2
    let response = eval_value_of(form).await;
5
2
    assert!(
6
2
        response.contains(":error") && response.contains(message),
7
        "{form} must be a reader error mentioning {message:?}, got: {response}"
8
    );
9
2
}
10

            
11
#[tokio::test]
12
1
async fn t_and_every_spelling_of_nil_print_lowercase() {
13
1
    assert_values(&[
14
1
        ("t", "t"),
15
1
        ("nil", "nil"),
16
1
        ("()", "nil"),
17
1
        ("'()", "nil"),
18
1
        ("(list)", "nil"),
19
1
    ])
20
1
    .await;
21
1
}
22

            
23
#[tokio::test]
24
1
async fn scheme_boolean_literals_are_reader_errors() {
25
1
    assert_reader_error("#t", "#t is not nomiscript syntax; use t").await;
26
1
    assert_reader_error("#f", "#f is not nomiscript syntax; use nil").await;
27
1
}
28

            
29
#[tokio::test]
30
1
async fn t_and_nil_are_unique_objects() {
31
1
    assert_values(&[("(eql nil '())", "t"), ("(eq? t 't)", "t")]).await;
32
1
}
33

            
34
#[tokio::test]
35
1
async fn a_runtime_comparison_frame_carries_lowercase_t() {
36
1
    assert_values(&[("(> (rpc-protocol-version) 0)", "t")]).await;
37
1
}
38

            
39
#[tokio::test]
40
1
async fn empty_parens_still_serve_as_empty_parameter_and_binding_lists() {
41
1
    assert_values(&[
42
1
        ("(let () 3)", "3"),
43
1
        ("(let* () 3)", "3"),
44
1
        ("(funcall (lambda () 5))", "5"),
45
1
        ("(do () (t 7))", "7"),
46
1
    ])
47
1
    .await;
48
1
}
49

            
50
#[tokio::test]
51
1
async fn empty_constant_list_folds_are_nil() {
52
1
    assert_values(&[
53
1
        ("(filter (lambda (x) nil) (list 1 2))", "nil"),
54
1
        ("(null? (map '+ '()))", "t"),
55
1
        ("(append '() '())", "nil"),
56
1
        ("(reverse '())", "nil"),
57
1
    ])
58
1
    .await;
59
1
}
60

            
61
#[tokio::test]
62
1
async fn quoted_lists_print_through_one_printer() {
63
1
    assert_values(&[
64
1
        ("'(a . nil)", "\"(A)\""),
65
1
        ("'(1 . (2 3))", "\"(1 2 3)\""),
66
1
        ("'(1 . 2)", "\"(1 . 2)\""),
67
1
        ("'(1 2)", "\"(1 2)\""),
68
1
        ("'a", "\"A\""),
69
1
        ("'()", "nil"),
70
1
        ("':k", "\":K\""),
71
1
        ("'`(a)", "\"`(A)\""),
72
1
    ])
73
1
    .await;
74
1
}
75

            
76
#[tokio::test]
77
1
async fn a_quoted_datum_still_has_no_cell_representation() {
78
2
    for form in [
79
1
        "(list '(1) (rpc-protocol-version))",
80
1
        "(cons 'a (list (rpc-protocol-version)))",
81
1
    ] {
82
2
        let response = eval_value_of(form).await;
83
2
        assert!(
84
2
            response.contains("cannot compile to WASM stack value"),
85
1
            "{form}: {response}"
86
1
        );
87
1
    }
88
1
}
89

            
90
#[tokio::test]
91
1
async fn labels_produces_a_stack_value() {
92
1
    assert_values(&[
93
1
        ("(+ 1 (labels ((f (x) x)) (f 2)))", "3"),
94
1
        ("(let ((v (labels ((g () 4)) (g)))) v)", "4"),
95
1
        ("(labels ((f () 6)) (f))", "6"),
96
1
        ("(labels ((f (x) (+ x 1))) (f (rpc-protocol-version)))", "2"),
97
1
    ])
98
1
    .await;
99
1
}
100

            
101
#[tokio::test]
102
1
async fn the_empty_list_is_nil_to_if_null_and_length() {
103
1
    assert_values(&[
104
1
        ("(if '() 1 2)", "2"),
105
1
        ("(null? '())", "t"),
106
1
        ("(length '())", "0"),
107
1
    ])
108
1
    .await;
109
1
}
110

            
111
#[tokio::test]
112
1
async fn handler_case_catch_all_t_returns_nil() {
113
1
    assert_values(&[("(handler-case (error 'x \"m\") (t (e) nil))", "nil")]).await;
114
1
}