1
//! Coverage gaps in `compiler/expr.rs` — keyword expressions, lambda
2
//! literals at value position, quasiquote with various inner shapes,
3
//! quoted lists in different positions.
4

            
5
use super::common::{compile_and_validate, compile_expect_error};
6

            
7
#[test]
8
1
fn keyword_at_value_position() {
9
1
    compile_and_validate(":my-keyword");
10
1
}
11

            
12
#[test]
13
1
fn lambda_literal_at_value_position() {
14
    // Lambda at value position serializes its textual form (via
15
    // `compile_string` of `format_expr(expr)`).
16
1
    compile_and_validate("(lambda (x) x)");
17
1
}
18

            
19
#[test]
20
1
fn nested_quasiquote_with_unquote() {
21
1
    compile_and_validate("(defvar x 5) `(1 ,x 2)");
22
1
}
23

            
24
#[test]
25
1
fn nested_quasiquote_with_unquote_splicing() {
26
1
    compile_and_validate("(defvar xs '(1 2 3)) `(0 ,@xs 4)");
27
1
}
28

            
29
#[test]
30
1
fn quasiquote_nested_list() {
31
1
    compile_and_validate("(defvar x 5) `(1 (2 ,x))");
32
1
}
33

            
34
/// A quasiquote whose template holds a symbol expands to a list datum with
35
/// symbol members, a `$pair` chain of `$symbol` cells (plan 0014 Stage 8).
36
#[test]
37
1
fn quasiquote_with_a_symbol_member_is_a_list() {
38
1
    for src in [
39
1
        "(defvar x 5) `(a ,x b)",
40
1
        "(defvar xs '(1 2 3)) `(start ,@xs end)",
41
1
        "`(outer (inner 1))",
42
1
    ] {
43
3
        compile_and_validate(src);
44
    }
45
1
}
46

            
47
#[test]
48
1
fn quoted_constant_string() {
49
1
    compile_and_validate("'\"literal\"");
50
1
}
51

            
52
#[test]
53
1
fn quoted_bool() {
54
1
    compile_and_validate("'t");
55
1
}
56

            
57
#[test]
58
1
fn quoted_nil() {
59
1
    compile_and_validate("'nil");
60
1
}
61

            
62
#[test]
63
1
fn quoted_number_fraction() {
64
1
    compile_and_validate("'1/4");
65
1
}
66

            
67
/// `'(/ 1 4)` is a list datum whose head is the symbol `/`, not a fraction.
68
#[test]
69
1
fn quoted_division_form_is_a_symbol_list() {
70
1
    compile_and_validate("'(/ 1 4)");
71
1
}
72

            
73
#[test]
74
1
fn quoted_empty_list() {
75
1
    compile_and_validate("'()");
76
1
}
77

            
78
#[test]
79
1
fn unquote_outside_quasiquote_errors() {
80
1
    let err = compile_expect_error(",foo");
81
1
    assert!(
82
1
        err.contains("unquote") || err.contains("quasiquote"),
83
        "got: {err}"
84
    );
85
1
}
86

            
87
#[test]
88
1
fn empty_function_call_compiles_to_nil() {
89
    // Empty parens parse to an empty list which the compiler treats
90
    // as `nil` (the canonical empty-list representation).
91
1
    compile_and_validate("()");
92
1
}
93

            
94
#[test]
95
1
fn unbound_symbol_errors() {
96
1
    let err = compile_expect_error("xyzzy-undefined");
97
1
    assert!(
98
1
        err.contains("Undefined") || err.contains("xyzzy"),
99
        "got: {err}",
100
    );
101
1
}