use serde::{Deserialize, Serialize};
use super::expressions::Expr;
use super::statements::Statement;
use super::time::Timeframe;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TestDef {
pub name: String,
pub setup: Option<Vec<Statement>>,
pub teardown: Option<Vec<Statement>>,
pub test_cases: Vec<TestCase>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TestCase {
pub description: String,
pub tags: Vec<String>,
pub body: Vec<TestStatement>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TestStatement {
Statement(Statement),
Assert(AssertStatement),
Expect(ExpectStatement),
Should(ShouldStatement),
Fixture(TestFixture),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AssertStatement {
pub condition: Expr,
pub message: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExpectStatement {
pub actual: Expr,
pub matcher: ExpectationMatcher,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ExpectationMatcher {
ToBe(Expr),
ToEqual(Expr),
ToBeCloseTo {
expected: Expr,
tolerance: Option<f64>,
},
ToBeGreaterThan(Expr),
ToBeLessThan(Expr),
ToContain(Expr),
ToBeTruthy,
ToBeFalsy,
ToThrow(Option<String>),
ToMatchPattern {
pattern: String,
options: TestMatchOptions,
},
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct TestMatchOptions {
pub fuzzy: Option<f64>,
pub timeframe: Option<Timeframe>,
pub symbol: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShouldStatement {
pub subject: Expr,
pub matcher: ShouldMatcher,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ShouldMatcher {
Be(Expr),
Equal(Expr),
Contain(Expr),
Match(String),
BeCloseTo {
expected: Expr,
tolerance: Option<f64>,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TestFixture {
WithData { data: Expr, body: Vec<Statement> },
WithMock {
target: String,
mock_value: Option<Expr>,
body: Vec<Statement>,
},
}