summaryrefslogtreecommitdiff
path: root/rust/src/lambda.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/lambda.rs')
-rw-r--r--rust/src/lambda.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/rust/src/lambda.rs b/rust/src/lambda.rs
index e6102d8..ee5cb1f 100644
--- a/rust/src/lambda.rs
+++ b/rust/src/lambda.rs
@@ -115,6 +115,8 @@ pub fn generate_expr(size: u32, runner: &mut TestRunner) -> Value {
4 => simple_app().new_tree(runner).unwrap().current(),
5 => nested_simple_app().new_tree(runner).unwrap().current(),
6 => simple_lambda().new_tree(runner).unwrap().current(),
+ 7 => app_to_lambda().new_tree(runner).unwrap().current(),
+ 8 => multi_app().new_tree(runner).unwrap().current(),
_ => todo!(),
}
}
@@ -124,6 +126,11 @@ fn simple_app() -> impl Strategy<Value = Value> {
(leaf.clone(), leaf.clone()).prop_map(|(l, r)| Value::App(Box::new(l), Box::new(r)))
}
+fn multi_app() -> impl Strategy<Value = Value> {
+ let leaf = prop_oneof![any_num(), any_sym()];
+ (leaf.clone(), leaf.clone()).prop_map(|(l, r)| Value::App(Box::new(l), Box::new(r)))
+}
+
fn any_num() -> impl Strategy<Value = Value> {
any::<i32>().prop_map(Value::Num)
}
@@ -140,9 +147,16 @@ fn any_sym() -> impl Strategy<Value = Value> {
}
fn simple_lambda() -> impl Strategy<Value = Value> {
+ // TODO: there's nothing to guarantee the variable appears in the body
(ascii_identifier(), nested_simple_app()).prop_map(|(v, b)| Value::Lam(v, Box::new(b)))
}
+fn app_to_lambda() -> impl Strategy<Value = Value> {
+ let lam = simple_lambda();
+ let arg = prop_oneof![any_num(), any_sym(), nested_simple_app()];
+ (lam, arg).prop_map(|(l, a)| Value::App(Box::new(l), Box::new(a)))
+}
+
#[cfg(test)]
mod lambda_test {
use crate::parser::parse;