Lines
100 %
Functions
Branches
//! A SHOULD-APPLY defined in a session never runs there: the global it stores
//! to stays a constant, so a macro body may read it.
use rpc::{ScriptCtx, Session};
use uuid::Uuid;
fn extract_value(response: &str) -> &str {
response
.split_once(":value ")
.map(|(_, rest)| rest.trim_end_matches(')').trim())
.unwrap_or(response)
}
#[tokio::test(flavor = "current_thread")]
async fn a_macro_reads_a_global_a_session_should_apply_stores_to() {
let mut session = Session::new(ScriptCtx::new(Uuid::new_v4())).unwrap();
let mut last = String::new();
for form in [
"(defvar *seen* 0)",
"(defun should-apply () (setf *seen* 5) t)",
"(defmacro rd () *seen*)",
"(rd)",
] {
last = session.handle_form(&format!("(:id 1 :form {form})")).await;
assert_eq!(extract_value(&last), "0", "got: {last}");