1
//! A SHOULD-APPLY defined in a session never runs there: the global it stores
2
//! to stays a constant, so a macro body may read it.
3

            
4
use rpc::{ScriptCtx, Session};
5
use uuid::Uuid;
6

            
7
1
fn extract_value(response: &str) -> &str {
8
1
    response
9
1
        .split_once(":value ")
10
1
        .map(|(_, rest)| rest.trim_end_matches(')').trim())
11
1
        .unwrap_or(response)
12
1
}
13

            
14
#[tokio::test(flavor = "current_thread")]
15
1
async fn a_macro_reads_a_global_a_session_should_apply_stores_to() {
16
1
    let mut session = Session::new(ScriptCtx::new(Uuid::new_v4())).unwrap();
17
1
    let mut last = String::new();
18
1
    for form in [
19
1
        "(defvar *seen* 0)",
20
1
        "(defun should-apply () (setf *seen* 5) t)",
21
1
        "(defmacro rd () *seen*)",
22
1
        "(rd)",
23
1
    ] {
24
4
        last = session.handle_form(&format!("(:id 1 :form {form})")).await;
25
1
    }
26
1
    assert_eq!(extract_value(&last), "0", "got: {last}");
27
1
}