packages feed

genvalidity-property 0.2.0.0 → 0.2.0.1

raw patch · 3 files changed

+35/−8 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Test.Validity.Property.Utils: shouldBeInvalid :: (Show a, Validity a) => a -> Expectation
+ Test.Validity.Property.Utils: shouldBeValid :: (Show a, Validity a) => a -> Expectation
- Test.Validity.Functions: producesValidsOnGen :: (Show a, Show b, Validity b) => (a -> b) -> Gen a -> (a -> [a]) -> Property
+ Test.Validity.Functions: producesValidsOnGen :: forall a b. (Show a, Show b, Validity b) => (a -> b) -> Gen a -> (a -> [a]) -> Property
- Test.Validity.Functions.Validity: producesValidsOnGen :: (Show a, Show b, Validity b) => (a -> b) -> Gen a -> (a -> [a]) -> Property
+ Test.Validity.Functions.Validity: producesValidsOnGen :: forall a b. (Show a, Show b, Validity b) => (a -> b) -> Gen a -> (a -> [a]) -> Property
- Test.Validity.Property: producesValidsOnGen :: (Show a, Show b, Validity b) => (a -> b) -> Gen a -> (a -> [a]) -> Property
+ Test.Validity.Property: producesValidsOnGen :: forall a b. (Show a, Show b, Validity b) => (a -> b) -> Gen a -> (a -> [a]) -> Property

Files

genvalidity-property.cabal view
@@ -2,10 +2,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 88ebdd6aba74a11de1e4d1cdf78781911c52e8e435ccf2d5810e9fa541c8947b+-- hash: e9c9e7e6228875c498d456f8962ef94cfad30210ea24ceb610ff94f0ee957673  name:           genvalidity-property-version:        0.2.0.0+version:        0.2.0.1 synopsis:       Standard properties for functions on `Validity` types description:    Standard properties for functions on `Validity` types category:       Testing
src/Test/Validity/Functions/Validity.hs view
@@ -19,19 +19,19 @@  import Data.GenValidity -import Test.Hspec import Test.QuickCheck +import Test.Validity.Property.Utils+ -- | The function produces valid output when the input is generated as -- specified by the given generator. producesValidsOnGen ::-       (Show a, Show b, Validity b)+       forall a b. (Show a, Show b, Validity b)     => (a -> b)     -> Gen a     -> (a -> [a])     -> Property-producesValidsOnGen func gen s =-    forAllShrink gen s $ \a -> func a `shouldSatisfy` isValid+producesValidsOnGen func gen s = forAllShrink gen s $ shouldBeValid . func  -- | The function produces valid output when the input is generated by -- @genValid@@@ -58,7 +58,7 @@     -> ((a, b) -> [(a, b)])     -> Property producesValidsOnGens2 func gen s =-    forAllShrink gen s $ \(a, b) -> func a b `shouldSatisfy` isValid+    forAllShrink gen s $ \(a, b) -> shouldBeValid $ func a b  producesValidsOnValids2 ::        (Show a, Show b, Show c, GenValid a, GenValid b, Validity c)@@ -85,7 +85,7 @@     -> ((a, b, c) -> [(a, b, c)])     -> Property producesValidsOnGens3 func gen s =-    forAllShrink gen s $ \(a, b, c) -> func a b c `shouldSatisfy` isValid+    forAllShrink gen s $ \(a, b, c) -> shouldBeValid $ func a b c  producesValidsOnValids3 ::        ( Show a
src/Test/Validity/Property/Utils.hs view
@@ -2,10 +2,15 @@     ( forAllUnchecked     , forAllValid     , forAllInvalid+    , shouldBeValid+    , shouldBeInvalid     , (<==>)     , (===>)     ) where +import Control.Monad (unless)++import Test.Hspec import Test.QuickCheck  import Data.GenValidity@@ -26,3 +31,25 @@  (<==>) :: Bool -> Bool -> Bool (<==>) a b = a ===> b && b ===> a++shouldBeValid :: (Show a, Validity a) => a -> Expectation+shouldBeValid a = do+    case prettyValidation a of+        Right _ -> pure ()+        Left err ->+            expectationFailure $+            unlines+                [ "'validate' reported this value to be invalid: " ++ show a+                , err+                , ""+                ]+    unless (isValid a) $+        expectationFailure $+        unlines+            [ "isValid considered this value invalid: " ++ show a+            , "This is odd because 'validate' reported no issues."+            , "Are you sure 'Validity' is implemented correctly?"+            ]++shouldBeInvalid :: (Show a, Validity a) => a -> Expectation+shouldBeInvalid a = a `shouldNotSatisfy` isValid