Lines
100 %
Functions
Branches
//! A closure over money, or over compound money, as a later unit sees it
//! (PERSIST S6).
use super::carry_money_tests::{money, units};
use super::*;
#[tokio::test(flavor = "current_thread")]
async fn a_closure_over_money_is_called_by_the_next_unit() {
let outcomes = units(&[
"(defvar f (let ((m (usd))) (lambda () (+ m m))))",
"(funcall f)",
])
.await;
assert_eq!(outcomes[0], Ok(EvalValue::Nil), "{outcomes:?}");
assert_eq!(outcomes[1], money(6, 1));
}
async fn a_closure_over_compound_money_is_lost_to_the_next_unit() {
"(defvar f (let ((m (* (usd) (usd)))) (lambda () m)))",
assert_eq!(
outcomes[1],
Err("Compile error: F: its closure value does not survive the form".to_string())
);
async fn a_list_of_closures_is_called_by_the_next_unit() {
"(defvar *l* (let ((m (usd))) (let ((f (lambda () (+ m m)))) (list f))))",
"(funcall (car *l*))",
assert_eq!(outcomes[1], money(6, 1), "{outcomes:?}");
async fn a_list_of_closures_over_compound_money_is_lost_to_the_next_unit() {
"(defvar *l* (let ((m (* (usd) (usd)))) (let ((f (lambda () m))) (list f))))",
"(car *l*)",
Err("Compile error: *L*: its list value does not survive the form".to_string())