Skip to content

Commit

Permalink
expr: implement Arbitrary for UnaryFunc (incomplete)
Browse files Browse the repository at this point in the history
We need a custom implementation because the one synthesized
by the derive macro is hitting a known proptest issue[^1].

More arms need to be added as we build up the protobuf
support for `UnaryFunc` towards closing #11747.

[1]: proptest-rs/proptest#152
  • Loading branch information
aalexandrov committed Apr 13, 2022
1 parent 849bc1e commit fd59850
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/expr/src/scalar/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3500,6 +3500,70 @@ pub enum UnaryFunc {
MzTypeName(MzTypeName),
}

#[cfg(feature = "test-utils")]
use proptest::{prelude::*, strategy::*};

#[cfg(feature = "test-utils")]
impl proptest::arbitrary::Arbitrary for UnaryFunc {
type Parameters = ();

type Strategy = Union<BoxedStrategy<UnaryFunc>>;

fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
prop_oneof![
Not::arbitrary().prop_map_into(),
IsNull::arbitrary().prop_map_into(),
IsTrue::arbitrary().prop_map_into(),
IsFalse::arbitrary().prop_map_into(),
BitNotInt16::arbitrary().prop_map_into(),
BitNotInt32::arbitrary().prop_map_into(),
BitNotInt64::arbitrary().prop_map_into(),
NegInt16::arbitrary().prop_map_into(),
NegInt32::arbitrary().prop_map_into(),
NegInt64::arbitrary().prop_map_into(),
NegFloat32::arbitrary().prop_map_into(),
NegFloat64::arbitrary().prop_map_into(),
NegNumeric::arbitrary().prop_map_into(),
NegInterval::arbitrary().prop_map_into(),
SqrtFloat64::arbitrary().prop_map_into(),
SqrtNumeric::arbitrary().prop_map_into(),
CbrtFloat64::arbitrary().prop_map_into(),
AbsInt16::arbitrary().prop_map_into(),
AbsInt32::arbitrary().prop_map_into(),
AbsInt64::arbitrary().prop_map_into(),
AbsFloat32::arbitrary().prop_map_into(),
AbsFloat64::arbitrary().prop_map_into(),
AbsNumeric::arbitrary().prop_map_into(),
CastBoolToString::arbitrary().prop_map_into(),
CastBoolToStringNonstandard::arbitrary().prop_map_into(),
CastBoolToInt32::arbitrary().prop_map_into(),
CastInt16ToFloat32::arbitrary().prop_map_into(),
CastInt16ToFloat64::arbitrary().prop_map_into(),
CastInt16ToInt32::arbitrary().prop_map_into(),
CastInt16ToInt64::arbitrary().prop_map_into(),
CastInt16ToString::arbitrary().prop_map_into(),
CastInt2VectorToArray::arbitrary().prop_map_into(),
CastInt32ToBool::arbitrary().prop_map_into(),
CastInt32ToFloat32::arbitrary().prop_map_into(),
CastInt32ToFloat64::arbitrary().prop_map_into(),
CastInt32ToOid::arbitrary().prop_map_into(),
CastInt32ToPgLegacyChar::arbitrary().prop_map_into(),
CastInt32ToInt16::arbitrary().prop_map_into(),
CastInt32ToInt64::arbitrary().prop_map_into(),
CastInt32ToString::arbitrary().prop_map_into(),
CastOidToInt32::arbitrary().prop_map_into(),
CastOidToInt64::arbitrary().prop_map_into(),
CastOidToString::arbitrary().prop_map_into(),
CastOidToRegClass::arbitrary().prop_map_into(),
CastRegClassToOid::arbitrary().prop_map_into(),
CastOidToRegProc::arbitrary().prop_map_into(),
CastRegProcToOid::arbitrary().prop_map_into(),
CastOidToRegType::arbitrary().prop_map_into(),
CastRegTypeToOid::arbitrary().prop_map_into(),
]
}
}

derive_unary!(
Not,
NegFloat32,
Expand Down
1 change: 1 addition & 0 deletions src/expr/src/scalar/func/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ macro_rules! sqlfunc {
) => {
paste::paste! {
#[derive(Ord, PartialOrd, Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, Hash, mz_lowertest::MzReflect)]
#[cfg_attr(feature = "test-utils", derive(proptest_derive::Arbitrary))]
pub struct [<$fn_name:camel>];

impl<'a> crate::func::EagerUnaryFunc<'a> for [<$fn_name:camel>] {
Expand Down

0 comments on commit fd59850

Please sign in to comment.