Skip to main content

syntax_workout_core/
execution_mode.rs

1use serde::{Deserialize, Serialize};
2use ts_rs::TS;
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
5#[ts(export, export_to = "../../../bindings/napi/generated/")]
6#[serde(tag = "type", content = "value")]
7pub enum ExecutionMode {
8    Sequential,
9    Parallel,
10    Circuit { rounds: u32 },
11    Custom(String),
12}
13
14#[cfg(test)]
15mod tests {
16    use super::*;
17
18    #[test]
19    fn sequential_round_trip() {
20        let m = ExecutionMode::Sequential;
21        let json = serde_json::to_string(&m).unwrap();
22        assert_eq!(json, r#"{"type":"Sequential"}"#);
23        let back: ExecutionMode = serde_json::from_str(&json).unwrap();
24        assert_eq!(back, m);
25    }
26
27    #[test]
28    fn parallel_round_trip() {
29        let m = ExecutionMode::Parallel;
30        let json = serde_json::to_string(&m).unwrap();
31        assert_eq!(json, r#"{"type":"Parallel"}"#);
32        let back: ExecutionMode = serde_json::from_str(&json).unwrap();
33        assert_eq!(back, m);
34    }
35
36    #[test]
37    fn circuit_round_trip() {
38        let m = ExecutionMode::Circuit { rounds: 3 };
39        let json = serde_json::to_string(&m).unwrap();
40        assert!(json.contains(r#""type":"Circuit""#));
41        assert!(json.contains(r#""rounds":3"#));
42        let back: ExecutionMode = serde_json::from_str(&json).unwrap();
43        assert_eq!(back, m);
44    }
45
46    #[test]
47    fn custom_round_trip() {
48        let m = ExecutionMode::Custom("AMRAP".into());
49        let json = serde_json::to_string(&m).unwrap();
50        let back: ExecutionMode = serde_json::from_str(&json).unwrap();
51        assert_eq!(back, m);
52    }
53}