toasty_driver_integration_suite/stmt.rs
1//! Expression utilities for testing with assert_struct!
2//!
3//! This module provides test utilities like the Any wildcard
4//! for use with the Like trait in assert_struct! macros.
5
6use assert_struct::Like;
7use toasty_core::stmt::{Expr, Value, ValueStream};
8
9/// Wildcard type that matches any expression - useful for ignoring fields in patterns
10#[derive(Debug, Clone)]
11pub struct Any;
12
13/// Any wildcard matches any expression
14impl Like<Any> for Expr {
15 fn like(&self, _pattern: &Any) -> bool {
16 true // Any matches everything
17 }
18}
19
20impl PartialEq<Any> for Expr {
21 fn eq(&self, _: &Any) -> bool {
22 true
23 }
24}
25
26/// Any wildcard matches any value
27impl Like<Any> for Value {
28 fn like(&self, _pattern: &Any) -> bool {
29 true // Any matches everything
30 }
31}
32
33impl PartialEq<Any> for Value {
34 fn eq(&self, _: &Any) -> bool {
35 true
36 }
37}
38
39/// Extension trait for ValueStream providing convenient testing methods
40pub trait ValueStreamExt {
41 /// Returns buffered values, asserting that the stream is fully buffered
42 ///
43 /// This method will panic if the stream is not fully buffered (i.e., if there
44 /// are still pending values in the stream that haven't been loaded into the buffer).
45 /// Use this in tests when you want to access buffered values synchronously.
46 fn buffered(&self) -> Vec<Value>;
47}
48
49/// Blanket implementation of ValueStreamExt for ValueStream
50impl ValueStreamExt for ValueStream {
51 fn buffered(&self) -> Vec<Value> {
52 assert!(
53 self.is_buffered(),
54 "ValueStream is not fully buffered - call .buffer().await first"
55 );
56 self.buffered_to_vec()
57 }
58}