packages feed

genvalidity-text 0.1.0.1 → 0.2.0.0

raw patch · 2 files changed

+47/−39 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.GenValidity.Text: instance Data.GenValidity.GenValidity Data.Text.Internal.Text
+ Data.GenValidity.Text: instance Data.GenValidity.GenInvalid Data.Text.Internal.Text
+ Data.GenValidity.Text: instance Data.GenValidity.GenUnchecked Data.Text.Internal.Text
+ Data.GenValidity.Text: instance Data.GenValidity.GenValid Data.Text.Internal.Text
- Data.GenValidity.Text: textWithoutAnyOf :: String -> Gen Text
+ Data.GenValidity.Text: textWithoutAnyOf :: [Char] -> Gen Text

Files

genvalidity-text.cabal view
@@ -1,5 +1,5 @@ name:                genvalidity-text-version:             0.1.0.1+version:             0.2.0.0 synopsis:            GenValidity support for Text description:         Please see README.md homepage:            https://github.com/NorfairKing/validity#readme
src/Data/GenValidity/Text.hs view
@@ -1,63 +1,71 @@ module Data.GenValidity.Text where -import           Data.GenValidity-import           Data.Validity.Text ()--import           Test.QuickCheck+import Data.GenValidity+import Data.Validity.Text () -import           Control.Monad+import Test.QuickCheck -import qualified Data.Text.Array    as A-import           Data.Text.Internal (Text(..))-import qualified Data.Text          as T+import Control.Monad +import qualified Data.Text as T+import qualified Data.Text.Array as A+import Data.Text.Internal (Text(..)) -instance GenValidity Text where+instance GenUnchecked Text where     genUnchecked = Text <$> uncheckedArray <*> arbitrary <*> arbitrary       where-        uncheckedArray = sized $ \n -> do+        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++instance GenValid Text where+    genValid =+        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+            chars <- resize size $ genListOf arbitrary+            return $ T.pack chars -    genValid = sized $ \n -> do-        size <- upTo n-        chars <- resize size $ genListOf arbitrary-        return $ T.pack chars+instance GenInvalid Text +-- | 'textStartingWith c' generates a 'Text' value that starts with 'c'. textStartingWith :: Char -> Gen Text-textStartingWith c = sized $ \n ->-    case n of-        0 -> pure $ T.singleton c-        1 -> pure $ T.singleton c-        _ -> do-            rest <- resize (n - 1) genValid-            return $ T.cons c rest+textStartingWith c =+    sized $ \n ->+        case n of+            0 -> pure $ T.singleton c+            1 -> pure $ T.singleton c+            _ -> do+                rest <- resize (n - 1) genValid+                return $ T.cons c rest +-- | 'textStartingWith g' generates a 'Text' value that contains a substring generated by 'g'. textWith :: Gen Text -> Gen Text-textWith gen = sized $ \n -> do-    (b, m, a) <- genSplit3 n-    before <- resize b genValid-    middle <- resize m gen-    after  <- resize a genValid-    return $ T.concat [before, middle, after]+textWith gen =+    sized $ \n -> do+        (b, m, a) <- genSplit3 n+        before <- resize b genValid+        middle <- resize m gen+        after <- resize a genValid+        return $ T.concat [before, middle, after] +-- | 'textStartingWith c' generates a 'Text' value that contains a 'c'. textWithA :: Char -> Gen Text textWithA c = textWith $ T.singleton <$> pure c +-- | 'textWithoutAny c' generates a 'Text' value that does not contain any 'c'. textWithoutAny :: Char -> Gen Text textWithoutAny c = textWithoutAnyOf [c] -textWithoutAnyOf :: String -> Gen Text+-- | 'textWithoutAnyOf c' generates a 'Text' value that does not contain any character in 'ls'.+textWithoutAnyOf :: [Char] -> Gen Text textWithoutAnyOf cs = T.pack <$> genListOf (arbitrary `suchThat` (`notElem` cs)) +-- | 'textAllCaps' generates a 'Text' value with only upper-case characters. textAllCaps :: Gen Text textAllCaps = T.toUpper <$> genValid-----