use pattern_wishcast::pattern_wishcast;
pattern_wishcast! {
enum TypedTerm = CoreAtoms | Box<TypedTermComplex> | {
Literal { value: String },
TupleCons { elements: Vec<TypedTerm> }, };
enum TypedTermComplex = {
Lambda { body: TypedTerm }, Application { func: TypedTerm, arg: TypedTerm }, };
enum CoreAtoms = {
Variable { name: String },
Level0,
};
}
#[test]
fn test_forward_references() {
let var = CoreAtoms::Variable { name: "x".to_string() };
let term: TypedTerm = var.into();
let tuple = TypedTerm::TupleCons { elements: vec![term] };
let lambda = TypedTermComplex::Lambda { body: tuple };
let boxed_term = TypedTerm::TypedTermComplex(Box::new(lambda));
match &boxed_term {
TypedTerm::TypedTermComplex(complex) => match complex.as_ref() {
TypedTermComplex::Lambda { body } => match body {
TypedTerm::TupleCons { elements } => {
assert_eq!(elements.len(), 1);
}
_ => panic!("Expected TupleCons"),
},
_ => panic!("Expected Lambda"),
},
_ => panic!("Expected TypedTermComplex"),
}
}