1
//! A closure and a condition reach the client in one opaque form each.
2

            
3
use super::*;
4
use crate::envelope::format_response;
5

            
6
5
async fn frame(source: &str) -> String {
7
5
    let mut session = Session::new(ScriptCtx::new(uuid::Uuid::nil())).expect("Session::new");
8
5
    let outcome = session.handle_request(&format!("(progn {source})")).await;
9
5
    format_response(&Response {
10
5
        stream: 0,
11
5
        id: RequestId::Int(1),
12
5
        payload: outcome.payload,
13
5
    })
14
5
}
15

            
16
#[tokio::test]
17
1
async fn a_closure_prints_as_its_site() {
18
1
    for (source, wire) in [
19
1
        ("(lambda () 1)", "(:id 1 :value #<closure:0>)"),
20
1
        ("(list (lambda () 1))", "(:id 1 :value (#<closure:0>))"),
21
1
        (
22
1
            "(defstruct pt x) (let ((f (lambda () 1))) (make-pt :x f))",
23
1
            "(:id 1 :value #S(PT :X #<closure:0>))",
24
1
        ),
25
1
    ] {
26
3
        assert_eq!(frame(source).await, wire, "{source}");
27
1
    }
28
1
}
29

            
30
#[tokio::test]
31
1
async fn a_condition_prints_in_one_opaque_form() {
32
1
    for (source, wire) in [
33
1
        (
34
1
            "(handler-case (error 'boom \"m\") (boom (e) e))",
35
1
            "(:id 1 :value #<condition>)",
36
1
        ),
37
1
        (
38
1
            "(handler-case (error 'boom \"m\") (boom (e) (list 1 e)))",
39
1
            "(:id 1 :value (1 #<condition>))",
40
1
        ),
41
1
    ] {
42
2
        assert_eq!(frame(source).await, wire, "{source}");
43
1
    }
44
1
}