Skip to content

Commit

Permalink
cleanup: Remove Arbitrary instance from main library.
Browse files Browse the repository at this point in the history
Reducing dependencies.
  • Loading branch information
iphydf committed Feb 14, 2022
1 parent 938c304 commit 9ebde92
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 27 deletions.
36 changes: 9 additions & 27 deletions src/Data/MessagePack/Types/Object.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ module Data.MessagePack.Types.Object
( Object (..)
) where

import Control.Applicative ((<$>), (<*>))
import Control.DeepSeq (NFData (..))
import qualified Data.ByteString as S
import Data.Int (Int64)
import qualified Data.Text as T
import Data.Typeable (Typeable)
import qualified Data.Vector as V
import Data.Word (Word64, Word8)
import GHC.Generics (Generic)
import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
import qualified Test.QuickCheck.Gen as Gen
import Control.Applicative ((<$>), (<*>))
import Control.DeepSeq (NFData (..))
import qualified Data.ByteString as S
import Data.Int (Int64)
import qualified Data.Text as T
import Data.Typeable (Typeable)
import qualified Data.Vector as V
import Data.Word (Word64, Word8)
import GHC.Generics (Generic)


-- | Object Representation of MessagePack data.
Expand Down Expand Up @@ -48,19 +46,3 @@ data Object
deriving (Read, Show, Eq, Ord, Typeable, Generic)

instance NFData Object

instance Arbitrary Object where
arbitrary = Gen.sized $ \n -> Gen.oneof
[ pure ObjectNil
, ObjectBool <$> arbitrary
, ObjectInt <$> negatives
, ObjectWord <$> arbitrary
, ObjectFloat <$> arbitrary
, ObjectDouble <$> arbitrary
, ObjectStr <$> (T.pack <$> arbitrary)
, ObjectBin <$> (S.pack <$> arbitrary)
, ObjectArray <$> (V.fromList <$> Gen.resize (n `div` 2) arbitrary)
, ObjectMap <$> (V.fromList <$> Gen.resize (n `div` 4) arbitrary)
, ObjectExt <$> arbitrary <*> (S.pack <$> arbitrary)
]
where negatives = Gen.choose (minBound, -1)
28 changes: 28 additions & 0 deletions test/Data/MessagePack/Arbitrary.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE Trustworthy #-}
module Data.MessagePack.Arbitrary () where

import qualified Data.ByteString as S
import Data.MessagePack.Types (Object (..))
import qualified Data.Text as T
import qualified Data.Vector as V
import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
import qualified Test.QuickCheck.Gen as Gen


instance Arbitrary Object where
arbitrary = Gen.sized $ \n -> Gen.oneof
[ pure ObjectNil
, ObjectBool <$> arbitrary
, ObjectInt <$> negatives
, ObjectWord <$> arbitrary
, ObjectFloat <$> arbitrary
, ObjectDouble <$> arbitrary
, ObjectStr <$> (T.pack <$> arbitrary)
, ObjectBin <$> (S.pack <$> arbitrary)
, ObjectArray <$> (V.fromList <$> Gen.resize (n `div` 2) arbitrary)
, ObjectMap <$> (V.fromList <$> Gen.resize (n `div` 4) arbitrary)
, ObjectExt <$> arbitrary <*> (S.pack <$> arbitrary)
]
where negatives = Gen.choose (minBound, -1)
1 change: 1 addition & 0 deletions test/Data/MessagePack/Types/ClassSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Data.Hashable (Hashable)
import Data.Int (Int16, Int32, Int64, Int8)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Map as Map
import Data.MessagePack.Arbitrary ()
import Data.MessagePack.Types (Assoc (..),
MessagePack (..),
Object (..), defaultConfig,
Expand Down

0 comments on commit 9ebde92

Please sign in to comment.