diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-24 08:48:55 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-24 08:49:57 +0200 |
| commit | c87e50d9b4859ad16034437e812a84cbe59db6a7 (patch) | |
| tree | c02916da82fdb0eb16ed54f43233397bda55586e /rust | |
| parent | 402013e9e8b3366dd604d4abbe69b7585426c568 (diff) | |
| download | lambda-nantes-c87e50d9b4859ad16034437e812a84cbe59db6a7.tar.gz | |
Ignore whitespaces in input
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/src/lambda.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/rust/src/lambda.rs b/rust/src/lambda.rs index ccb8c28..8c4c640 100644 --- a/rust/src/lambda.rs +++ b/rust/src/lambda.rs @@ -28,10 +28,12 @@ impl Display for Value { } fn interpret(arg: &str) -> Value { - arg.parse::<i32>() + let token = arg.trim(); + token + .parse::<i32>() .map(Value::Num) - .or(arg.parse::<bool>().map(Value::Bool)) - .unwrap_or(Value::Sym(arg.to_string())) + .or(token.parse::<bool>().map(Value::Bool)) + .unwrap_or(Value::Sym(token.to_string())) } #[cfg(test)] @@ -59,4 +61,10 @@ mod tests { 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")); + } } |
