use std::fs::read_to_string; mod ast; use ast::*; mod parser; use parser::*; pub fn run(arg: &str) -> String { let content = read_to_string(arg).unwrap(); let result = interpret(&content.to_string()); result.to_string() } fn interpret(arg: &str) -> Value { // interpreting a value is the value itself parse(arg) } #[cfg(test)] mod tests { use super::interpret; use super::Value::*; use proptest::prelude::*; proptest! { #[test] fn interpret_integer_as_number(i in -1000i32..1000) { let result = interpret(&i.to_string()); assert_eq!(Num(i), result); } } #[test] fn interpret_truth_values_as_booleans() { assert_eq!(Bool(true), interpret("true")); assert_eq!(Bool(false), interpret("false")); } #[test] fn interpret_identifiers_values_as_symbols() { assert_eq!(Sym("foo".to_string()), interpret("foo")); } #[test] fn ignores_whitespace() { assert_eq!(Sym("foo".to_string()), interpret(" foo \n\r")); assert_eq!(Num(-42), interpret("\n-42")); } }