{-# OPTIONS_GHC -Wno-orphans #-}
module Data.Text.Arbitrary () where

import Data.Text (Text)
import Test.QuickCheck (Arbitrary(..), frequency, suchThat)
import qualified Data.Text

instance Arbitrary Text where
  arbitrary :: Gen Text
arbitrary = String -> Text
Data.Text.pack (String -> Text) -> Gen String -> Gen Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen String
forall a. Arbitrary a => Gen a
arbitrary
  shrink :: Text -> [Text]
shrink Text
xs = String -> Text
Data.Text.pack (String -> Text) -> [String] -> [Text]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> String -> [String]
forall a. Arbitrary a => a -> [a]
shrink (Text -> String
Data.Text.unpack Text
xs)

instance {-# OVERLAPPING #-} Arbitrary (Maybe Text) where
  arbitrary :: Gen (Maybe Text)
arbitrary = [(Int, Gen (Maybe Text))] -> Gen (Maybe Text)
forall a. HasCallStack => [(Int, Gen a)] -> Gen a
frequency
    [ (Int
1, Maybe Text -> Gen (Maybe Text)
forall a. a -> Gen a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Text
forall a. Maybe a
Nothing)
    , (Int
3, Text -> Maybe Text
forall a. a -> Maybe a
Just (Text -> Maybe Text) -> Gen Text -> Gen (Maybe Text)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Gen Text
forall a. Arbitrary a => Gen a
arbitrary Gen Text -> (Text -> Bool) -> Gen Text
forall a. Gen a -> (a -> Bool) -> Gen a
`suchThat` (Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
/= Text
forall a. Monoid a => a
mempty))
    ]