1
//! A closure over money, or over compound money, as a later unit sees it
2
//! (PERSIST S6).
3

            
4
use super::carry_money_tests::{money, units};
5
use super::*;
6

            
7
#[tokio::test(flavor = "current_thread")]
8
1
async fn a_closure_over_money_is_called_by_the_next_unit() {
9
1
    let outcomes = units(&[
10
1
        "(defvar f (let ((m (usd))) (lambda () (+ m m))))",
11
1
        "(funcall f)",
12
1
    ])
13
1
    .await;
14
1
    assert_eq!(outcomes[0], Ok(EvalValue::Nil), "{outcomes:?}");
15
1
    assert_eq!(outcomes[1], money(6, 1));
16
1
}
17

            
18
#[tokio::test(flavor = "current_thread")]
19
1
async fn a_closure_over_compound_money_is_lost_to_the_next_unit() {
20
1
    let outcomes = units(&[
21
1
        "(defvar f (let ((m (* (usd) (usd)))) (lambda () m)))",
22
1
        "(funcall f)",
23
1
    ])
24
1
    .await;
25
1
    assert_eq!(
26
1
        outcomes[1],
27
1
        Err("Compile error: F: its closure value does not survive the form".to_string())
28
1
    );
29
1
}
30

            
31
#[tokio::test(flavor = "current_thread")]
32
1
async fn a_list_of_closures_is_called_by_the_next_unit() {
33
1
    let outcomes = units(&[
34
1
        "(defvar *l* (let ((m (usd))) (let ((f (lambda () (+ m m)))) (list f))))",
35
1
        "(funcall (car *l*))",
36
1
    ])
37
1
    .await;
38
1
    assert_eq!(outcomes[1], money(6, 1), "{outcomes:?}");
39
1
}
40

            
41
#[tokio::test(flavor = "current_thread")]
42
1
async fn a_list_of_closures_over_compound_money_is_lost_to_the_next_unit() {
43
1
    let outcomes = units(&[
44
1
        "(defvar *l* (let ((m (* (usd) (usd)))) (let ((f (lambda () m))) (list f))))",
45
1
        "(car *l*)",
46
1
    ])
47
1
    .await;
48
1
    assert_eq!(
49
1
        outcomes[1],
50
1
        Err("Compile error: *L*: its list value does not survive the form".to_string())
51
1
    );
52
1
}