Skip to main content

simulator_client/
recipes.rs

1use simulator_api::DirectFillTemplate;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub struct Recipe {
5    pub name: &'static str,
6    json: &'static str,
7}
8
9impl Recipe {
10    pub fn templates(&self) -> Vec<DirectFillTemplate> {
11        serde_json::from_str(self.json)
12            .unwrap_or_else(|error| panic!("recipe {} ships invalid JSON: {error}", self.name))
13    }
14}
15
16pub const PROP_AMMS: Recipe = Recipe {
17    name: "prop-amms",
18    json: include_str!("../recipes/prop_amms.json"),
19};
20
21pub const ALL: [Recipe; 1] = [PROP_AMMS];
22
23#[cfg(test)]
24mod tests {
25    use std::collections::HashSet;
26
27    use super::*;
28
29    #[test]
30    fn every_recipe_parses() {
31        for recipe in ALL {
32            assert!(
33                !recipe.templates().is_empty(),
34                "{} carries no templates",
35                recipe.name
36            );
37        }
38    }
39
40    #[test]
41    fn labels_are_unique_across_every_recipe() {
42        let mut seen = HashSet::new();
43        for recipe in ALL {
44            for template in recipe.templates() {
45                assert!(
46                    seen.insert(template.label.clone()),
47                    "{} repeats the label {}",
48                    recipe.name,
49                    template.label
50                );
51            }
52        }
53    }
54}