genvalidity-hspec-optics 0.0.0.0 → 0.1.0.0
raw patch · 3 files changed
+201/−14 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Test.Validity.Optics: lensGettingProducesValid :: (Show s, GenUnchecked s, Show b, Validity b) => Lens s s b b -> Property
+ Test.Validity.Optics: lensGettingProducesValidOnArbitrary :: (Show s, Arbitrary s, Show b, Validity b) => Lens s s b b -> Property
+ Test.Validity.Optics: lensGettingProducesValidOnGen :: (Validity b, Show b, Show s) => Lens s s b b -> Gen s -> (s -> [s]) -> Property
+ Test.Validity.Optics: lensGettingProducesValidOnValid :: (Show s, GenValid s, Show b, GenValid b) => Lens s s b b -> Property
+ Test.Validity.Optics: lensSettingProducesValid :: (Show s, GenUnchecked s, Show b, GenUnchecked b, Show t, Validity t) => Lens s t a b -> Property
+ Test.Validity.Optics: lensSettingProducesValidOnArbitrary :: (Show s, Arbitrary s, Show b, Arbitrary b, Show t, Validity t) => Lens s t a b -> Property
+ Test.Validity.Optics: lensSettingProducesValidOnGen :: (Show s, Show b, Show t, Validity t) => Lens s t a b -> Gen b -> (b -> [b]) -> Gen s -> (s -> [s]) -> Property
+ Test.Validity.Optics: lensSettingProducesValidOnValid :: (Show s, GenValid s, Show b, GenValid b, Show t, Validity t) => Lens s t a b -> Property
- Test.Validity.Optics: lensSpec :: forall s b. (Show b, Eq b, GenUnchecked b, Show s, Eq s, GenUnchecked s) => Lens s s b b -> Spec
+ Test.Validity.Optics: lensSpec :: forall s b. (Show b, Eq b, GenUnchecked b, Validity b, Show s, Eq s, GenUnchecked s, Validity s) => Lens s s b b -> Spec
- Test.Validity.Optics: lensSpecOnArbitrary :: forall s b. (Show b, Eq b, Arbitrary b, Show s, Eq s, Arbitrary s) => Lens s s b b -> Spec
+ Test.Validity.Optics: lensSpecOnArbitrary :: forall s b. (Show b, Eq b, Arbitrary b, Validity b, Show s, Eq s, Arbitrary s, Validity s) => Lens s s b b -> Spec
- Test.Validity.Optics: lensSpecOnGen :: (Show b, Eq b, Show s, Eq s) => Lens s s b b -> Gen b -> String -> (b -> [b]) -> Gen s -> String -> (s -> [s]) -> Spec
+ Test.Validity.Optics: lensSpecOnGen :: (Show b, Eq b, Validity b, Show s, Eq s, Validity s) => Lens s s b b -> Gen b -> String -> (b -> [b]) -> Gen s -> String -> (s -> [s]) -> Spec
Files
- genvalidity-hspec-optics.cabal +5/−4
- src/Test/Validity/Optics.hs +158/−8
- test/Test/Validity/OpticsSpec.hs +38/−2
genvalidity-hspec-optics.cabal view
@@ -1,11 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.28.2.+cabal-version: >= 1.10++-- This file has been generated from package.yaml by hpack version 0.29.6. -- -- see: https://github.com/sol/hpack ----- hash: ecb9b0d1832fdff54efd2e5d6f1c72a9329c9bbdc19155ebd06520044b80dbee+-- hash: 38a81f3211972dd978ce11429e65c9e83d7fbe78b4c022ae1d94312a2b248ba8 name: genvalidity-hspec-optics-version: 0.0.0.0+version: 0.1.0.0 synopsis: Standard spec's for optics description: Standard spec's for optics category: Testing@@ -18,7 +20,6 @@ license: MIT license-file: LICENSE build-type: Simple-cabal-version: >= 1.10 source-repository head type: git
src/Test/Validity/Optics.hs view
@@ -4,8 +4,6 @@ {-# LANGUAGE TypeApplications #-} -- | Standard test `Spec`s for optics------ You will need @TypeApplications@ to use these. module Test.Validity.Optics ( lensSpecOnValid , lensSpec@@ -14,6 +12,14 @@ , lensLaw1 , lensLaw2 , lensLaw3+ , lensGettingProducesValidOnValid+ , lensGettingProducesValid+ , lensGettingProducesValidOnArbitrary+ , lensGettingProducesValidOnGen+ , lensSettingProducesValidOnValid+ , lensSettingProducesValid+ , lensSettingProducesValidOnArbitrary+ , lensSettingProducesValidOnGen ) where import Lens.Micro@@ -23,13 +29,14 @@ import Test.Hspec import Test.QuickCheck+ import Test.Validity.Utils -- | Standard test spec for properties lenses for valid values -- -- Example usage: ----- lensSpecOnValid ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+-- > lensSpecOnValid ((_2) :: Lens (Double, Double) (Double, Double) Double Double) lensSpecOnValid :: forall s b. (Show b, Eq b, GenValid b, Show s, Eq s, GenValid s) => Lens s s b b@@ -48,9 +55,18 @@ -- -- Example usage: ----- lensSpec ((_2) :: Lens (Int, Int) (Int, Int) Int Int)+-- > lensSpec ((_2) :: Lens (Int, Int) (Int, Int) Int Int) lensSpec ::- forall s b. (Show b, Eq b, GenUnchecked b, Show s, Eq s, GenUnchecked s)+ forall s b.+ ( Show b+ , Eq b+ , GenUnchecked b+ , Validity b+ , Show s+ , Eq s+ , GenUnchecked s+ , Validity s+ ) => Lens s s b b -> Spec lensSpec l =@@ -67,9 +83,18 @@ -- -- Example usage: ----- lensSpecOnArbitrary ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+-- > lensSpecOnArbitrary ((_2) :: Lens (Double, Double) (Double, Double) Double Double) lensSpecOnArbitrary ::- forall s b. (Show b, Eq b, Arbitrary b, Show s, Eq s, Arbitrary s)+ forall s b.+ ( Show b+ , Eq b+ , Arbitrary b+ , Validity b+ , Show s+ , Eq s+ , Arbitrary s+ , Validity s+ ) => Lens s s b b -> Spec lensSpecOnArbitrary l =@@ -95,7 +120,7 @@ -- > "tuples of negative valid doubles" -- > (const []) lensSpecOnGen ::- (Show b, Eq b, Show s, Eq s)+ (Show b, Eq b, Validity b, Show s, Eq s, Validity s) => Lens s s b b -> Gen b -> String@@ -116,11 +141,24 @@ (unwords ["satisfies the third lens law for", genBName, "and", genSName]) $ lensLaw3 l genB shrinkB genS shrinkS+ it (unwords ["gets valid values from", genSName, "values"]) $+ lensGettingProducesValidOnGen l genS shrinkS+ it+ (unwords+ [ "produces valid values when it is used to set"+ , genBName+ , "values on"+ , genSName+ , "values"+ ]) $+ lensSettingProducesValidOnGen l genB shrinkB genS shrinkS -- | A property combinator for the first lens law: -- -- > view l (set l v s) ≡ v --+-- Example usage:+-- -- prop> lensLaw1 ((_2) :: Lens (Double, Double) (Double, Double) Double Double) genValid shrinkValid genValid shrinkValid lensLaw1 :: (Show b, Eq b, Show s)@@ -138,6 +176,8 @@ -- -- > set l (view l s) s ≡ s --+-- Example usage:+-- -- prop> lensLaw2 ((_2) :: Lens (Double, Double) (Double, Double) Double Double) genValid shrinkValid lensLaw2 :: (Show s, Eq s) => Lens s s b b -> Gen s -> (s -> [s]) -> Property lensLaw2 l genS shrinkS =@@ -147,6 +187,8 @@ -- -- > set l v' (set l v s) ≡ set l v' s --+-- Example usage:+-- -- prop> lensLaw3 ((_2) :: Lens (Double, Double) (Double, Double) Double Double) genValid shrinkValid genValid shrinkValid lensLaw3 :: (Show b, Eq b, Show s, Eq s)@@ -161,3 +203,111 @@ forAllShrink genB shrinkB $ \b' -> forAllShrink genS shrinkS $ \s -> set l b' (set l b s) `shouldBe` set l b' s++-- | A property combinator to test whether getting values via a lens on valid values produces valid values.+--+-- Example Usage:+--+-- prop> lensGettingProducesValidOnValid ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+lensGettingProducesValidOnValid ::+ (Show s, GenValid s, Show b, GenValid b) => Lens s s b b -> Property+lensGettingProducesValidOnValid l =+ lensGettingProducesValidOnGen l genValid shrinkValid++-- | A property combinator to test whether getting values via a lens on unchecked values produces valid values.+--+-- Example Usage:+--+-- prop> lensGettingProducesValid ((_2) :: Lens (Int, Int) (Int, Int) Int Int)+lensGettingProducesValid ::+ (Show s, GenUnchecked s, Show b, Validity b) => Lens s s b b -> Property+lensGettingProducesValid l =+ lensGettingProducesValidOnGen l genUnchecked shrinkUnchecked++-- | A property combinator to test whether getting values via a lens on arbitrary values produces valid values.+--+-- Example Usage:+--+-- prop> lensGettingProducesValidOnArbitrary ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+lensGettingProducesValidOnArbitrary ::+ (Show s, Arbitrary s, Show b, Validity b)+ => Lens s s b b+ -> Property+lensGettingProducesValidOnArbitrary l =+ lensGettingProducesValidOnGen l arbitrary shrink++-- | A property combinator to test whether getting values generated by given a generator via a lens on values generated by a given generator produces valid values.+--+-- > isValid (view l s)+--+-- Example Usage:+--+-- prop> lensGettingProducesValidOnGen ((_2) :: Lens (Double, Double) (Double, Double) Double Double) genValid shrinkValid+lensGettingProducesValidOnGen ::+ (Validity b, Show b, Show s)+ => Lens s s b b+ -> Gen s+ -> (s -> [s])+ -> Property+lensGettingProducesValidOnGen l genS shrinkS =+ forAllShrink genS shrinkS $ \s -> shouldBeValid $ view l s++-- | A property combinator to test whether setting valid values via a lens on valid values produces valid values.+--+-- Example usage:+--+-- prop> lensSettingProducesValidOnValid ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+lensSettingProducesValidOnValid ::+ (Show s, GenValid s, Show b, GenValid b, Show t, Validity t)+ => Lens s t a b+ -> Property+lensSettingProducesValidOnValid l =+ lensSettingProducesValidOnGen l genValid shrinkValid genValid shrinkValid++-- | A property combinator to test whether setting unchecked values via a lens on unchecked values produces valid values.+--+-- Example usage:+--+-- prop> lensSettingProducesValid ((_2) :: Lens (Int, Int) (Int, Int) Int Int)+lensSettingProducesValid ::+ (Show s, GenUnchecked s, Show b, GenUnchecked b, Show t, Validity t)+ => Lens s t a b+ -> Property+lensSettingProducesValid l =+ lensSettingProducesValidOnGen+ l+ genUnchecked+ shrinkUnchecked+ genUnchecked+ shrinkUnchecked++-- | A property combinator to test whether setting arbitrary values via a lens on arbitrary values produces valid values.+--+-- Example usage:+--+-- prop> lensSettingProducesValidOnArbitrary ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+lensSettingProducesValidOnArbitrary ::+ (Show s, Arbitrary s, Show b, Arbitrary b, Show t, Validity t)+ => Lens s t a b+ -> Property+lensSettingProducesValidOnArbitrary l =+ lensSettingProducesValidOnGen l arbitrary shrink arbitrary shrink++-- | A property combinator to test whether setting values generated by given a generator via a lens on values generated by a given generator produces valid values.+--+-- > isValid (set l b s)+--+-- Example usage:+--+-- prop> lensSettingProducesValidOnGen ((_2) :: Lens (Double, Double) (Double, Double) Double Double) genValid shrinkValid genValid shrinkValid+lensSettingProducesValidOnGen ::+ (Show s, Show b, Show t, Validity t)+ => Lens s t a b+ -> Gen b+ -> (b -> [b])+ -> Gen s+ -> (s -> [s])+ -> Property+lensSettingProducesValidOnGen l genB shrinkB genS shrinkS =+ forAllShrink genS shrinkS $ \s ->+ forAllShrink genB shrinkB $ \b -> shouldBeValid $ set l b s
test/Test/Validity/OpticsSpec.hs view
@@ -31,10 +31,46 @@ ((,) <$> (negate . abs <$> genValid) <*> (negate . abs <$> genValid)) "tuples of negative valid doubles" (const [])+ describe "lensGettingProducesValidOnValid" $+ it "holds for (_2) for doubles" $+ lensGettingProducesValidOnValid+ ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+ describe "lensGettingProducesValid" $+ it "holds for (_2) for ints" $+ lensGettingProducesValid ((_2) :: Lens (Int, Int) (Int, Int) Int Int)+ describe "lensGettingProducesValidOnArbitrary" $+ it "holds for (_2) for doubles" $+ lensGettingProducesValidOnArbitrary+ ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+ describe "lensGettingProducesValidOnGen" $+ it "holds for (_2) for special generators" $+ lensGettingProducesValidOnGen+ ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+ ((,) <$> (negate . abs <$> genValid) <*> (negate . abs <$> genValid))+ (const [])+ describe "lensSettingProducesValidOnValid" $+ it "holds for (_2) for doubles" $+ lensSettingProducesValidOnValid+ ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+ describe "lensSettingProducesValid" $+ it "holds for (_2) for ints" $+ lensSettingProducesValid ((_2) :: Lens (Int, Int) (Int, Int) Int Int)+ describe "lensSettingProducesValidOnArbitrary" $+ it "holds for (_2) for doubles" $+ lensSettingProducesValidOnArbitrary+ ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+ describe "lensSettingProducesValidOnGen" $+ it "holds for (_2) for special generators" $+ lensSettingProducesValidOnGen+ ((_2) :: Lens (Double, Double) (Double, Double) Double Double)+ (abs <$> genValid)+ (filter (0.0 >=) . shrinkValid)+ ((,) <$> (negate . abs <$> genValid) <*> (negate . abs <$> genValid))+ (const []) describe "myBoolLens" $- lensSpec myBoolLens -- For any unchecked value, prefer this version if you can.+ lensSpecOnValid myBoolLens describe "myRationalLens" $- lensSpecOnValid myRationalLens -- Only for valid values+ lensSpecOnValid myRationalLens data MyRecord = MyRecord { myBool :: Bool