fakedata-quickcheck 0.1.0 → 0.2.0
raw patch · 4 files changed
+69/−22 lines, 4 filesdep ~fakedatadep ~randomnew-uploaderPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: fakedata, random
API changes (from Hackage documentation)
Files
- Readme.md +0/−4
- fakedata-quickcheck.cabal +46/−8
- src/Test/QuickCheck/Gen/Faker.hs +12/−7
- test/Test/FakeQuickCheckSpec.hs +11/−3
Readme.md view
@@ -18,7 +18,3 @@ ``` See the full code in the tests.-------Added to a separate project as discussed in [here](https://github.com/psibi/fakedata/pull/27)
fakedata-quickcheck.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.34.2.+-- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack name: fakedata-quickcheck-version: 0.1.0+version: 0.2.0 synopsis: Fake a -> Gen a description: Use fakedata Fake monad for quicheck tests. See readme for examples at <https://github.com/fakedata-haskell/fakedata-quickcheck>. category: Random, Fake, FakeData@@ -32,13 +32,32 @@ Paths_fakedata_quickcheck hs-source-dirs: src- default-extensions: EmptyCase FlexibleContexts FlexibleInstances InstanceSigs MultiParamTypeClasses LambdaCase MultiWayIf NamedFieldPuns TupleSections DeriveFoldable DeriveFunctor DeriveGeneric DeriveLift DeriveTraversable DerivingStrategies GeneralizedNewtypeDeriving StandaloneDeriving OverloadedStrings TypeApplications+ default-extensions:+ EmptyCase+ FlexibleContexts+ FlexibleInstances+ InstanceSigs+ MultiParamTypeClasses+ LambdaCase+ MultiWayIf+ NamedFieldPuns+ TupleSections+ DeriveFoldable+ DeriveFunctor+ DeriveGeneric+ DeriveLift+ DeriveTraversable+ DerivingStrategies+ GeneralizedNewtypeDeriving+ StandaloneDeriving+ OverloadedStrings+ TypeApplications ghc-options: -Wall -Wcompat -Wincomplete-uni-patterns -Wredundant-constraints -Wincomplete-record-updates -Widentities build-depends: QuickCheck >=2.6 && <2.15 , base >=4.7 && <5- , fakedata >=0.6.0 && <0.9.0- , random >=1 && <1.2.0+ , fakedata+ , random default-language: Haskell2010 test-suite unit@@ -49,16 +68,35 @@ Paths_fakedata_quickcheck hs-source-dirs: test- default-extensions: EmptyCase FlexibleContexts FlexibleInstances InstanceSigs MultiParamTypeClasses LambdaCase MultiWayIf NamedFieldPuns TupleSections DeriveFoldable DeriveFunctor DeriveGeneric DeriveLift DeriveTraversable DerivingStrategies GeneralizedNewtypeDeriving StandaloneDeriving OverloadedStrings TypeApplications+ default-extensions:+ EmptyCase+ FlexibleContexts+ FlexibleInstances+ InstanceSigs+ MultiParamTypeClasses+ LambdaCase+ MultiWayIf+ NamedFieldPuns+ TupleSections+ DeriveFoldable+ DeriveFunctor+ DeriveGeneric+ DeriveLift+ DeriveTraversable+ DerivingStrategies+ GeneralizedNewtypeDeriving+ StandaloneDeriving+ OverloadedStrings+ TypeApplications ghc-options: -Wall -Wcompat -Wincomplete-uni-patterns -Wredundant-constraints -Wincomplete-record-updates -Widentities build-depends: QuickCheck >=2.6 && <2.15 , base >=4.7 && <5- , fakedata >=0.6.0 && <0.9.0+ , fakedata , fakedata-quickcheck , hspec , hspec-core- , random >=1 && <1.2.0+ , random , regex-tdfa , text default-language: Haskell2010
src/Test/QuickCheck/Gen/Faker.hs view
@@ -12,15 +12,20 @@ fakeQuickcheck :: Fake a -> Q.Gen a fakeQuickcheck = fakeQuickcheck' defaultFakerSettings --- | copied from https://github.com/parsonsmatt/hedgehog-fakedata/blob/d342c6eb5aeb9990bb36ede1d1f08becc7d71e16/src/Hedgehog/Gen/Faker.hs--- Works in Quickcheck gen instead of hedgehog+-- | Select a value 'Fake' program in 'Gen'. ----- Select a value 'Fake' program in 'Gen'.+-- Example property to check that names aren't empty: ----- Note that the implementation relies on 'unsafePerformIO'.--- The faker library uses IO internally for looking up data files.--- but 'liftIO' in the 'Fake' monad is a gateway to arbitrary side effects.--- This library doesn't solve that.+-- @+-- λ> import Faker.Name (name)+-- λ> import Test.QuickCheck.Gen.Faker+-- λ> import qualified Test.QuickCheck as Q+-- λ> import qualified Data.Text as T+-- λ> Q.quickCheck (Q.forAll (fakeQuickcheck name) (not . T.null))+-- +++ OK, passed 100 tests.+--+-- @+ fakeQuickcheck' :: FakerSettings -> Fake a -> Q.Gen a fakeQuickcheck' fakerSettings f = do randomGen <- mkStdGen <$> Q.choose (minBound, maxBound)
test/Test/FakeQuickCheckSpec.hs view
@@ -15,8 +15,9 @@ import qualified Faker.Internet as F import Test.Hspec import qualified Test.QuickCheck as Q+import qualified Test.QuickCheck.Gen as QG import Data.Char(isAlphaNum)-+import Data.List (nub) isDomain :: Text -> Bool isDomain = (=~ ddd) . T.unpack@@ -26,8 +27,11 @@ spec :: Spec spec = do- describe "fakedata quickcheck" $- it "forall domain fullfils is a domain name regex" $ Q.property $ Q.forAll (fakeQuickcheck domain) isDomain+ describe "fakedata quickcheck" $ do+ it "forall domain fullfils is a domain name regex" $ Q.property (Q.forAll (fakeQuickcheck domain) isDomain)+ it "has different sample values" $ do+ values <- QG.sample' (fakeQuickcheck CM.name)+ (isUnique values) `shouldBe` True domain :: Fake Text domain = do@@ -37,3 +41,7 @@ fixupName :: Text -> Text fixupName = T.filter (\c -> isAlphaNum c || c == '_') . T.replace " " "_"++-- | Check that at least a single value is different+isUnique :: [Text] -> Bool+isUnique xs = length (nub xs) > 1