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