Lines
100 %
Functions
Branches
use super::*;
mod mux;
#[tokio::test]
async fn the_recording_link_receives_the_enveloped_form_and_sends_no_reply() {
let (mut eval, sent) = ConsoleEval::recording();
eval.submit(MAIN_STREAM, "(foo)".to_string());
assert_eq!(sent.frames(), ["(:id 1 :form (foo))"]);
assert!(eval.drain().is_empty());
}
async fn a_request_for_another_stream_names_it_in_the_envelope() {
eval.submit(3, "(foo)".to_string());
assert_eq!(sent.frames(), ["(:id 1 :stream 3 :form (foo))"]);
async fn interrupt_and_close_without_a_running_eval_do_not_panic() {
let (mut eval, _sent) = ConsoleEval::recording();
eval.interrupt(MAIN_STREAM);
eval.close(3);
async fn submit_after_the_ids_ran_out_reports_failure() {
let mut eval = ConsoleEval::broken();
assert!(eval.submit(MAIN_STREAM, "(x)".to_string()).is_none());
async fn submit_returns_monotonic_ids() {
let ids: Vec<Option<i64>> = ["(a)", "(b)", "(c)"]
.into_iter()
.map(|form| eval.submit(MAIN_STREAM, form.to_string()))
.collect();
assert_eq!(ids, [Some(1), Some(2), Some(3)]);
async fn a_reply_that_is_not_a_response_is_unroutable() {
let (mut eval, replies) = ConsoleEval::scripted();
eval.submit(MAIN_STREAM, "(x)".to_string());
assert!(replies.try_send("(:id 1 :form (x))".to_string()).is_ok());
let items = eval.drain();
assert!(
matches!(items.as_slice(), [DrainItem::Unroutable(_)]),
"{items:?}"
);
#[test]
fn classify_response_positive_id_is_routed() {
let item = classify_response("(:id 5 :value 42)".to_string());
assert!(matches!(item, DrainItem::Routed { id: 5, .. }), "{item:?}");
fn classify_response_id_zero_is_unroutable() {
let item = classify_response("(:id 0 :value 42)".to_string());
assert!(matches!(item, DrainItem::Unroutable(_)), "{item:?}");
fn classify_response_parse_error_is_unroutable() {
let item = classify_response("((((".to_string());
fn classify_response_string_id_is_unroutable() {
let item = classify_response(r#"(:id "abc" :value 1)"#.to_string());
async fn each_recording_console_keeps_its_own_frames() {
let (mut first, first_sent) = ConsoleEval::recording();
let (mut second, second_sent) = ConsoleEval::recording();
first.submit(MAIN_STREAM, "(a)".to_string());
second.submit(MAIN_STREAM, "(b)".to_string());
assert_eq!(first_sent.frames(), ["(:id 1 :form (a))"]);
assert_eq!(second_sent.frames(), ["(:id 1 :form (b))"]);