1use crate::{parse, CallSnapshot, Environment, Exception, Expression};
2
3use crate::Locker;
4
5fn exec(code: &str) -> Result<Expression, Exception> {
6 let root = Locker::new(Environment::root());
7 let expressions = parse(code, "<test module>")?;
8 let mut ret = Expression::nil();
9 for expression in expressions {
10 let snapshot = CallSnapshot::root(&expression);
11 ret = expression
12 .eval_async(snapshot, root.clone())?
13 .recv()
14 .unwrap()?;
15 }
16 Ok(ret)
17}
18
19pub fn check(code: &str) -> Result<Expression, Exception> {
20 match exec(code) {
21 Ok(value) => {
22 println!("{}", value);
23 Ok(value)
24 }
25 Err(value) => {
26 eprintln!("{}", value);
27 Err(value)
28 }
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::check;
35
36 #[test]
37 fn smoke_test() {
38 assert!(check(include_str!("smoke_test.lisp")).is_ok());
39 }
40
41 #[test]
42 fn math() {
43 assert!(check(include_str!("math.lisp")).is_ok());
44 }
45
46 #[test]
47 fn map() {
48 assert!(check(include_str!("map.lisp")).is_ok());
49 }
50
51 #[test]
52 fn euler_1() {
53 assert!(check(include_str!("euler_1.lisp")).is_ok());
54 }
55
56 #[test]
57 fn euler_2() {
58 assert!(check(include_str!("euler_2.lisp")).is_ok());
59 }
60
61 #[test]
62 fn euler_3() {
63 assert!(check(include_str!("euler_3.lisp")).is_ok());
64 }
65
66 #[test]
67 fn euler_4() {
68 assert!(check(include_str!("euler_4.lisp")).is_ok());
69 }
70}