hspec-laws (empty) → 0.0.0
raw patch · 6 files changed
+134/−0 lines, 6 filesdep +QuickCheckdep +basedep +hspecsetup-changed
Dependencies added: QuickCheck, base, hspec, hspec-laws, markdown-unlit
Files
- LICENSE +19/−0
- README.lhs +35/−0
- Setup.lhs +3/−0
- hspec-laws.cabal +56/−0
- src/Test/Hspec/Laws.hs +20/−0
- test/Spec.hs +1/−0
+ LICENSE view
@@ -0,0 +1,19 @@+Copyright (c) 2012-2014 Simon Hengel <sol@typeful.net>++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ README.lhs view
@@ -0,0 +1,35 @@+# Reusable specifications+(similar in spirit to [checkers](http://hackage.haskell.org/package/checkers))++## Check Monoid laws++`shouldSatisfyMonoidLaws` can be used to specify, that a given type should+satisfy the Monoid laws.++~~~ {.haskell .literate}+-- file Spec.hs+import Test.Hspec+import Test.Hspec.Laws++main :: IO ()+main = hspec $ do+ describe "List as a Monoid" $+ shouldSatisfyMonoidLaws (undefined :: [Int])+~~~++Running this produces a nice spec.++~~~+$ runhaskell Spec.hs++List as a Monoid+ mempty+ - is a left identity+ - is a right identity++ mappend+ - is associative++Finished in 0.1142 seconds+3 examples, 0 failures+~~~
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ hspec-laws.cabal view
@@ -0,0 +1,56 @@+name: hspec-laws+version: 0.0.0+license: MIT+license-file: LICENSE+copyright: (c) 2012-2014 Simon Hengel+author: Simon Hengel <sol@typeful.net>+maintainer: Simon Hengel <sol@typeful.net>+build-type: Simple+cabal-version: >= 1.8+category: Testing+synopsis: Document and test laws for standard type classes+description: Document and test laws for standard type classes++source-repository head+ type: git+ location: https://github.com/hspec/hspec-laws++library+ ghc-options:+ -Wall+ hs-source-dirs:+ src+ exposed-modules:+ Test.Hspec.Laws+ build-depends:+ base == 4.*+ , hspec >= 1.4+ , QuickCheck++test-suite spec+ type:+ exitcode-stdio-1.0+ ghc-options:+ -Wall+ hs-source-dirs:+ test+ main-is:+ Spec.hs+ build-depends:+ base == 4.*+ , hspec-laws+ , hspec+ , QuickCheck++test-suite README+ type:+ exitcode-stdio-1.0+ ghc-options:+ -Wall -pgmL markdown-unlit+ main-is:+ README.lhs+ build-depends:+ base == 4.*+ , hspec-laws+ , hspec+ , markdown-unlit
+ src/Test/Hspec/Laws.hs view
@@ -0,0 +1,20 @@+-- | Reusable specifications.+module Test.Hspec.Laws (shouldSatisfyMonoidLaws) where++import Prelude+import Data.Monoid+import Test.QuickCheck+import Test.Hspec++shouldSatisfyMonoidLaws :: (Eq a, Show a, Monoid a, Arbitrary a) => a -> Spec+shouldSatisfyMonoidLaws t = do+ describe "mempty" $ do+ it "is a left identity" $ property $ \x ->+ mempty <> x == x `asTypeOf` t++ it "is a right identity" $ property $ \x ->+ x <> mempty == x `asTypeOf` t++ describe "mappend" $ do+ it "is associative" $ property $ \x y z ->+ (x <> y) <> z == x <> (y <> z) `asTypeOf` t
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}