Add tests for evaluation of recursive records
@@ -198,8 +198,8 @@ impl Program {
let t = self
.parse_with_cache(self.main_id)
.map_err(|e| Error::from(e))?;
- let t = transformations::transform(t, self).map_err(|err| Error::ImportError(err))?;
println!("Typechecked: {:?}", type_check(t.as_ref(), self));
+ let t = transformations::transform(t, self).map_err(|err| Error::ImportError(err))?;
eval::eval(t, self.mk_global_env()?, self).map_err(|e| e.into())
}
@@ -1103,4 +1103,22 @@ Assume(#alwaysTrue -> #alwaysFalse, not ) true
_ => assert!(false),
};
}
+
+ #[test]
+ fn recursive_records() {
+ assert_eq!(
+ eval_string("{a = 1; b = a + 1; c = b + a}.c"),
+ Ok(Term::Num(3.0))
+ );
+ assert_eq!(
+ eval_string("{f = fun x y => if isZero x then y else f (x + (-1)) (y + 1)}.f 5 5"),
+ Ok(Term::Num(10.0))
+ );
+ assert_eq!(
+ eval_string("
+ let with_res = fun res => { f = fun x => if isZero x then res else g x; g = fun y => f (y + (-1)) }.f 10 in
+ with_res \"done\""),
+ Ok(Term::Str(String::from("done")))
+ );
+ }
}
