Lines
100 %
Functions
Branches
//! A closure and a condition reach the client in one opaque form each.
use super::*;
use crate::envelope::format_response;
async fn frame(source: &str) -> String {
let mut session = Session::new(ScriptCtx::new(uuid::Uuid::nil())).expect("Session::new");
let outcome = session.handle_request(&format!("(progn {source})")).await;
format_response(&Response {
stream: 0,
id: RequestId::Int(1),
payload: outcome.payload,
})
}
#[tokio::test]
async fn a_closure_prints_as_its_site() {
for (source, wire) in [
("(lambda () 1)", "(:id 1 :value #<closure:0>)"),
("(list (lambda () 1))", "(:id 1 :value (#<closure:0>))"),
(
"(defstruct pt x) (let ((f (lambda () 1))) (make-pt :x f))",
"(:id 1 :value #S(PT :X #<closure:0>))",
),
] {
assert_eq!(frame(source).await, wire, "{source}");
async fn a_condition_prints_in_one_opaque_form() {
"(handler-case (error 'boom \"m\") (boom (e) e))",
"(:id 1 :value #<condition>)",
"(handler-case (error 'boom \"m\") (boom (e) (list 1 e)))",
"(:id 1 :value (1 #<condition>))",