Lines
100 %
Functions
Branches
//! `LABELS` special form — mutual-recursion-capable local functions.
use super::common::{compile_and_validate, compile_expect_error};
#[test]
fn labels_single_function_called_in_body() {
compile_and_validate("(labels ((square (x) (* x x))) (square 5))");
}
fn labels_mutually_recursive_functions() {
compile_and_validate(
"(labels ((even? (n) (if (= n 0) #t (odd? (- n 1)))) \
(odd? (n) (if (= n 0) #f (even? (- n 1))))) \
(even? 4))",
);
fn labels_multiple_body_forms() {
compile_and_validate("(labels ((id (x) x)) (id 1) (id 2) (id 3))");
fn labels_empty_definitions_compiles() {
compile_and_validate("(labels () 42)");
fn labels_missing_body_errors() {
let err = compile_expect_error("(labels ((f (x) x)))");
assert!(err.contains("LABELS"), "got: {err}");
fn labels_malformed_definition_errors() {
// Definition without a body — only name and params.
let err = compile_expect_error("(labels ((f (x))) (f 1))");