Lines
97.92 %
Functions
100 %
Branches
//! A `DEFSTRUCT` instance reaches the client as Common Lisp prints it, never as
//! an opaque placeholder: in a result, a list cell and a raise detail.
use super::*;
use crate::envelope::format_response;
use nomiscript::format_value;
async fn printed_units(sources: &[&str]) -> Vec<String> {
let mut session = Session::new(ScriptCtx::new(uuid::Uuid::nil())).expect("Session::new");
let mut outcomes = Vec::new();
for source in sources {
let outcome = session.handle_request(source).await;
outcomes.push(match outcome.payload {
ResponsePayload::Error { message, .. } => message,
ResponsePayload::Value(value) => format_value(&value),
});
}
outcomes
#[tokio::test]
async fn an_instance_global_result_prints_its_name_and_fields() {
let outcomes = printed_units(&["(defstruct pt x)", "(defvar *p* (make-pt :x 1))", "*p*"]).await;
assert_eq!(outcomes[2], "#S(PT :X 1)");
async fn a_list_holding_an_instance_prints_it_in_the_cell() {
let outcomes = printed_units(&[
"(defstruct pt x)",
"(defvar *p* (make-pt :x 1))",
"(list *p* 1)",
])
.await;
assert_eq!(outcomes[2], "(#S(PT :X 1) 1)");
async fn a_constructor_result_prints_its_name_and_fields() {
let outcomes = printed_units(&["(defstruct pt x)", "(make-pt :x 2)"]).await;
assert_eq!(outcomes[1], "#S(PT :X 2)");
async fn a_raise_detail_holding_an_instance_prints_it() {
session.handle_request("(defstruct pt x)").await;
session.handle_request("(defvar *p* (make-pt :x 1))").await;
let outcome = session
.handle_request(r#"(error 'boom "m" (list :row 7 :p *p*))"#)
let wire = format_response(&Response {
stream: 0,
id: RequestId::Int(1),
payload: outcome.payload,
assert!(
wire.contains(r#":detail (:ROW 7 :P #S(PT :X 1))"#),
"{wire}"
);
async fn an_instance_result_is_a_struct_on_the_wire() {
let wire = eval_value_of("(progn (defstruct pt x) (list (make-pt :x 2) 1))").await;
assert_eq!(wire, "(:id 4 :value (#S(PT :X 2) 1))");