1
//! Acceptance row R1 of `doc/ops/0011-typed-elaboration-ir.org`: an identity
2
//! test against `t` / `nil` keeps its other operand's effects. `n` stands for
3
//! `(rpc-protocol-version)`, which is 1.
4

            
5
use super::*;
6

            
7
7
async fn output_and_payload(source: &str) -> (String, ResponsePayload) {
8
7
    let mut session = Session::new(ScriptCtx::new(uuid::Uuid::nil())).expect("Session::new");
9
7
    let outcome = session.handle_request(source).await;
10
7
    (outcome.output, outcome.payload)
11
7
}
12

            
13
#[tokio::test]
14
1
async fn t_against_an_effectful_index_prints_once_and_is_nil() {
15
1
    for source in [
16
1
        "(eq? t (progn (print \"x\") (rpc-protocol-version)))",
17
1
        "(eq? (progn (print \"x\") (rpc-protocol-version)) t)",
18
1
        "(eq? nil (progn (print \"x\") (rpc-protocol-version)))",
19
1
        "(eql t (progn (print \"x\") (rpc-protocol-version)))",
20
1
        "(equal t (progn (print \"x\") (rpc-protocol-version)))",
21
1
        "(equal? t (progn (print \"x\") (rpc-protocol-version)))",
22
1
    ] {
23
6
        let (output, payload) = output_and_payload(source).await;
24
6
        assert_eq!(output, "x", "{source}");
25
6
        assert_eq!(payload, ResponsePayload::Value(Value::Nil), "{source}");
26
1
    }
27
1
}
28

            
29
#[tokio::test]
30
1
async fn t_against_an_effectful_truth_value_prints_once_and_tests_it() {
31
    let (output, payload) =
32
1
        output_and_payload("(eq? t (progn (print \"x\") (< (rpc-protocol-version) 2)))").await;
33
1
    assert_eq!(output, "x");
34
1
    assert_eq!(payload, ResponsePayload::Value(Value::T));
35
1
}