1
//! Here we test an interesting side-effect case, with rules return a reduction based on the metadata.
2
//! These rules will not be run a second time if no other rule applies to the same node, which might be unexpected.
3

            
4
use tree_morph::*;
5
use uniplate::derive::Uniplate;
6

            
7
#[derive(Debug, Clone, PartialEq, Eq, Uniplate)]
8
#[uniplate()]
9
enum Expr {
10
    One,
11
    Two,
12
}
13

            
14
fn transform(cmd: &mut Commands<Expr, bool>, expr: &Expr, meta: &bool) -> Option<Expr> {
15
    if let Expr::One = expr {
16
        if *meta {
17
            return Some(Expr::Two);
18
        } else {
19
            cmd.mut_meta(|m| *m = true); // The next application of this rule should
20
        }
21
    }
22
    None
23
}
24

            
25
// #[test] // TODO (Felix) how might we fix this, in the engine or by blocking this use case?
26
fn test_meta_branching_side_effect() {
27
    let expr = Expr::One;
28
    let (expr, meta) = reduce(transform, expr, false);
29
    assert_eq!(expr, Expr::Two);
30
    assert_eq!(meta, true);
31
}