use quote::quote;
use super::generate_procedure_registry_method;
const LIST_RETURNING_SCHEMA: &str = r#"
type TickerArgs {
symbol String
}
type Tick {
price Float
}
procedure ticks(args: TickerArgs): Tick[]
"#;
const STREAM_SCHEMA: &str = r#"
type TickerArgs {
symbol String
}
type Tick {
price Float
}
procedure ticks(args: TickerArgs): Tick[]
@stream
"#;
fn parse_first_procedure(source: &str) -> cratestack_core::Procedure {
cratestack_parser::parse_schema(source)
.expect("fixture schema should parse and validate")
.procedures
.remove(0)
}
#[test]
fn non_stream_list_procedure_trait_method_is_unchanged() {
let procedure = parse_first_procedure(LIST_RETURNING_SCHEMA);
let actual = generate_procedure_registry_method(&procedure)
.expect("codegen should succeed")
.to_string();
let expected = quote! {
fn ticks(
&self,
db: &super::Cratestack,
ctx: &::cratestack::CoolContext,
args: ticks::Args,
) -> impl ::core::future::Future<Output = Result<ticks::Output, ::cratestack::CoolError>> + Send;
}
.to_string();
assert_eq!(
actual, expected,
"non-@stream list-returning procedure's trait method must stay byte-identical"
);
}
#[test]
fn stream_marked_list_procedure_generates_stream_shaped_trait_method() {
let procedure = parse_first_procedure(STREAM_SCHEMA);
let actual = generate_procedure_registry_method(&procedure)
.expect("codegen should succeed")
.to_string();
let expected = quote! {
fn ticks(
&self,
db: &super::Cratestack,
ctx: &::cratestack::CoolContext,
args: ticks::Args,
) -> impl ::cratestack::futures::Stream<Item = Result<ticks::Item, ::cratestack::CoolError>> + Send;
}
.to_string();
assert_eq!(
actual, expected,
"@stream-marked procedure must generate a Stream-shaped trait method, not Future<Output = Vec<T>>"
);
}