genvalidity-text 0.7.0.2 → 1.0.0.0
raw patch · 7 files changed
+162/−134 lines, 7 filesdep ~genvaliditysetup-changedPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: genvalidity
API changes (from Hackage documentation)
- Data.GenValidity.Text: instance (TypeError ...) => Data.GenValidity.GenUnchecked Data.Text.Internal.Lazy.Text
- Data.GenValidity.Text: instance (TypeError ...) => Data.GenValidity.GenUnchecked Data.Text.Internal.Text
+ Data.GenValidity.Text: genSingleLineText :: Gen Text
Files
- CHANGELOG.md +51/−0
- LICENSE +1/−1
- Setup.hs +0/−3
- bench/Main.hs +13/−14
- genvalidity-text.cabal +7/−6
- src/Data/GenValidity/Text.hs +13/−31
- test/Data/GenValidity/TextSpec.hs +77/−79
+ CHANGELOG.md view
@@ -0,0 +1,51 @@+# Changelog++## [1.0.0.0] - 2021-11-20++### Changed++* Compatibility with `genvalidity >= 1.0.0.0`++## [0.7.0.2] - 2020-02-10++## Changed++* Improved the cabal file++## [0.7.0.1] - 2019-12-05++## Changed++* Optimised the 'GenValid Text' instance to be 5x faster.++## Added++* `genText` with the new approach.+* `genTextBy` with the new approach where you can supply your own `Gen Char`.+++## [0.7.0.0] - 2019-06-26++## Changed++* Updated the 'GenValid Text' instance to use 'genValid :: Gen Char' instead of 'arbitrary :: Gen Char'.++## [0.6.0.0] - 2019-03-06++### Changed++* Removed the 'GenUnchecked' and 'GenInvalid' instance for Text.+* Poisoned those two instances as well.+* Removed an 'upTo' from the implementation of 'GenValid Text'.+ It should generate better sized Text now.++## [0.5.1.0] - 2018-08-25++### Added++* A `GenUnchecked`, `GenValid` and `GenInvalid` instance for lazy text++## Older versions++No history before version 0.5.1.0+
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
bench/Main.hs view
@@ -1,32 +1,31 @@ {-# LANGUAGE AllowAmbiguousTypes #-}-{-# LANGUAGE TypeApplications #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TypeApplications #-} module Main where -import Data.Text as Strict-import Data.Text.Lazy as Lazy- import Criterion.Main as Criterion- import Data.GenValidity-import Test.QuickCheck- import Data.GenValidity.Criterion import Data.GenValidity.Text+import Data.Text as Strict+import Data.Text.Lazy as Lazy+import Test.QuickCheck main :: IO () main = Criterion.defaultMain [ bgroup "Instances"- [genBench "Strict.Text" (genValid @Strict.Text), genBench "Lazy.Text" (genValid @Lazy.Text)]- , bgroup+ [ genBenchSizes "Strict.Text" (genValid @Strict.Text),+ genBenchSizes "Lazy.Text" (genValid @Lazy.Text)+ ],+ bgroup "Approaches"- [ genBench "via list (old version)" $ Strict.pack <$> genValid- , genBench "genText" genText- , genBench "genTextBy genValid" $ genTextBy genValid- , genBench "genTextBy (choose (minBound, maxBound)) (currently in use)" $- genTextBy (choose (minBound, maxBound))+ [ genBenchSizes "via list (old version)" $ Strict.pack <$> genValid,+ genBenchSizes "genText" genText,+ genBenchSizes "genTextBy genValid" $ genTextBy genValid,+ genBenchSizes "genTextBy (choose (minBound, maxBound)) (currently in use)" $+ genTextBy (choose (minBound, maxBound)) ] ]
genvalidity-text.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: 90ba697f2e33cb5f691e3e849adffedb8313bd211dfe400e134d429347999528 name: genvalidity-text-version: 0.7.0.2+version: 1.0.0.0 synopsis: GenValidity support for Text category: Testing homepage: https://github.com/NorfairKing/validity#readme bug-reports: https://github.com/NorfairKing/validity/issues author: Tom Sydney Kerckhove maintainer: syd@cs-syd.eu-copyright: Copyright: (c) 2016-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 @@ QuickCheck , array , base >=4.7 && <5- , genvalidity >=0.5+ , genvalidity >=1.0 , random , text , validity >=0.5
src/Data/GenValidity/Text.hs view
@@ -1,39 +1,21 @@ {-# OPTIONS_GHC -fno-warn-orphans #-}-{-# LANGUAGE CPP #-}-#if MIN_VERSION_base(4,9,0)-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE UndecidableInstances #-}-#endif+ module Data.GenValidity.Text where import Data.GenValidity+import qualified Data.Text as ST+import qualified Data.Text.Internal.Lazy as LT+import qualified Data.Text.Lazy as LT import Data.Validity.Text ()- import System.Random as Random import Test.QuickCheck import Test.QuickCheck.Gen import Test.QuickCheck.Random-#if !MIN_VERSION_base(4,8,0)-import Control.Applicative ((<*>), pure)-import Data.Functor ((<$>))-#endif-import qualified Data.Text as ST-import qualified Data.Text.Internal.Lazy as LT-import qualified Data.Text.Lazy as LT-#if MIN_VERSION_base(4,9,0)-import GHC.TypeLits-#endif+ instance GenValid ST.Text where genValid = genText shrinkValid = fmap ST.pack . shrinkValid . ST.unpack-#if MIN_VERSION_base(4,9,0)--- If you see this error and want to learn more, have a look at docs/BYTESTRING.md-instance GHC.TypeLits.TypeError ('GHC.TypeLits.Text "The GenUnchecked Data.Text.Text is disabled:" 'GHC.TypeLits.:$$: 'GHC.TypeLits.Text "Do not instantiate GenUnchecked, instantiate GenValid instead") =>- GenUnchecked ST.Text where- genUnchecked = error "unreachable"- shrinkUnchecked = error "unreachable"-#endif+ genText :: Gen ST.Text genText = do len <- genListLength@@ -60,13 +42,7 @@ lt <- resize b genValid pure $ LT.Chunk st lt shrinkValid = fmap LT.fromChunks . shrinkValid . LT.toChunks-#if MIN_VERSION_base(4,9,0)--- If you see this error and want to learn more, have a look at docs/BYTESTRING.md-instance GHC.TypeLits.TypeError ('GHC.TypeLits.Text "The GenUnchecked Data.Text.Lazy.Text is disabled:" 'GHC.TypeLits.:$$: 'GHC.TypeLits.Text "Do not instantiate GenUnchecked, instantiate GenValid instead") =>- GenUnchecked LT.Text where- genUnchecked = error "unreachable"- shrinkUnchecked = error "unreachable"-#endif+ -- | 'textStartingWith c' generates a 'Text' value that starts with 'c'. textStartingWith :: Char -> Gen ST.Text textStartingWith c =@@ -101,3 +77,9 @@ -- | 'textAllCaps' generates a 'Text' value with only upper-case characters. textAllCaps :: Gen ST.Text textAllCaps = ST.toUpper <$> genValid++-- | 'genSingleLineText' generates a single-line text, that is without any line separators.+--+-- See 'Data.GenValidity.genNonLineSeparator' and 'Data.Validity.isLineSeparator'+genSingleLineText :: Gen ST.Text+genSingleLineText = genTextBy genNonLineSeparator
test/Data/GenValidity/TextSpec.hs view
@@ -1,100 +1,98 @@ {-# LANGUAGE TypeApplications #-} module Data.GenValidity.TextSpec- ( spec- ) where+ ( spec,+ )+where import Control.Monad-import Data.List-import Data.Word-import Text.Printf--import Test.Hspec-import Test.QuickCheck-import Test.Validity- import Data.GenValidity.Text-+import Data.List import qualified Data.Text as ST import qualified Data.Text.Array as A import qualified Data.Text.Internal as ST import qualified Data.Text.Internal.Lazy as LT import qualified Data.Text.Lazy as LT+import Data.Word+import Test.Hspec+import Test.QuickCheck+import Test.Validity+import Text.Printf showTextDebug :: ST.Text -> String showTextDebug (ST.Text arr off len) =- unlines- [ unwords- [ "arr: "- , intercalate "," $- map (printf "%4d" :: Word16 -> String) $ A.toList arr off len- ]- , unwords- [ "hexarr:"- , intercalate "," $- map (printf "%4x" :: Word16 -> String) $ A.toList arr off len- ]- , unwords ["off: ", show off]- , unwords ["len: ", show len]- ]+ unlines+ [ unwords+ [ "arr: ",+ intercalate "," $+ map (printf "%4d" :: Word16 -> String) $ A.toList arr off len+ ],+ unwords+ [ "hexarr:",+ intercalate "," $+ map (printf "%4x" :: Word16 -> String) $ A.toList arr off len+ ],+ unwords ["off: ", show off],+ unwords ["len: ", show len]+ ] showLazyTextDebug :: LT.Text -> String showLazyTextDebug LT.Empty = "empty" showLazyTextDebug (LT.Chunk st lt) =- unlines- [ "A chuck with this strict text:"- , showTextDebug st- , "and this rest of the lazy text:"- , showLazyTextDebug lt- , ""- ]+ unlines+ [ "A chuck with this strict text:",+ showTextDebug st,+ "and this rest of the lazy text:",+ showLazyTextDebug lt,+ ""+ ] spec :: Spec spec = do- describe "Strict Text" $ do- genValidSpec @ST.Text- describe "genValid" $ do- it "is always empty when resized to 0" $- forAll (resize 0 genValid) (`shouldSatisfy` ST.null)- it "generates valid text" $- forAll (genValid) $ \t ->- unless (isValid t) $ expectationFailure $ showTextDebug t- describe "textStartingWith" $ do- it "is never empty" $- forAll arbitrary $ \c ->- forAll (textStartingWith c) $ \t ->- t `shouldNotSatisfy` ST.null- it "contains exactly the first character if resized to 0" $- forAll arbitrary $ \c ->- forAll (resize 0 $ textStartingWith c) $ \t ->- t `shouldBe` ST.pack [c]- it "contains exactly the first character if resized to 1" $- forAll arbitrary $ \c ->- forAll (resize 0 $ textStartingWith c) $ \t ->- t `shouldBe` ST.pack [c]- it "always starts with the given char" $- forAll arbitrary $ \c ->- forAll (textStartingWith c) $ \t -> ST.head t `shouldBe` c- describe "textWithA" $- it "contains the given character" $- forAll arbitrary $ \c ->- forAll (textWithA c) $ \t -> ST.unpack t `shouldSatisfy` elem c- describe "textWithoutAny" $- it "never contains the given char" $- forAll arbitrary $ \c ->- forAll (textWithoutAny c) $ \t ->- ST.unpack t `shouldNotSatisfy` elem c- describe "textWithoutAnyOf" $- it "never contains any of the given chars" $- forAll arbitrary $ \cs ->- forAll (textWithoutAnyOf cs) $ \text ->- ST.unpack text `shouldNotSatisfy` (\t -> any (`elem` t) cs)- describe "Lazy Text" $ do- genValidSpec @LT.Text- describe "genValid" $ do- it "is always empty when resized to 0" $- forAll (resize 0 genValid) (`shouldSatisfy` LT.null)- it "generates valid text" $- forAll (genValid) $ \t ->- unless (isValid t) $- expectationFailure $ showLazyTextDebug t+ describe "Strict Text" $ do+ genValidSpec @ST.Text+ describe "genValid" $ do+ it "is always empty when resized to 0" $+ forAll (resize 0 genValid) (`shouldSatisfy` ST.null)+ it "generates valid text" $+ forAll (genValid) $ \t ->+ unless (isValid t) $ expectationFailure $ showTextDebug t+ describe "textStartingWith" $ do+ it "is never empty" $+ forAll arbitrary $ \c ->+ forAll (textStartingWith c) $ \t ->+ t `shouldNotSatisfy` ST.null+ it "contains exactly the first character if resized to 0" $+ forAll arbitrary $ \c ->+ forAll (resize 0 $ textStartingWith c) $ \t ->+ t `shouldBe` ST.pack [c]+ it "contains exactly the first character if resized to 1" $+ forAll arbitrary $ \c ->+ forAll (resize 0 $ textStartingWith c) $ \t ->+ t `shouldBe` ST.pack [c]+ it "always starts with the given char" $+ forAll arbitrary $ \c ->+ forAll (textStartingWith c) $ \t -> ST.head t `shouldBe` c+ describe "textWithA" $+ it "contains the given character" $+ forAll arbitrary $ \c ->+ forAll (textWithA c) $ \t -> ST.unpack t `shouldSatisfy` elem c+ describe "textWithoutAny" $+ it "never contains the given char" $+ forAll arbitrary $ \c ->+ forAll (textWithoutAny c) $ \t ->+ ST.unpack t `shouldNotSatisfy` elem c+ describe "textWithoutAnyOf" $+ it "never contains any of the given chars" $+ forAll arbitrary $ \cs ->+ forAll (textWithoutAnyOf cs) $ \text ->+ ST.unpack text `shouldNotSatisfy` (\t -> any (`elem` t) cs)+ describe "Lazy Text" $ do+ genValidSpec @LT.Text+ describe "genValid" $ do+ it "is always empty when resized to 0" $+ forAll (resize 0 genValid) (`shouldSatisfy` LT.null)+ it "generates valid text" $+ forAll (genValid) $ \t ->+ unless (isValid t) $+ expectationFailure $ showLazyTextDebug t