use super::types::Type; #[derive(PartialEq, Debug)] pub enum SExpr { Atom(Type), Sexpr(Vec) } #[test] fn construct() { let atom1 = SExpr::Atom(Type::Number(Number::Int(1))); let atom2 = SExpr::Atom(Type::Number(Number::Int(2))); let atom3 = SExpr::Atom(Type::Number(Number::Int(3))); let atom4 = SExpr::Atom(Type::Number(Number::Int(4))); let sexp = SExpr::Sexpr(vec!(atom1, atom2, atom3, atom4)); match sexp { SExpr::Sexpr(ref x) => { assert_eq!(x[0], SExpr::Atom(Type::Number(Number::Int(1)))); }, _ => panic!("What") } } #[test] fn mutability() { let atom1 = SExpr::Atom(Type::Number(Number::Int(1))); let atom2 = SExpr::Atom(Type::Number(Number::Int(2))); let atom3 = SExpr::Atom(Type::Number(Number::Int(3))); let atom4 = SExpr::Atom(Type::Number(Number::Int(4))); let mut sexp = SExpr::Sexpr(vec!(atom1, atom2, atom3, atom4)); match sexp { SExpr::Sexpr(ref mut x) => match x[0] { SExpr::Atom(Type::Number(Number::Int(ref mut x))) => *x += 7, _ => panic!("What") }, _ => panic!("What") } match sexp { SExpr::Sexpr(ref x) => { assert_eq!(x[0], SExpr::Atom(Type::Number(Number::Int(8)))); }, _ => panic!("What") } }