1
//! Here we test an interesting side-effect case, with rules which return a reduction based on a metadata field.
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
// TODO (Felix) how might we fix this, in the engine or by blocking this use case?
5

            
6
use tree_morph::*;
7
use uniplate::derive::Uniplate;
8

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

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

            
27
#[test]
28
#[ignore = "this will fail until we fix it"]
29
fn test_meta_branching_side_effect() {
30
    let expr = Expr::One;
31
    let (expr, meta) = reduce(&[transform], expr, false);
32
    assert_eq!(expr, Expr::Two);
33
    assert_eq!(meta, true);
34
}