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
        ("'(1 . (2 3))", "(1 2 3)"),
65
1
        ("'(1 . nil)", "(1)"),
66
1
        ("'(1 2)", "(1 2)"),
67
1
        ("'a", "A"),
68
1
        ("'()", "nil"),
69
1
        ("':k", ":K"),
70
1
        ("'`(a)", "\"`(A)\""),
71
1
        ("'(a . nil)", "(A)"),
72
1
    ])
73
1
    .await;
74
    // A non-list tail has no `$pair` cell representation (plan 0014 Stage 1):
75
    // the structured rejection, never a printed string.
76
1
    let response = eval_value_of("'(1 . 2)").await;
77
1
    assert!(
78
1
        response.contains("'(1 . 2) has no list cell representation"),
79
1
        "{response}"
80
1
    );
81
1
}
82

            
83
#[tokio::test]
84
1
async fn a_quoted_symbol_rides_a_list_cell() {
85
    // A nested constant LIST materializes as a real `$pair` chain (ADR-0033
86
    // Phase 6 — see `phase6_anyref_decode_tests`), and a quoted symbol rides
87
    // a symbol cell beside it (plan 0014 Stage 8).
88
1
    assert_values(&[("(cons 'a (list (rpc-protocol-version)))", "(A 1)")]).await;
89
1
}
90

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

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

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