packages feed

hspec-quickcheck-classes (empty) → 0.0.0.0

raw patch · 6 files changed

+321/−0 lines, 6 filesdep +QuickCheckdep +basedep +hspec

Dependencies added: QuickCheck, base, hspec, hspec-quickcheck-classes, quickcheck-classes

Files

+ CHANGELOG.md view
@@ -0,0 +1,3 @@+# 0.0.0.0++- Initial release.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Jonathan Knowles (c) 2026++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Jonathan Knowles nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,55 @@+# `hspec-quickcheck-classes`++[![Latest Release](+  https://img.shields.io/hackage/v/hspec-quickcheck-classes?label=Latest%20Release&color=227755+)](https://hackage.haskell.org/package/hspec-quickcheck-classes)+[![Development Branch](+  https://img.shields.io/badge/Development%20Branch-API%20Documentation-225577+)](https://jonathanknowles.github.io/hspec-quickcheck-classes/)++This package integrates [Hspec](https://hackage.haskell.org/package/hspec) with+[quickcheck-classes](https://hackage.haskell.org/package/quickcheck-classes),+making it convenient for Hspec test suites to include tests for the lawfulness+of type class instances.++# Usage++To test that a type satisfies the laws of one or more type classes:++```haskell+testLaws @Bool+  [ eqLaws+  , ordLaws+  , showLaws+  ]+```++## Kind polymorphism++The `testLaws` function is **kind-polymorphic**, supporting type parameters of+any kind.++This means it can be used to test instances of type classes whose type+parameters are not of kind `Type`.++For example, with `Maybe` (which has kind `Type -> Type`):++```haskell+testLaws @Maybe+  [ applicativeLaws+  , functorLaws+  , monadLaws+  , foldableLaws+  , traversableLaws+  ]+```++And with `Either` (which has kind `Type -> Type -> Type`):++```haskell+testLaws @Either+  [ bifoldableLaws+  , bifunctorLaws+  , bitraversableLaws+  ]+```
+ components/lib/Test/Hspec/QuickCheck/Classes.hs view
@@ -0,0 +1,108 @@+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-}++module Test.Hspec.QuickCheck.Classes+  ( testLaws+  ) where++import Data.Kind+  ( Type+  )+import Data.Proxy+  ( Proxy (Proxy)+  )+import Data.Typeable+  ( Typeable+  , typeRep+  )+import GHC.Stack+  ( HasCallStack+  )+import Test.Hspec+  ( Spec+  )+import Test.QuickCheck+  ( Property+  )+import Test.QuickCheck.Classes+  ( Laws (lawsProperties, lawsTypeclass)+  )++import qualified Test.Hspec as Hspec++_importsRequiredForHaddock :: ()+_importsRequiredForHaddock = undefined+  where+    _type :: Type+    _type = undefined++-- | Tests that a type satisfies the laws of one or more typeclasses.+--+-- For example, to test that 'Bool' satisfies the laws of 'Eq', 'Ord', and+-- 'Show':+--+-- @+-- 'testLaws' \@'Bool'+--   [ 'Test.QuickCheck.Classes.eqLaws'+--   , 'Test.QuickCheck.Classes.ordLaws'+--   , 'Test.QuickCheck.Classes.showLaws'+--   ]+-- @+--+-- === Kind polymorphism+--+-- The 'testLaws' function can also test instances of type classes whose type+-- parameters are not of kind 'Type'.+--+-- For example, with 'Maybe', which has kind @'Type' -> 'Type'@:+--+-- @+-- 'testLaws' \@'Maybe'+--   [ 'Test.QuickCheck.Classes.applicativeLaws'+--   , 'Test.QuickCheck.Classes.functorLaws'+--   , 'Test.QuickCheck.Classes.monadLaws'+--   , 'Test.QuickCheck.Classes.foldableLaws'+--   , 'Test.QuickCheck.Classes.traversableLaws'+--   ]+-- @+--+-- And with 'Either', which has kind @'Type' -> 'Type' -> 'Type'@:+--+-- @+-- 'testLaws' \@'Either'+--   [ 'Test.QuickCheck.Classes.bifoldableLaws'+--   , 'Test.QuickCheck.Classes.bifunctorLaws'+--   , 'Test.QuickCheck.Classes.bitraversableLaws'+--   ]+-- @+testLaws+  :: forall a+   . Typeable a+  => HasCallStack+  => [Proxy a -> Laws]+  -> Spec+testLaws = Hspec.describe specDescription . mapM_ testLawsFor+  where+    specDescription :: String+    specDescription = unwords ["Testing laws for", typeName]+      where+        typeName :: String+        typeName = show $ typeRep $ Proxy @a++    testLawsFor :: (Proxy a -> Laws) -> Spec+    testLawsFor toLaws =+      Hspec.describe typeclassName $+        mapM_ testNamedProperty namedProperties+      where+        laws :: Laws+        laws = toLaws Proxy++        namedProperties :: [(String, Property)]+        namedProperties = lawsProperties laws++        testNamedProperty :: (String, Property) -> Spec+        testNamedProperty (name, property) = Hspec.it name property++        typeclassName :: String+        typeclassName = lawsTypeclass laws
+ components/test/Main.hs view
@@ -0,0 +1,62 @@+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE NoImplicitPrelude #-}++module Main (main) where++import Data.Bool+  ( Bool+  )+import Data.Either+  ( Either+  )+import Data.Function+  ( ($)+  )+import Data.Maybe+  ( Maybe+  )+import System.IO+  ( IO+  )+import Test.Hspec+  ( hspec+  )+import Test.Hspec.QuickCheck.Classes+  ( testLaws+  )+import Test.QuickCheck.Classes+  ( applicativeLaws+  , bifoldableLaws+  , bifunctorLaws+  , bitraversableLaws+  , eqLaws+  , foldableLaws+  , functorLaws+  , monadLaws+  , ordLaws+  , showLaws+  , traversableLaws+  )++main :: IO ()+main = hspec $ do+  -- Demonstrates usage with an argument of kind 'Type':+  testLaws @Bool+    [ eqLaws+    , ordLaws+    , showLaws+    ]+  -- Demonstrates usage with an argument of kind 'Type -> Type':+  testLaws @Maybe+    [ applicativeLaws+    , functorLaws+    , monadLaws+    , foldableLaws+    , traversableLaws+    ]+  -- Demonstrates usage with an argument of kind 'Type -> Type -> Type':+  testLaws @Either+    [ bifoldableLaws+    , bifunctorLaws+    , bitraversableLaws+    ]
+ hspec-quickcheck-classes.cabal view
@@ -0,0 +1,63 @@+cabal-version:  3.0+name:           hspec-quickcheck-classes+version:        0.0.0.0+synopsis:       Integration between Hspec and quickcheck-classes+category:       Testing+homepage:       https://github.com/jonathanknowles/hspec-quickcheck-classes+bug-reports:    https://github.com/jonathanknowles/hspec-quickcheck-classes/issues+author:         Jonathan Knowles+maintainer:     mail@jonathanknowles.net+copyright:      Jonathan Knowles+license:        BSD-3-Clause+license-file:   LICENSE+build-type:     Simple++description:++  Integrates Hspec with quickcheck-classes, making it convenient for Hspec test+  suites to include tests for the lawfulness of type class instances.++extra-doc-files:+  CHANGELOG.md+  README.md++common dependency-base+    build-depends:base                  >= 4.16.4.0   && < 4.23+common dependency-hspec+    build-depends:hspec                 >= 2.11.17    && < 2.12+common dependency-QuickCheck+    build-depends:QuickCheck            >= 2.16.0.0   && < 2.19+common dependency-quickcheck-classes+    build-depends:quickcheck-classes    >= 0.6.5.0    && < 0.7++source-repository head+  type: git+  location: https://github.com/jonathanknowles/hspec-quickcheck-classes++library+  import:+    , dependency-base+    , dependency-hspec+    , dependency-QuickCheck+    , dependency-quickcheck-classes+  exposed-modules:+      Test.Hspec.QuickCheck.Classes+  hs-source-dirs:+      components/lib+  ghc-options: -Wall+  default-language: Haskell2010++test-suite test+  import:+    , dependency-base+    , dependency-hspec+    , dependency-QuickCheck+    , dependency-quickcheck-classes+  type: exitcode-stdio-1.0+  main-is: Main.hs+  hs-source-dirs:+      components/test+  ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N+  build-depends:+    , hspec-quickcheck-classes+  default-language: Haskell2010