diff --git a/tests/Tests/QuickCheckUtils.hs b/tests/Tests/QuickCheckUtils.hs index f1a0b77e..84f3823e 100644 --- a/tests/Tests/QuickCheckUtils.hs +++ b/tests/Tests/QuickCheckUtils.hs @@ -110,16 +110,24 @@ instance Arbitrary BigInt where newtype NotEmpty a = NotEmpty { notEmpty :: a } deriving (Eq, Ord, Show) +toNotEmptyBy :: Functor m => ([Char] -> a) -> m (NonEmptyList Char) -> m (NotEmpty a) +toNotEmptyBy f = fmap (coerce f) + +arbitraryNotEmptyBy :: ([Char] -> a) -> Gen (NotEmpty a) +arbitraryNotEmptyBy f = toNotEmptyBy f arbitrary + +shrinkNotEmptyBy :: ([Char] -> a) -> (a -> [Char]) -> NotEmpty a -> [NotEmpty a] +shrinkNotEmptyBy g f = + toNotEmptyBy g . shrink . coerce f instance Arbitrary (NotEmpty T.Text) where - arbitrary = fmap (NotEmpty . T.pack . getNonEmpty) arbitrary - shrink = fmap (NotEmpty . T.pack . getNonEmpty) - . shrink . NonEmpty . T.unpack . notEmpty + arbitrary = arbitraryNotEmptyBy T.pack + shrink = shrinkNotEmptyBy T.pack T.unpack instance Arbitrary (NotEmpty TL.Text) where - arbitrary = fmap (NotEmpty . TL.pack . getNonEmpty) arbitrary - shrink = fmap (NotEmpty . TL.pack . getNonEmpty) - . shrink . NonEmpty . TL.unpack . notEmpty + arbitrary = arbitraryNotEmptyBy TL.pack + shrink = shrinkNotEmptyBy TL.pack TL.unpack + data DecodeErr = Lenient | Ignore | Strict | Replace deriving (Show, Eq, Bounded, Enum)