Skip to content

Commit c815068

Browse files
committed
tests: add custom Arbitrary (Maybe Text) that doesn't generate Just mempty
1 parent a7fbcf7 commit c815068

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

hnix-store-remote/tests/NixSerializerSpec.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ spec = parallel $ do
6262
prop "Bool" $ roundtripS bool
6363
prop "ByteString" $ roundtripS byteString
6464
prop "Text" $ roundtripS text
65-
prop "Maybe Text"
66-
$ forAll (arbitrary `suchThat` (/= Just ""))
67-
$ roundtripS maybeText
65+
prop "Maybe Text" $ roundtripS maybeText
6866
prop "UTCTime" $ roundtripS @UTCTime @() time
6967

7068
describe "Combinators" $ do

hnix-store-tests/src/Data/Text/Arbitrary.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
module Data.Text.Arbitrary () where
33

44
import Data.Text (Text)
5-
import Test.QuickCheck (Arbitrary(..))
5+
import Test.QuickCheck (Arbitrary(..), frequency, suchThat)
66
import qualified Data.Text
77

88
instance Arbitrary Text where
99
arbitrary = Data.Text.pack <$> arbitrary
1010
shrink xs = Data.Text.pack <$> shrink (Data.Text.unpack xs)
11+
12+
instance {-# OVERLAPPING #-} Arbitrary (Maybe Text) where
13+
arbitrary = frequency
14+
[ (1, pure Nothing)
15+
, (3, Just <$> arbitrary `suchThat` (/= mempty))
16+
]

0 commit comments

Comments
 (0)