tests: add custom Arbitrary (Maybe Text) that doesn't generate Just mempty

This commit is contained in:
sorki 2023-12-02 12:49:42 +01:00
parent a7fbcf7a02
commit c815068e60
2 changed files with 8 additions and 4 deletions

View File

@ -62,9 +62,7 @@ spec = parallel $ do
prop "Bool" $ roundtripS bool
prop "ByteString" $ roundtripS byteString
prop "Text" $ roundtripS text
prop "Maybe Text"
$ forAll (arbitrary `suchThat` (/= Just ""))
$ roundtripS maybeText
prop "Maybe Text" $ roundtripS maybeText
prop "UTCTime" $ roundtripS @UTCTime @() time
describe "Combinators" $ do

View File

@ -2,9 +2,15 @@
module Data.Text.Arbitrary () where
import Data.Text (Text)
import Test.QuickCheck (Arbitrary(..))
import Test.QuickCheck (Arbitrary(..), frequency, suchThat)
import qualified Data.Text
instance Arbitrary Text where
arbitrary = Data.Text.pack <$> arbitrary
shrink xs = Data.Text.pack <$> shrink (Data.Text.unpack xs)
instance {-# OVERLAPPING #-} Arbitrary (Maybe Text) where
arbitrary = frequency
[ (1, pure Nothing)
, (3, Just <$> arbitrary `suchThat` (/= mempty))
]