Skip to main content

rs_teststand/expression/function/
property.rs

1//! Property expression functions.
2
3/// A property function of the expression language.
4///
5/// Names only: what each one computes is the engine's to document.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum PropertyFunction {
8    /// `CommentOf`.
9    CommentOf,
10    /// `FindStep`.
11    FindStep,
12    /// `NameOf`.
13    NameOf,
14    /// `PropertyExists`.
15    PropertyExists,
16    /// `TypeOf`.
17    TypeOf,
18}
19
20impl PropertyFunction {
21    /// Every function in this family.
22    pub const ALL: [Self; 5] = [
23        Self::CommentOf,
24        Self::FindStep,
25        Self::NameOf,
26        Self::PropertyExists,
27        Self::TypeOf,
28    ];
29
30    /// The name as written in an expression.
31    #[must_use]
32    pub const fn name(self) -> &'static str {
33        match self {
34            Self::CommentOf => "CommentOf",
35            Self::FindStep => "FindStep",
36            Self::NameOf => "NameOf",
37            Self::PropertyExists => "PropertyExists",
38            Self::TypeOf => "TypeOf",
39        }
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::PropertyFunction;
46
47    #[test]
48    fn every_name_is_distinct() {
49        let mut names: Vec<&str> = PropertyFunction::ALL.iter().map(|f| f.name()).collect();
50        names.sort_unstable();
51        let count = names.len();
52        names.dedup();
53        assert_eq!(names.len(), count);
54    }
55}