genvalidity-text 0.2.0.0 → 0.3.0.0
raw patch · 4 files changed
+74/−84 lines, 4 filesdep +genvalidity-hspecdep ~QuickChecksetup-changedPVP ok
version bump matches the API change (PVP)
Dependencies added: genvalidity-hspec
Dependency ranges changed: QuickCheck
API changes (from Hackage documentation)
Files
- Setup.hs +1/−0
- genvalidity-text.cabal +45/−51
- src/Data/GenValidity/Text.hs +15/−11
- test/Data/GenValidity/TextSpec.hs +13/−22
Setup.hs view
@@ -1,2 +1,3 @@ import Distribution.Simple+ main = defaultMain
genvalidity-text.cabal view
@@ -1,55 +1,49 @@-name: genvalidity-text-version: 0.2.0.0-synopsis: GenValidity support for Text-description: Please see README.md-homepage: https://github.com/NorfairKing/validity#readme-license: MIT-license-file: LICENSE-author: Tom Sydney Kerckhove-maintainer: syd.kerckhove@gmail.com-copyright: Copyright: (c) 2016 Tom Sydney Kerckhove-category: Testing-build-type: Simple-cabal-version: >=1.10+name: genvalidity-text+version: 0.3.0.0+cabal-version: >=1.10+build-type: Simple+license: MIT+license-file: LICENSE+copyright: Copyright: (c) 2016 Tom Sydney Kerckhove+maintainer: syd.kerckhove@gmail.com+homepage: https://github.com/NorfairKing/validity#readme+synopsis: GenValidity support for Text+description:+ Please see README.md+category: Testing+author: Tom Sydney Kerckhove +source-repository head+ type: git+ location: https://github.com/NorfairKing/validity+ library- hs-source-dirs: src- exposed-modules: Data.GenValidity.Text- build-depends: base < 5- , validity- , validity-text- , genvalidity- , text- , array- , QuickCheck- default-language: Haskell2010+ exposed-modules:+ Data.GenValidity.Text+ build-depends:+ base <5,+ validity -any,+ validity-text -any,+ genvalidity -any,+ text -any,+ array -any,+ QuickCheck -any+ default-language: Haskell2010+ hs-source-dirs: src test-suite genvalidity-text-test- type:- exitcode-stdio-1.0- default-language:- Haskell2010- hs-source-dirs:- test- main-is:- Spec.hs- other-modules:- Data.GenValidity.TextSpec- ghc-options:- -threaded -rtsopts -with-rtsopts=-N- -Wall- -fno-warn-name-shadowing- build-depends:- base-- , hspec- , QuickCheck >= 2.8 && < 2.9-- , genvalidity- , genvalidity-text- , text---source-repository head- type: git- location: https://github.com/NorfairKing/validity+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ build-depends:+ base -any,+ hspec -any,+ QuickCheck,+ genvalidity -any,+ genvalidity-text -any,+ genvalidity-hspec -any,+ text -any+ default-language: Haskell2010+ hs-source-dirs: test+ other-modules:+ Data.GenValidity.TextSpec+ ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -fno-warn-name-shadowing
src/Data/GenValidity/Text.hs view
@@ -1,3 +1,5 @@+{-# OPTIONS_GHC -Wno-orphans #-}+ module Data.GenValidity.Text where import Data.GenValidity@@ -12,17 +14,19 @@ import Data.Text.Internal (Text(..)) instance GenUnchecked Text where- genUnchecked = Text <$> uncheckedArray <*> arbitrary <*> arbitrary- where- uncheckedArray =- sized $ \n -> do- size <- upTo n- ins <- replicateM size arbitrary- return $- A.run $ do- arr <- A.new size- forM_ (zip [0 ..] ins) $ uncurry $ A.unsafeWrite arr- return arr+ genUnchecked =+ sized $ \n -> do+ size <- upTo n+ arr <-+ do ins <- replicateM size arbitrary+ return $+ A.run $ do+ arr <- A.new size+ forM_ (zip [0 ..] ins) $ uncurry $ A.unsafeWrite arr+ return arr+ off <- upTo $ max 0 (size - 1)+ let len = size - off+ pure $ Text arr off len instance GenValid Text where genValid =
test/Data/GenValidity/TextSpec.hs view
@@ -1,55 +1,46 @@-module Data.GenValidity.TextSpec (spec) where+module Data.GenValidity.TextSpec+ ( spec+ ) where -import Test.Hspec-import Test.QuickCheck+import Test.Hspec+import Test.QuickCheck -import Data.GenValidity-import Data.GenValidity.Text+import Data.GenValidity+import Data.GenValidity.Text -import qualified Data.Text as T+import qualified Data.Text as T spec :: Spec spec = do describe "genValid" $ do it "is always empty when resized to 0" $ do forAll (resize 0 genValid) (`shouldSatisfy` T.null)- describe "textStartingWith" $ do it "is never empty" $ do forAll arbitrary $ \c ->- forAll (textStartingWith c) $ \t ->- t `shouldNotSatisfy` T.null-+ forAll (textStartingWith c) $ \t -> t `shouldNotSatisfy` T.null it "contains exactly the first character if resized to 0" $ do forAll arbitrary $ \c -> forAll (resize 0 $ textStartingWith c) $ \t -> t `shouldBe` T.pack [c]- it "contains exactly the first character if resized to 1" $ do forAll arbitrary $ \c -> forAll (resize 0 $ textStartingWith c) $ \t -> t `shouldBe` T.pack [c]- it "always starts with the given char" $ do forAll arbitrary $ \c ->- forAll (textStartingWith c) $ \t ->- T.head t `shouldBe` c-+ forAll (textStartingWith c) $ \t -> T.head t `shouldBe` c describe "textWithA" $ do it "contains the given character" $ do forAll arbitrary $ \c ->- forAll (textWithA c) $ \t ->- T.unpack t `shouldSatisfy` (elem c)-+ forAll (textWithA c) $ \t -> T.unpack t `shouldSatisfy` (elem c) describe "textWithoutAny" $ do it "never contains the given char" $ do forAll arbitrary $ \c -> forAll (textWithoutAny c) $ \t -> T.unpack t `shouldNotSatisfy` (elem c)- describe "textWithoutAnyOf" $ do it "never contains any of the given chars" $ do forAll arbitrary $ \cs ->- forAll (textWithoutAnyOf cs) $ \t ->- T.unpack t `shouldNotSatisfy` (\t -> any (`elem` t) cs)-+ forAll (textWithoutAnyOf cs) $ \text ->+ T.unpack text `shouldNotSatisfy` (\t -> any (`elem` t) cs)