1
//! `LABELS` special form — mutual-recursion-capable local functions.
2

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

            
5
#[test]
6
1
fn labels_single_function_called_in_body() {
7
1
    compile_and_validate("(labels ((square (x) (* x x))) (square 5))");
8
1
}
9

            
10
#[test]
11
1
fn labels_mutually_recursive_functions() {
12
1
    compile_and_validate(
13
1
        "(labels ((even? (n) (if (= n 0) #t (odd? (- n 1)))) \
14
1
                  (odd?  (n) (if (= n 0) #f (even? (- n 1))))) \
15
1
            (even? 4))",
16
    );
17
1
}
18

            
19
#[test]
20
1
fn labels_multiple_body_forms() {
21
1
    compile_and_validate("(labels ((id (x) x)) (id 1) (id 2) (id 3))");
22
1
}
23

            
24
#[test]
25
1
fn labels_empty_definitions_compiles() {
26
1
    compile_and_validate("(labels () 42)");
27
1
}
28

            
29
#[test]
30
1
fn labels_missing_body_errors() {
31
1
    let err = compile_expect_error("(labels ((f (x) x)))");
32
1
    assert!(err.contains("LABELS"), "got: {err}");
33
1
}
34

            
35
#[test]
36
1
fn labels_malformed_definition_errors() {
37
    // Definition without a body — only name and params.
38
1
    let err = compile_expect_error("(labels ((f (x))) (f 1))");
39
1
    assert!(err.contains("LABELS"), "got: {err}");
40
1
}