1use serde::{Deserialize, Serialize};
4
5use super::expressions::Expr;
6use super::statements::Statement;
7use super::time::Timeframe;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct TestDef {
12 pub name: String,
14 pub setup: Option<Vec<Statement>>,
16 pub teardown: Option<Vec<Statement>>,
18 pub test_cases: Vec<TestCase>,
20}
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct TestCase {
25 pub description: String,
27 pub tags: Vec<String>,
29 pub body: Vec<TestStatement>,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35pub enum TestStatement {
36 Statement(Statement),
38 Assert(AssertStatement),
40 Expect(ExpectStatement),
42 Should(ShouldStatement),
44 Fixture(TestFixture),
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct AssertStatement {
51 pub condition: Expr,
53 pub message: Option<String>,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct ExpectStatement {
60 pub actual: Expr,
62 pub matcher: ExpectationMatcher,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68pub enum ExpectationMatcher {
69 ToBe(Expr),
71 ToEqual(Expr),
73 ToBeCloseTo {
75 expected: Expr,
76 tolerance: Option<f64>,
77 },
78 ToBeGreaterThan(Expr),
80 ToBeLessThan(Expr),
82 ToContain(Expr),
84 ToBeTruthy,
86 ToBeFalsy,
88 ToThrow(Option<String>),
90 ToMatchPattern {
92 pattern: String,
93 options: TestMatchOptions,
94 },
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize, Default)]
99pub struct TestMatchOptions {
100 pub fuzzy: Option<f64>,
102 pub timeframe: Option<Timeframe>,
104 pub symbol: Option<String>,
106}
107
108#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct ShouldStatement {
111 pub subject: Expr,
113 pub matcher: ShouldMatcher,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize)]
119pub enum ShouldMatcher {
120 Be(Expr),
122 Equal(Expr),
124 Contain(Expr),
126 Match(String),
128 BeCloseTo {
130 expected: Expr,
131 tolerance: Option<f64>,
132 },
133}
134
135#[derive(Debug, Clone, Serialize, Deserialize)]
137pub enum TestFixture {
138 WithData { data: Expr, body: Vec<Statement> },
140 WithMock {
142 target: String,
143 mock_value: Option<Expr>,
144 body: Vec<Statement>,
145 },
146}