Lines
96.55 %
Functions
92.86 %
Branches
100 %
//! A value the server sends must be one the client reader accepts: the decoder
//! ceiling is `MAX_WIRE_LIST_DEPTH`, and one level deeper is a server error.
use scripting::MAX_WIRE_LIST_DEPTH;
use super::*;
const WIDEN: &str = "(> (rpc-protocol-version) 999)";
/// `n` nested lists built at runtime around `seed`; the `or` forces `AnyRef`.
fn labels_nest(n: usize, seed: &str) -> String {
format!(
"(labels ((build (n acc) \
(if (<= n 0) acc (build (- n 1) (or {WIDEN} (list acc)))))) \
(build {n} {seed}))"
)
}
fn anyref_nest(n: usize) -> String {
labels_nest(n, "nil")
/// A fixed `PairRef` result whose one car is the deeper `AnyRef` chain.
fn fixed_nest(n: usize) -> String {
format!("(let ((r {})) (list r))", anyref_nest(n - 1))
async fn parsed(form: &str) -> ResponsePayload {
let wire = eval_value_of(form).await;
crate::parse_response(&wire)
.unwrap_or_else(|e| panic!("client cannot read {form}: {e}\n{wire}"))
.payload
async fn assert_ceiling(build: impl Fn(usize) -> String) {
let ok = parsed(&build(MAX_WIRE_LIST_DEPTH)).await;
assert!(matches!(ok, ResponsePayload::Value(_)), "{ok:?}");
let over = parsed(&build(MAX_WIRE_LIST_DEPTH + 1)).await;
assert!(
matches!(&over, ResponsePayload::Error { message, .. } if message.contains("depth limit")),
"{over:?}"
);
#[tokio::test]
async fn a_fixed_pair_result_is_read_back_at_the_ceiling() {
assert_ceiling(fixed_nest).await;
async fn an_anyref_result_is_read_back_at_the_ceiling() {
assert_ceiling(anyref_nest).await;