Add support for casting.
This commit is contained in:
@@ -124,7 +124,30 @@ impl Arbitrary for Expression {
|
||||
Union::new([value_strategy, reference_strategy]).boxed()
|
||||
};
|
||||
|
||||
leaf_strategy
|
||||
let cast_strategy = if let Some(bigger_type) = target_type {
|
||||
let mut smaller_types = bigger_type.safe_casts_to();
|
||||
|
||||
if smaller_types.is_empty() {
|
||||
leaf_strategy
|
||||
} else {
|
||||
let duplicated_env = defined_variables.clone();
|
||||
let cast_exp = |t, e| Expression::Cast(Location::manufactured(), t, Box::new(e));
|
||||
|
||||
let smaller_strats: Vec<BoxedStrategy<Expression>> = smaller_types
|
||||
.drain(..)
|
||||
.map(|t| {
|
||||
Expression::arbitrary_with((Some(duplicated_env.clone()), Some(t)))
|
||||
.prop_map(move |e| cast_exp(t.name(), e))
|
||||
.boxed()
|
||||
})
|
||||
.collect();
|
||||
Union::new(smaller_strats).boxed()
|
||||
}
|
||||
} else {
|
||||
leaf_strategy
|
||||
};
|
||||
|
||||
cast_strategy
|
||||
.prop_recursive(3, 64, 2, move |inner| {
|
||||
(select(OPERATORS), proptest::collection::vec(inner, 2)).prop_map(
|
||||
move |((operator, arg_count), mut exprs)| {
|
||||
|
||||
Reference in New Issue
Block a user