Skip to content

Commit

Permalink
Add some more leaf generators
Browse files Browse the repository at this point in the history
  • Loading branch information
7h3kk1d committed Dec 16, 2024
1 parent bef0026 commit e2f5f72
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/haz3lmenhir/AST.re
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,16 @@ let arb_var = QCheck.(map(x => Var(x), arb_ident));

let arb_exp_sized: QCheck.arbitrary(exp) =
QCheck.(
let leaf = oneof([arb_int, arb_str, arb_float, arb_var]);
let leaf =
oneof([
arb_int,
arb_str,
arb_float,
arb_var,
always(~print=show_exp, EmptyHole),
// always(~print=show_exp, TupleExp([])), // TODO Seems to be broken
always(~print=show_exp, ListExp([])),
]);

let gen: Gen.t(exp) =
QCheck.Gen.sized_size(
Expand Down Expand Up @@ -220,20 +229,20 @@ let arb_exp_sized: QCheck.arbitrary(exp) =
list_sizes,
),
),
// Need to make ExpToSegment add parens for tuples for menhir
Gen.join(
Gen.map(
(sizes: array(int)) => {
let exps = Array.map((size: int) => self(size), sizes);
let flattened = Gen.flatten_a(exps);
Gen.map(
(exps: array(exp)) => TupleExp(Array.to_list(exps)),
(exps: array(exp)) => TupleExp(Array.to_list(exps)), // TODO See if there's a way to do unit and various sizes here
flattened,
);
},
list_sizes,
),
),
Gen.map(exp => Test(exp), self(n - 1)),
]);
}
}),
Expand Down

0 comments on commit e2f5f72

Please sign in to comment.