diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-24 09:35:10 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-24 09:35:10 +0200 |
| commit | 5182b0d798f4914687532975de3cca014923fbda (patch) | |
| tree | 220cbbba823053426c1418050633843dfe71b844 /rust | |
| parent | 72190fe9bbe8b72294d4649d9c3b68f101f2aad2 (diff) | |
| download | lambda-nantes-5182b0d798f4914687532975de3cca014923fbda.tar.gz | |
Push down tests at parser level
Interpret now is a Value-transforming function
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/src/lambda.rs | 40 | ||||
| -rw-r--r-- | rust/src/parser.rs | 33 |
2 files changed, 37 insertions, 36 deletions
diff --git a/rust/src/lambda.rs b/rust/src/lambda.rs index 18568d7..9633bdd 100644 --- a/rust/src/lambda.rs +++ b/rust/src/lambda.rs @@ -8,45 +8,13 @@ use parser::*; pub fn run(arg: &str) -> String { let content = read_to_string(arg).unwrap(); - let result = interpret(&content.to_string()); + let value = parse(&content.to_string()); + let result = interpret(value); result.to_string() } -fn interpret(arg: &str) -> Value { +fn interpret(arg: Value) -> 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")); - } + arg } 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<Value, String> { .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")); + } +} |
