packages feed

genvalidity-hspec-persistent 0.0.0.1 → 1.0.0.0

raw patch · 6 files changed

+80/−72 lines, 6 filesdep ~genvaliditydep ~genvalidity-propertysetup-changedPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: genvalidity, genvalidity-property

API changes (from Hackage documentation)

- Test.Validity.Persist: persistSpecOnValid :: forall a. (Show a, Eq a, Typeable a, GenValid a, PersistField a) => Spec
- Test.Validity.Persist: persistSpec :: forall a. (Show a, Eq a, Typeable a, GenUnchecked a, PersistField a) => Spec
+ Test.Validity.Persist: persistSpec :: forall a. (Show a, Eq a, Typeable a, GenValid a, PersistField a) => Spec

Files

+ CHANGELOG.md view
@@ -0,0 +1,19 @@+# Changelog++## [1.0.0.0] - 2021-11-20++* Compatibility with `genvalidity >= 1.0.0.0`+* Renamed every combinator that ends in `OnValid` (or similar) to not have that suffix anymore.++### Removed++* Every combinator that relates to unchecked or invalid values.++## [0.1.1.2] - 2020-02-10++### Changed++* Removed the doctests+* Improved the cabal file++## [0.0.0.0] - 2019-06-22
LICENSE view
@@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016-2020 Tom Sydney Kerckhove+Copyright (c) 2016-2021 Tom Sydney Kerckhove  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
− Setup.hs
@@ -1,3 +0,0 @@-import Distribution.Simple--main = defaultMain
genvalidity-hspec-persistent.cabal view
@@ -1,23 +1,24 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack------ hash: a73cdedb7c072f48e81f2f75a910ab26eb53bce85e595938137996e2b48e15c4  name:           genvalidity-hspec-persistent-version:        0.0.0.1+version:        1.0.0.0 synopsis:       Standard spec's for persistent-related instances category:       Testing homepage:       http://cs-syd.eu bug-reports:    https://github.com/NorfairKing/validity/issues author:         Tom Sydney Kerckhove maintainer:     syd@cs-syd.eu-copyright:      Copyright: (c) 2019-2020 Tom Sydney Kerckhove+copyright:      Copyright: (c) 2016-2021 Tom Sydney Kerckhove license:        MIT license-file:   LICENSE build-type:     Simple+extra-source-files:+    LICENSE+    CHANGELOG.md  source-repository head   type: git@@ -34,7 +35,7 @@   build-depends:       QuickCheck     , base >=4.9 && <=5-    , genvalidity >=0.5+    , genvalidity >=1.0     , genvalidity-hspec >=0.6     , hspec     , persistent@@ -53,10 +54,10 @@   build-depends:       QuickCheck     , base >=4.9 && <=5-    , genvalidity >=0.7+    , genvalidity     , genvalidity-hspec     , genvalidity-hspec-persistent-    , genvalidity-property >=0.3+    , genvalidity-property     , genvalidity-text     , hspec     , persistent
src/Test/Validity/Persist.hs view
@@ -1,24 +1,23 @@+{-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-}-{-# LANGUAGE AllowAmbiguousTypes #-}  -- | Standard test `Spec`s and raw `Property`s for `PersistField` instances. -- -- You will need @TypeApplications@ to use these. module Test.Validity.Persist-  ( persistSpecOnValid-  , persistSpec-  , persistSpecOnArbitrary-  , persistSpecOnGen-  , fromPersistValueAndToPersistValueAreInversesOnGen-  ) where--import Data.GenValidity+  ( persistSpec,+    persistSpecOnArbitrary,+    persistSpecOnGen,+    fromPersistValueAndToPersistValueAreInversesOnGen,+  )+where  import Control.Monad+import Data.GenValidity import qualified Data.Text as T import Data.Typeable-import Database.Persist (PersistField(..))+import Database.Persist (PersistField (..)) import Test.Hspec import Test.QuickCheck import Test.Validity.Utils@@ -27,21 +26,12 @@ -- -- Example usage: ----- > persistSpecOnValid @Rational-persistSpecOnValid ::-     forall a. (Show a, Eq a, Typeable a, GenValid a, PersistField a)-  => Spec-persistSpecOnValid = persistSpecOnGen (genValid @a) "valid" shrinkValid---- | Standard test spec for properties of persistent-related functions for unchecked values------ Example usage:--- -- > persistSpec @Int persistSpec ::-     forall a. (Show a, Eq a, Typeable a, GenUnchecked a, PersistField a)-  => Spec-persistSpec = persistSpecOnGen (genUnchecked @a) "unchecked" shrinkUnchecked+  forall a.+  (Show a, Eq a, Typeable a, GenValid a, PersistField a) =>+  Spec+persistSpec = persistSpecOnGen (genValid @a) "valid" shrinkValid  -- | Standard test spec for properties of persistent-related functions for arbitrary values --@@ -49,8 +39,9 @@ -- -- > persistSpecOnArbitrary @Int persistSpecOnArbitrary ::-     forall a. (Show a, Eq a, Typeable a, Arbitrary a, PersistField a)-  => Spec+  forall a.+  (Show a, Eq a, Typeable a, Arbitrary a, PersistField a) =>+  Spec persistSpecOnArbitrary = persistSpecOnGen (arbitrary @a) "arbitrary" shrink  -- | Standard test spec for properties of persistent-related functions for a given generator (and a name for that generator).@@ -59,39 +50,41 @@ -- -- > persistSpecOnGen (genListOf $ pure 'a') "sequence of 'a's" persistSpecOnGen ::-     forall a. (Show a, Eq a, Typeable a, PersistField a)-  => Gen a-  -> String-  -> (a -> [a])-  -> Spec+  forall a.+  (Show a, Eq a, Typeable a, PersistField a) =>+  Gen a ->+  String ->+  (a -> [a]) ->+  Spec persistSpecOnGen gen genname s =   parallel $ do     let name = nameOf @a     describe ("PersistField " ++ name ++ " (" ++ genname ++ ")") $ do       describe ("fromPersistValue :: PersistValue -> Either Text " ++ name) $         it-          (unwords-             [ "ensures that toPersistValue and fromPersistValue are inverses for"-             , "\"" ++ genname-             , name ++ "\"" ++ "'s"-             ]) $-        fromPersistValueAndToPersistValueAreInversesOnGen gen s+          ( unwords+              [ "ensures that toPersistValue and fromPersistValue are inverses for",+                "\"" ++ genname,+                name ++ "\"" ++ "'s"+              ]+          )+          $ fromPersistValueAndToPersistValueAreInversesOnGen gen s  -- | -- -- prop> fromPersistValueAndToPersistValueAreInversesOnGen @Bool arbitrary shrink ----- prop> fromPersistValueAndToPersistValueAreInversesOnGen @Bool genUnchecked shrinkUnchecked+-- prop> fromPersistValueAndToPersistValueAreInversesOnGen @Bool genValid shrinkValid -- -- prop> fromPersistValueAndToPersistValueAreInversesOnGen @Bool genValid shrinkValid -- -- prop> fromPersistValueAndToPersistValueAreInversesOnGen @Int arbitrary shrink ----- prop> fromPersistValueAndToPersistValueAreInversesOnGen @Int genUnchecked shrinkUnchecked+-- prop> fromPersistValueAndToPersistValueAreInversesOnGen @Int genValid shrinkValid -- -- prop> fromPersistValueAndToPersistValueAreInversesOnGen @Int genValid shrinkValid fromPersistValueAndToPersistValueAreInversesOnGen ::-     (Show a, Eq a, PersistField a) => Gen a -> (a -> [a]) -> Property+  (Show a, Eq a, PersistField a) => Gen a -> (a -> [a]) -> Property fromPersistValueAndToPersistValueAreInversesOnGen gen s =   forAllShrink gen s $ \(a :: a) ->     let encoded = toPersistValue a@@ -99,22 +92,22 @@      in case errOrDecoded of           Left err ->             expectationFailure $-            unlines-              [ "Decoding failed with error"-              , T.unpack err-              , "instead of decoding to"-              , show a-              , "'encode' encoded it to the persist"-              , show encoded-              ]+              unlines+                [ "Decoding failed with error",+                  T.unpack err,+                  "instead of decoding to",+                  show a,+                  "'encode' encoded it to the persist",+                  show encoded+                ]           Right decoded ->             unless (decoded == a) $-            expectationFailure $-            unlines-              [ "Decoding succeeded, but the decoded value"-              , show decoded-              , "differs from expected decoded value"-              , show a-              , "'encode' encoded it to the persist"-              , show encoded-              ]+              expectationFailure $+                unlines+                  [ "Decoding succeeded, but the decoded value",+                    show decoded,+                    "differs from expected decoded value",+                    show a,+                    "'encode' encoded it to the persist",+                    show encoded+                  ]
test/Test/Validity/PersistSpec.hs view
@@ -2,17 +2,15 @@  module Test.Validity.PersistSpec where -import Test.Hspec- -- import Numeric.Natural import Data.GenValidity+import Test.Hspec import Test.Validity.Persist  spec :: Spec spec = do   persistSpecOnGen (genListOf $ pure 'a') "sequence of 'a's" (const [])   -- persistSpec @Double -- DOES NOT HOLD-  persistSpecOnValid @Rational+  persistSpec @Rational   persistSpec @Int   persistSpecOnArbitrary @Int-  -- persistSpecOnValid @Natural -- DOES NOT HOLD