Skip to content

Commit

Permalink
cleanup: Remove QuickCheck dependency.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Feb 15, 2022
1 parent 4d35f9c commit 4557dee
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 107 deletions.
5 changes: 2 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ project(license = "hs-msgpack")
haskell_library(
name = "hs-msgpack-types",
srcs = glob(["src/**/*.*hs"]),
compiler_flags = ["-Wno-unused-imports"],
src_strip_prefix = "src",
version = "0.3.1",
version = "0.3.2",
visibility = ["//visibility:public"],
deps = [
hazel_library("QuickCheck"),
hazel_library("base"),
hazel_library("bytestring"),
hazel_library("containers"),
Expand Down Expand Up @@ -42,6 +40,7 @@ hspec_test(
hazel_library("hashable"),
hazel_library("hspec"),
hazel_library("monad-validate"),
hazel_library("quickcheck-instances"),
hazel_library("text"),
hazel_library("unordered-containers"),
hazel_library("vector"),
Expand Down
8 changes: 5 additions & 3 deletions msgpack-types.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: msgpack-types
version: 0.3.1
version: 0.3.2
synopsis: A Haskell implementation of MessagePack.
homepage: http://msgpack.org/
license: BSD3
Expand Down Expand Up @@ -30,6 +30,7 @@ library
-Wall
-fno-warn-unused-imports
exposed-modules:
Data.MessagePack.Tags
Data.MessagePack.Types
other-modules:
Data.MessagePack.Types.Assoc
Expand All @@ -39,7 +40,6 @@ library
Data.MessagePack.Types.Object
build-depends:
base < 5
, QuickCheck
, bytestring
, containers
, deepseq
Expand All @@ -56,9 +56,10 @@ test-suite testsuite
hs-source-dirs: test
main-is: testsuite.hs
other-modules:
Data.MessagePack.Arbitrary
Data.MessagePack.TagsSpec
Data.MessagePack.Types.AssocSpec
Data.MessagePack.Types.ClassSpec
Test.QuickCheck.Instances.MessagePack
ghc-options:
-Wall
-fno-warn-unused-imports
Expand All @@ -75,6 +76,7 @@ test-suite testsuite
, hspec
, monad-validate
, msgpack-types
, quickcheck-instances
, text
, unordered-containers
, vector
9 changes: 2 additions & 7 deletions src/Data/MessagePack/Types/Assoc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@ module Data.MessagePack.Types.Assoc
( Assoc (..)
) where

import Control.Applicative ((<$>))
import Control.DeepSeq (NFData)
import Data.Typeable (Typeable)
import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
import Control.DeepSeq (NFData)
import Data.Typeable (Typeable)

-- not defined for general Functor for performance reason.
-- (ie. you would want to write custom instances for each type using
-- specialized mapM-like functions)
newtype Assoc a
= Assoc { unAssoc :: a }
deriving (Show, Read, Eq, Ord, Typeable, NFData)

instance Arbitrary a => Arbitrary (Assoc a) where
arbitrary = Assoc <$> arbitrary
5 changes: 2 additions & 3 deletions src/Data/MessagePack/Types/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module Data.MessagePack.Types.Class
, defaultConfig
) where

import Control.Applicative (Applicative, (<$>), (<*>))
import Control.Arrow ((***))
import Control.Monad.Validate (MonadValidate (..))
import qualified Data.ByteString as S
Expand All @@ -45,8 +44,8 @@ import qualified Data.Text.Lazy as LT
import qualified Data.Vector as V
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Unboxed as VU
import Data.Word (Word, Word16, Word32,
Word64, Word8)
import Data.Word (Word16, Word32, Word64,
Word8)
import GHC.Generics (Generic, Rep, from, to)

import Data.MessagePack.Types.Assoc (Assoc (..))
Expand Down
2 changes: 0 additions & 2 deletions src/Data/MessagePack/Types/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
{-# LANGUAGE UndecidableInstances #-}
module Data.MessagePack.Types.Generic () where

import Control.Applicative (Applicative, (<$>), (<*>))
import Control.Monad ((>=>))
import Control.Monad.Trans.State.Strict (StateT, evalStateT, get,
put)
import Control.Monad.Validate (MonadValidate, refute)
Expand Down
18 changes: 8 additions & 10 deletions src/Data/MessagePack/Types/Object.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StrictData #-}
Expand All @@ -7,15 +6,14 @@ 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 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
28 changes: 0 additions & 28 deletions test/Data/MessagePack/Arbitrary.hs

This file was deleted.

16 changes: 16 additions & 0 deletions test/Data/MessagePack/TagsSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{-# LANGUAGE LambdaCase #-}
module Data.MessagePack.TagsSpec where

import Data.MessagePack.Tags
import Test.Hspec (Spec, describe, it, shouldSatisfy)

spec :: Spec
spec =
describe "Assoc" $
it "has a working Read/Show implementation" $ do
(TAG_nil :: Int) `shouldSatisfy` \case
TAG_nil -> True
_ -> False
(TAG_nil :: Integer) `shouldSatisfy` \case
TAG_nil -> True
_ -> False
9 changes: 6 additions & 3 deletions test/Data/MessagePack/Types/AssocSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
{-# LANGUAGE Trustworthy #-}
module Data.MessagePack.Types.AssocSpec where

import Data.MessagePack.Types (Assoc (..))
import Test.Hspec (Spec, describe, it, shouldBe)
import Test.QuickCheck (Arbitrary (..), property)
import Data.MessagePack.Types (Assoc (..))
import Test.Hspec (Spec, describe, it,
shouldBe)
import Test.QuickCheck (Arbitrary (..),
property)
import Test.QuickCheck.Instances.MessagePack ()

spec :: Spec
spec =
Expand Down
82 changes: 34 additions & 48 deletions test/Data/MessagePack/Types/ClassSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,40 @@
{-# LANGUAGE Trustworthy #-}
module Data.MessagePack.Types.ClassSpec where

import Control.Applicative (empty, pure, (<$>), (<*>),
(<|>))
import Control.Monad (mplus, mzero)
import Control.Monad.Validate (MonadValidate (..),
runValidate)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.HashMap.Strict as HashMap
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,
errorMessages)
import qualified Data.Text as Text
import qualified Data.Text.Lazy as LText
import qualified Data.Vector as V
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Unboxed as VU
import Data.Word (Word, Word16, Word32,
Word64, Word8)
import GHC.Generics (Generic)
import Test.Hspec (Spec, describe, it,
shouldBe, shouldSatisfy)
import Test.QuickCheck (Arbitrary (..),
genericShrink, property,
withMaxSuccess)
import Test.QuickCheck.Arbitrary.Generic (genericArbitrary)
import Control.Applicative (empty, pure, (<$>),
(<*>), (<|>))
import Control.Monad (mplus, mzero)
import Control.Monad.Validate (MonadValidate (..),
runValidate)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as LBS
import qualified Data.HashMap.Strict as HashMap
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.Types (Assoc (..),
MessagePack (..),
Object (..),
defaultConfig,
errorMessages)
import qualified Data.Text as Text
import qualified Data.Text.Lazy as LText
import qualified Data.Vector as V
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Unboxed as VU
import Data.Word (Word, Word16, Word32,
Word64, Word8)
import GHC.Generics (Generic)
import Test.Hspec (Spec, describe, it,
shouldBe, shouldSatisfy)
import Test.QuickCheck (Arbitrary (..),
genericShrink, property,
withMaxSuccess)
import Test.QuickCheck.Arbitrary.Generic (genericArbitrary)
import Test.QuickCheck.Instances ()
import Test.QuickCheck.Instances.MessagePack ()

data MyType
= SequenceTyCon Int String Int Int
Expand Down Expand Up @@ -82,23 +85,6 @@ instance Arbitrary MyType where
arbitrary = genericArbitrary
shrink = genericShrink

instance Arbitrary BS.ByteString where
arbitrary = BS.pack . take 10 <$> arbitrary
instance Arbitrary LBS.ByteString where
arbitrary = LBS.pack . take 10 <$> arbitrary
instance Arbitrary Text.Text where
arbitrary = Text.pack . take 10 <$> arbitrary
instance Arbitrary LText.Text where
arbitrary = LText.pack . take 10 <$> arbitrary
instance Arbitrary a => Arbitrary (V.Vector a) where
arbitrary = V.fromList <$> arbitrary
instance (Arbitrary a, VS.Storable a) => Arbitrary (VS.Vector a) where
arbitrary = VS.fromList <$> arbitrary
instance (Arbitrary a, VU.Unbox a) => Arbitrary (VU.Vector a) where
arbitrary = VU.fromList <$> arbitrary
instance (Arbitrary a, Hashable a, Eq a, Arbitrary b) => Arbitrary (HashMap.HashMap a b) where
arbitrary = HashMap.fromList <$> arbitrary


type Result a = Either [String] a

Expand Down
33 changes: 33 additions & 0 deletions test/Test/QuickCheck/Instances/MessagePack.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE Trustworthy #-}
module Test.QuickCheck.Instances.MessagePack () where

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


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 <$> Gen.resize (n `div` 2) arbitrary
, ObjectMap <$> Gen.resize (n `div` 4) arbitrary
, ObjectExt <$> arbitrary <*> arbitrary
]
where negatives = Gen.choose (minBound, -1)


instance Arbitrary a => Arbitrary (Assoc a) where
arbitrary = Assoc <$> arbitrary

0 comments on commit 4557dee

Please sign in to comment.