diff options
| author | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-24 10:12:54 +0200 |
|---|---|---|
| committer | Arnaud Bailly <arnaud.bailly@iohk.io> | 2024-09-24 10:12:54 +0200 |
| commit | 41eee266cbbd742d883844f552509e823910f85b (patch) | |
| tree | 994ff159563e329dd7480e61a0e63ae9672815cd /rust/src/parser.rs | |
| parent | c568c9d38fafe61ae043b69b0aa7a998b142448b (diff) | |
| download | lambda-nantes-41eee266cbbd742d883844f552509e823910f85b.tar.gz | |
Check parsing is inverse to display
Diffstat (limited to 'rust/src/parser.rs')
| -rw-r--r-- | rust/src/parser.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/rust/src/parser.rs b/rust/src/parser.rs index b3d76fb..812444d 100644 --- a/rust/src/parser.rs +++ b/rust/src/parser.rs @@ -37,6 +37,7 @@ fn parse_number(token: &str) -> Result<Value, String> { #[cfg(test)] mod tests { + use super::Value; use super::Value::*; use super::{parse, tokenize}; use proptest::prelude::*; @@ -71,4 +72,27 @@ mod tests { fn tokenize_several_values() { assert_eq!(vec!["42", "foo", "true"], tokenize("42 foo \ntrue ")); } + + impl Arbitrary for Value { + type Parameters = (); + type Strategy = BoxedStrategy<Self>; + + fn arbitrary_with(_args: ()) -> Self::Strategy { + prop_oneof![ + any::<i32>().prop_map(Num), + any::<bool>().prop_map(Bool), + // see https://unicode.org/reports/tr18/#General_Category_Property for one letter unicode categories + "\\pL(\\pL|\\pN)*".prop_map(Sym), + ] + .boxed() + } + } + + proptest! { + #[test] + fn parse_is_inverse_to_display(values in any::<Vec<Value>>()) { + let result : Vec<String> = values.iter().map(|v:&Value| v.to_string()).collect(); + assert_eq!(values, result.iter().map(|s| parse(s)).collect::<Vec<Value>>()); + } + } } |
