1
use super::{parse_notices, parse_response};
2
use crate::envelope::{RequestId, Response, ResponsePayload, format_response, with_notices};
3
use nomiscript::Value;
4

            
5
4
fn reply() -> String {
6
4
    format_response(&Response {
7
4
        stream: 0,
8
4
        id: RequestId::Int(7),
9
4
        payload: ResponsePayload::Value(Value::String("id".to_string())),
10
4
    })
11
4
}
12

            
13
#[test]
14
1
fn notices_ride_beside_the_value() -> anyhow::Result<()> {
15
1
    let notices = vec!["twin \"Cafe\"".to_string(), "second".to_string()];
16
1
    let wire = with_notices(reply(), &notices);
17

            
18
1
    assert_eq!(
19
1
        wire,
20
1
        "(:id 7 :value \"id\" :notices (\"twin \\\"Cafe\\\"\" \"second\"))"
21
    );
22
1
    assert_eq!(parse_notices(&wire), notices);
23
1
    assert_eq!(
24
1
        parse_response(&wire)?.payload,
25
1
        ResponsePayload::Value(Value::String("id".to_string()))
26
    );
27
1
    Ok(())
28
1
}
29

            
30
#[test]
31
1
fn no_notices_leave_the_frame_alone() {
32
1
    assert_eq!(with_notices(reply(), &[]), reply());
33
1
    assert!(parse_notices(&reply()).is_empty());
34
1
    assert!(parse_notices("not a frame (").is_empty());
35
1
}