File tree Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Expand file tree Collapse file tree 3 files changed +79
-0
lines changed Original file line number Diff line number Diff line change 1+ # HierarchicalGuard
2+ -interface-
3+ A
4+ B[val:bool]
5+
6+ -machine-
7+ $I
8+ |>| entered(" I" ) ^
9+ |<| left(" I" ) ^
10+ |A| -> $S0 ^
11+
12+ $S
13+ |>| entered(" S" ) ^
14+ |<| left(" S" ) ^
15+ |B|[val:bool]
16+ val ? : -> " |B| | val == false" $I :: ^
17+
18+ $S0 => $S
19+ |>| entered(" S0" ) ^
20+ |<| left(" S0" ) ^
21+ |B|[val:bool]
22+ val ? -> " |B| | val == true" $S1 : :: ^
23+
24+ $S1 => $S
25+ |>| entered(" S1" ) ^
26+ |<| left(" S1" ) ^
27+ |B|[val:bool]
28+ val ? -> " |B| | val == true" $S0 : :: ^
29+
30+ -actions-
31+ entered[msg:&String]
32+ left[msg:&String]
33+
34+ -domain-
35+ var entry_log:Log = `vec![]`
36+ var exit_log:Log = `vec![]`
37+ # #
Original file line number Diff line number Diff line change 1+ type Log = Vec < String > ;
2+ include ! ( concat!( env!( "OUT_DIR" ) , "/" , "hierarchical_guard.rs" ) ) ;
3+
4+ impl HierarchicalGuard {
5+ pub fn entered ( & mut self , state : String ) {
6+ self . entry_log . push ( state) ;
7+ }
8+ pub fn left ( & mut self , state : String ) {
9+ self . exit_log . push ( state) ;
10+ }
11+ pub fn transition_hook (
12+ & mut self ,
13+ _current : HierarchicalGuardState ,
14+ _next : HierarchicalGuardState ,
15+ ) {
16+ }
17+ }
18+
19+ #[ cfg( test) ]
20+ mod tests {
21+ use super :: * ;
22+
23+ #[ test]
24+ fn hierarchical_child_transition_handler_with_guard ( ) {
25+ let mut sm = HierarchicalGuard :: new ( ) ;
26+ sm. A ( ) ;
27+ sm. B ( true ) ;
28+ assert_eq ! ( sm. get_current_state_enum( ) , HierarchicalGuardState :: S1 ) ;
29+ }
30+
31+ // Revisit: parent handler for event isn't getting called if child has handler
32+ // regardless of wether it results on transition or not
33+ #[ test]
34+ #[ ignore]
35+ fn hierarchical_parent_transition_handler_with_guard ( ) {
36+ let mut sm = HierarchicalGuard :: new ( ) ;
37+ sm. A ( ) ;
38+ sm. B ( false ) ;
39+ assert_eq ! ( sm. get_current_state_enum( ) , HierarchicalGuardState :: I ) ;
40+ }
41+ }
Original file line number Diff line number Diff line change 11mod basic;
22mod hierarchical;
3+ mod hierarchical_guard;
You can’t perform that action at this time.
0 commit comments