1
//! `COMPILE` / `EVAL` / `DESCRIBE` special forms.
2

            
3
use super::common::{compile_and_validate, compile_expect_error};
4

            
5
#[test]
6
1
fn eval_with_quoted_constant() {
7
1
    compile_and_validate("(eval '(+ 1 2))");
8
1
}
9

            
10
#[test]
11
1
fn eval_with_quoted_arithmetic() {
12
1
    compile_and_validate("(eval '(* 3 4))");
13
1
}
14

            
15
#[test]
16
1
fn eval_wrong_arity_errors() {
17
1
    let err = compile_expect_error("(eval)");
18
1
    assert!(err.contains("eval"), "got: {err}");
19
1
}
20

            
21
#[test]
22
1
fn compile_quoted_user_function() {
23
1
    compile_and_validate("(defun greet () \"hello\") (compile 'greet)");
24
1
}
25

            
26
#[test]
27
1
fn compile_unknown_symbol_errors() {
28
1
    let err = compile_expect_error("(compile 'no-such-function)");
29
1
    assert!(
30
1
        err.contains("Undefined") || err.contains("no-such-function"),
31
        "got: {err}",
32
    );
33
1
}
34

            
35
#[test]
36
1
fn compile_wrong_arity_errors() {
37
1
    let err = compile_expect_error("(compile)");
38
1
    assert!(err.contains("compile"), "got: {err}");
39
1
}
40

            
41
#[test]
42
1
fn compile_non_quoted_symbol_errors() {
43
1
    let err = compile_expect_error("(compile 42)");
44
1
    assert!(err.contains("quoted symbol"), "got: {err}");
45
1
}
46

            
47
#[test]
48
1
fn describe_native_returns_string() {
49
1
    compile_and_validate("(describe '+)");
50
1
}
51

            
52
#[test]
53
1
fn describe_unknown_symbol_errors() {
54
1
    let err = compile_expect_error("(describe 'no-such-name)");
55
1
    assert!(
56
1
        err.contains("Undefined") || err.contains("no-such-name"),
57
        "got: {err}",
58
    );
59
1
}
60

            
61
#[test]
62
1
fn describe_wrong_arity_errors() {
63
1
    let err = compile_expect_error("(describe)");
64
1
    assert!(err.contains("DESCRIBE"), "got: {err}");
65
1
}
66

            
67
#[test]
68
1
fn describe_user_function() {
69
1
    compile_and_validate("(defun example (x) (+ x 1)) (describe 'example)");
70
1
}
71

            
72
#[test]
73
1
fn describe_variable() {
74
1
    compile_and_validate("(defvar my-num 42) (describe 'my-num)");
75
1
}