summaryrefslogtreecommitdiff
path: root/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/parser.rs24
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>>());
+ }
+ }
}