From 5182b0d798f4914687532975de3cca014923fbda Mon Sep 17 00:00:00 2001 From: Arnaud Bailly Date: Tue, 24 Sep 2024 09:35:10 +0200 Subject: Push down tests at parser level Interpret now is a Value-transforming function --- rust/src/parser.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'rust/src/parser.rs') diff --git a/rust/src/parser.rs b/rust/src/parser.rs index d5d4c30..6b18a9d 100644 --- a/rust/src/parser.rs +++ b/rust/src/parser.rs @@ -25,3 +25,36 @@ fn parse_number(token: &str) -> Result { .map(Value::Num) .map_err(|e| e.to_string()) } + +#[cfg(test)] +mod tests { + use super::parse; + use super::Value::*; + use proptest::prelude::*; + + proptest! { + #[test] + fn parse_integer_as_number(i in -1000i32..1000) { + let result = parse(&i.to_string()); + assert_eq!(Num(i), result); + } + + } + + #[test] + fn parse_truth_values_as_booleans() { + assert_eq!(Bool(true), parse("true")); + assert_eq!(Bool(false), parse("false")); + } + + #[test] + fn parse_identifiers_values_as_symbols() { + assert_eq!(Sym("foo".to_string()), parse("foo")); + } + + #[test] + fn ignores_whitespace() { + assert_eq!(Sym("foo".to_string()), parse(" foo \n\r")); + assert_eq!(Num(-42), parse("\n-42")); + } +} -- cgit v1.2.3