syntax-workout-core 0.2.0

Workout tree algebra — represent any physical workout as a recursive tree
Documentation
use serde::{Deserialize, Serialize};
use ts_rs::TS;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, TS)]
#[ts(export, export_to = "../../../bindings/napi/generated/")]
#[serde(tag = "type", content = "value")]
pub enum ExecutionMode {
    Sequential,
    Parallel,
    Circuit { rounds: u32 },
    Custom(String),
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn sequential_round_trip() {
        let m = ExecutionMode::Sequential;
        let json = serde_json::to_string(&m).unwrap();
        assert_eq!(json, r#"{"type":"Sequential"}"#);
        let back: ExecutionMode = serde_json::from_str(&json).unwrap();
        assert_eq!(back, m);
    }

    #[test]
    fn parallel_round_trip() {
        let m = ExecutionMode::Parallel;
        let json = serde_json::to_string(&m).unwrap();
        assert_eq!(json, r#"{"type":"Parallel"}"#);
        let back: ExecutionMode = serde_json::from_str(&json).unwrap();
        assert_eq!(back, m);
    }

    #[test]
    fn circuit_round_trip() {
        let m = ExecutionMode::Circuit { rounds: 3 };
        let json = serde_json::to_string(&m).unwrap();
        assert!(json.contains(r#""type":"Circuit""#));
        assert!(json.contains(r#""rounds":3"#));
        let back: ExecutionMode = serde_json::from_str(&json).unwrap();
        assert_eq!(back, m);
    }

    #[test]
    fn custom_round_trip() {
        let m = ExecutionMode::Custom("AMRAP".into());
        let json = serde_json::to_string(&m).unwrap();
        let back: ExecutionMode = serde_json::from_str(&json).unwrap();
        assert_eq!(back, m);
    }
}