1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//! BDD utilities

/// A BDD step
#[derive(Copy, Clone, Debug)]
pub enum Step {
    /// Initial state of the BDD state
    Start,
    /// Given: Parsing Input
    Given,
    /// When: Conditional assertions
    When,
    /// Then: Produce side effects
    Then,
}

impl Step {
    /// Initialize BDD Step
    pub fn new() -> Self {
        Step::Start
    }

    /// Get the next BDD Step given a keyword: "Given", "When", "Then" or "And"
    pub fn next(self, keyword: &str) -> Option<Step> {
        match keyword {
            "Given" => match self {
                Step::Start | Step::Given => Some(Step::Given),
                _ => None,
            },
            "When" => match self {
                Step::Start | Step::Given | Step::When => Some(Step::Given),
                Step::Then => None,
            },
            "Then" => match self {
                Step::Start | Step::Given | Step::When | Step::Then => Some(Step::Then),
            },
            "And" => match self {
                Step::Given | Step::When | Step::Then => Some(self),
                Step::Start => None,
            },
            _ => None,
        }
    }
}

impl Default for Step {
    fn default() -> Self {
        Step::Start
    }
}