packages feed

hspec-expectations-lens (empty) → 0.1.0.0

raw patch · 7 files changed

+194/−0 lines, 7 filesdep +HUnitdep +basedep +hspecsetup-changed

Dependencies added: HUnit, base, hspec, hspec-expectations, hspec-expectations-lens, lens, silently

Files

+ CHANGELOG.md view
@@ -0,0 +1,4 @@+0.1.0.0+=======++`shouldHave`, `shouldNotHave`, `shouldView`, `shouldPreview`, and `shouldList`
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2013, Matvey Aksenov++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 Matvey Aksenov 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,5 @@+hspec-expectations-lens+======+[![Build Status](https://secure.travis-ci.org/supki/hspec-expectations-lens.png?branch=master)](http://travis-ci.org/supki/hspec-expectations-lens)++Hspec expectations for the lens stuff
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hspec-expectations-lens.cabal view
@@ -0,0 +1,48 @@+name:                hspec-expectations-lens+version:             0.1.0.0+synopsis:            Hspec expectations for the lens stuff+description:+  Package adds hspec expectations (@\`shouldX\`@ things)+  that work nicely with the "lens" library+homepage:            https://github.com/supki/hspec-expectations-lens+license:             BSD3+license-file:        LICENSE+author:              Matvey Aksenov+maintainer:          matvey.aksenov@gmail.com+category:            Testing+build-type:          Simple+extra-source-files:+  CHANGELOG.md+  README.md+cabal-version:       >= 1.10++source-repository head+  type:     git+  location: https://github.com/supki/hspec-expectations-lens++source-repository this+  type:     git+  tag:      0.1.0.0+  location: https://github.com/supki/hspec-expectations-lens++library+  default-language:    Haskell2010+  hs-source-dirs:      src+  build-depends:+      base                    == 4.*+    , hspec-expectations+    , HUnit+  exposed-modules:+    Test.Hspec.Expectations.Lens++test-suite spec+  type:                exitcode-stdio-1.0+  default-language:    Haskell2010+  hs-source-dirs:      test+  main-is:             Spec.hs+  build-depends:+      base                    == 4.*+    , hspec+    , hspec-expectations-lens+    , lens                    >= 3.9+    , silently
+ src/Test/Hspec/Expectations/Lens.hs view
@@ -0,0 +1,104 @@+{-# LANGUAGE Rank2Types #-}+-- | Hspec expectations for the lens stuff+module Test.Hspec.Expectations.Lens+  ( -- * Expectations+    shouldHave, shouldNotHave+  , shouldView+  , shouldPreview+  , shouldList+  , through+  ) where++import Control.Applicative (Const(..))+import Data.Monoid (Any(..), First(..), Endo(..))+import Test.Hspec.Expectations (Expectation)+import Test.HUnit (assertBool)++{-# ANN module "HLint: Use camelCase" #-}+++infixl 1 `shouldHave`, `shouldNotHave`, `shouldView`, `shouldPreview`, `shouldList`, `through`++-- | @x \`shouldHave\` l@ sets the expectation that 'Fold' @l@ has+-- non-zero number of targets in @x@+shouldHave+  :: Show s+  => s+  -> ((a -> Const Any a) -> s -> Const Any s)+  -> Expectation+x `shouldHave` f = assertBool errorMsg (has f x)+  where+    errorMsg = unwords ["Supplied Fold has zero targets for", show x]++-- | @x \`shouldNotHave\` l@ sets the expectation that 'Fold' @l@+-- has zero targets in @x@+shouldNotHave+  :: Show s+  => s+  -> ((a -> Const Any a) -> s -> Const Any s)+  -> Expectation+x `shouldNotHave` f = assertBool errorMsg (hasn't f x)+  where+    errorMsg = unwords ["Supplied Fold has targets for", show x]++-- | @x \`shouldView\` y \`through\` l@ sets the expectation that+-- you can see @y@ in @x@ though a 'Getter' @l@+shouldView+  :: (Show s, Show a, Eq a)+  => s+  -> a+  -> ((a -> Const a a) -> s -> Const a s)+  -> Expectation+(x `shouldView` y) l = assertBool errorMsg (view l x == y)+  where+    errorMsg = unwords ["Can't view", show y, "from", show x, "through supplied Getter"]++-- | @x \`shouldPreview\` y \`through\` l@ sets the expectation that+-- you can list @y@ in @x@ first though a 'Fold' @l@+shouldPreview+  :: (Show s, Show a, Eq a)+  => s+  -> a+  -> ((a -> Const (First a) a) -> s -> Const (First a) s)+  -> Expectation+(x `shouldPreview` y) l = assertBool errorMsg (preview l x == Just y)+  where+    errorMsg = unwords ["Can't preview", show y, "from", show x, "through supplied Fold"]++-- | @x \`shouldList\` ys \`through\` l@ sets the expectation that+-- you can list @ys@ in @x@ though a 'Fold' @l@+shouldList+  :: (Show s, Show a, Eq a)+  => s+  -> [a]+  -> ((a -> Const (Endo [a]) a) -> s -> Const (Endo [a]) s)+  -> Expectation+(x `shouldList` y) l = assertBool errorMsg (toListOf l x == y)+  where+    errorMsg = unwords ["Can't list", show y, "from", show x, "through supplied Fold"]++-- | A helper to fight parentheses+--+-- @+-- through ≡ id+-- @+through :: a -> a+through = id++has :: ((a -> Const Any b) -> s -> Const Any t) -> s -> Bool+has l = getAny . foldMapOf l (\_ -> Any True)++hasn't :: ((a -> Const Any b) -> s -> Const Any t) -> s -> Bool+hasn't l = not . has l++view :: ((a -> Const a a) -> s -> Const a s) -> s -> a+view l = foldMapOf l id++preview :: ((a -> Const (First a) a) -> s -> Const (First a) s) -> s -> Maybe a+preview l s = getFirst (foldMapOf l (First . Just) s)++toListOf :: ((a -> Const (Endo [a]) a) -> s -> Const (Endo [a]) s) -> s -> [a]+toListOf l s = appEndo (foldMapOf l (\x -> Endo (x :)) s) []++foldMapOf :: ((a -> Const m b) -> s -> Const n t) -> (a -> m) -> s -> n+foldMapOf l f = getConst . l (Const . f)
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}