packages feed

genvalidity-text 0.5.1.0 → 0.6.0.0

raw patch · 3 files changed

+34/−60 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.GenValidity.Text: instance Data.GenValidity.GenInvalid Data.Text.Internal.Lazy.Text
- Data.GenValidity.Text: instance Data.GenValidity.GenInvalid Data.Text.Internal.Text
- Data.GenValidity.Text: instance Data.GenValidity.GenUnchecked Data.Text.Internal.Lazy.Text
- Data.GenValidity.Text: instance Data.GenValidity.GenUnchecked Data.Text.Internal.Text
+ 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

Files

genvalidity-text.cabal view
@@ -1,13 +1,13 @@-cabal-version: >= 1.10+cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.29.6.+-- This file has been generated from package.yaml by hpack version 0.31.1. -- -- see: https://github.com/sol/hpack ----- hash: 0b74a2109a1d1a01ef347a56e9eb34ceafe87cdd703a165cc25c976325210d43+-- hash: ea9d370a4d6e4e02b556f3e585c751532a53c5c09c0268d232ac5a3e7d861fea  name:           genvalidity-text-version:        0.5.1.0+version:        0.6.0.0 synopsis:       GenValidity support for Text description:    Please see README.md category:       Testing@@ -16,7 +16,7 @@ author:         Tom Sydney Kerckhove maintainer:     syd.kerckhove@gmail.com,                 nick.van.den.broeck666@gmail.com-copyright:      Copyright: (c) 2016-2018 Tom Sydney Kerckhove+copyright:      Copyright: (c) 2016-2019 Tom Sydney Kerckhove license:        MIT license-file:   LICENSE build-type:     Simple
src/Data/GenValidity/Text.hs view
@@ -1,63 +1,39 @@ {-# 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 Data.Validity.Text ()  import Test.QuickCheck--import Control.Monad #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.Array as A-import qualified Data.Text.Internal as ST import qualified Data.Text.Internal.Lazy as LT--instance GenUnchecked ST.Text where-    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 $ ST.Text arr off len-    shrinkUnchecked _ = []-+import qualified Data.Text.Lazy as LT+#if MIN_VERSION_base(4,9,0)+import GHC.TypeLits+#endif instance GenValid ST.Text where     genValid =         sized $ \n -> do-            size <- upTo n-            chars <- resize size $ genListOf arbitrary+            chars <- resize n $ genListOf arbitrary             return $ ST.pack chars     shrinkValid = fmap ST.pack . shrinkValid . ST.unpack--instance GenInvalid ST.Text--instance GenUnchecked LT.Text where-    genUnchecked =-        sized $ \n ->-            case n of-                0 -> pure LT.Empty-                _ -> do-                    (a, b) <- genSplit n-                    st <- resize a genUnchecked-                    lt <- resize b genUnchecked-                    pure $ LT.Chunk st lt-    shrinkUnchecked LT.Empty = []-    shrinkUnchecked (LT.Chunk st lt) =-        [LT.Chunk st' lt' | (st', lt') <- shrinkUnchecked (st, lt)]-+#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 instance GenValid LT.Text where     genValid =         sized $ \n ->@@ -68,9 +44,14 @@                     st <- ST.cons <$> genValid <*> resize a genValid                     lt <- resize b genValid                     pure $ LT.Chunk st lt--instance GenInvalid LT.Text-+    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 =
test/Data/GenValidity/TextSpec.hs view
@@ -45,23 +45,20 @@         [ "A chuck with this strict text:"         , showTextDebug st         , "and this rest of the lazy text:"-        , showLazyTextDebug lt, ""+        , showLazyTextDebug lt+        , ""         ]  spec :: Spec spec = do     describe "Strict Text" $ do-        genValiditySpec @ST.Text+        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 "genUnchecked `suchThat` isValid" $-            it "generates valid text" $-            forAll ((genUnchecked :: Gen ST.Text) `suchThat` isValid) $ \t ->-                unless (isValid t) $ expectationFailure $ showTextDebug t         describe "textStartingWith" $ do             it "is never empty" $                 forAll arbitrary $ \c ->@@ -93,7 +90,7 @@                 forAll (textWithoutAnyOf cs) $ \text ->                     ST.unpack text `shouldNotSatisfy` (\t -> any (`elem` t) cs)     describe "Lazy Text" $ do-        genValiditySpec @LT.Text+        genValidSpec @LT.Text         describe "genValid" $ do             it "is always empty when resized to 0" $                 forAll (resize 0 genValid) (`shouldSatisfy` LT.null)@@ -101,7 +98,3 @@                 forAll (genValid) $ \t ->                     unless (isValid t) $                     expectationFailure $ showLazyTextDebug t-        describe "genUnchecked `suchThat` isValid" $-            it "generates valid text" $-            forAll ((genUnchecked :: Gen LT.Text) `suchThat` isValid) $ \t ->-                unless (isValid t) $ expectationFailure $ showLazyTextDebug t