summaryrefslogtreecommitdiff
path: root/src/lib/sexpr.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/sexpr.rs')
-rw-r--r--src/lib/sexpr.rs42
1 files changed, 40 insertions, 2 deletions
diff --git a/src/lib/sexpr.rs b/src/lib/sexpr.rs
index 0d37332..a6fbe49 100644
--- a/src/lib/sexpr.rs
+++ b/src/lib/sexpr.rs
@@ -1,7 +1,45 @@
use super::types::Type;
-pub enum SEXP {
+#[derive(PartialEq, Debug)]
+pub enum SExpr {
Atom(Type),
- List(Vec<SEXP>)
+ Sexpr(Vec<SExpr>)
}
+#[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")
+ }
+}