packages feed

genvalidity-text (empty) → 0.1.0.0

raw patch · 6 files changed

+181/−0 lines, 6 filesdep +QuickCheckdep +basedep +genvaliditysetup-changed

Dependencies added: QuickCheck, base, genvalidity, genvalidity-text, hspec, text, validity

Files

+ LICENSE view
@@ -0,0 +1,21 @@+The MIT License (MIT)++Copyright (c) 2016 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+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ genvalidity-text.cabal view
@@ -0,0 +1,53 @@+name:                genvalidity-text+version:             0.1.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++library+  hs-source-dirs:      src+  exposed-modules:     Data.GenValidity.Text+  build-depends:       base       < 5+                     , validity       +                     , genvalidity+                     , text       +                     , QuickCheck      +  default-language:    Haskell2010++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
+ src/Data/GenValidity/Text.hs view
@@ -0,0 +1,49 @@+module Data.GenValidity.Text where++import           Data.GenValidity++import           Test.QuickCheck++import           Data.Text        (Text)+import qualified Data.Text        as T+++genUncheckedText :: Gen Text+genUncheckedText = sized $ \n -> do+    size <- upTo n+    chars <- resize size $ genListOf arbitrary+    return $ T.pack chars++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) genUncheckedText+            return $ T.cons c rest++textWith :: Gen Text -> Gen Text+textWith gen = sized $ \n -> do+    (b, m, a) <- genSplit3 n+    before <- resize b genUncheckedText+    middle <- resize m gen+    after  <- resize a genUncheckedText+    return $ T.concat [before, middle, after]++textWithA :: Char -> Gen Text+textWithA c = textWith $ T.singleton <$> pure c++textWithoutAny :: Char -> Gen Text+textWithoutAny c = textWithoutAnyOf [c]++textWithoutAnyOf :: [Char] -> Gen Text+textWithoutAnyOf cs = T.pack <$> genListOf (arbitrary `suchThat` (`notElem` cs))++textAllCaps :: Gen Text+textAllCaps = T.toUpper <$> genUncheckedText+++++
+ test/Data/GenValidity/TextSpec.hs view
@@ -0,0 +1,55 @@+module Data.GenValidity.TextSpec (spec) where++import           Test.Hspec+import           Test.QuickCheck++import           Data.GenValidity      ()+import           Data.GenValidity.Text++import qualified Data.Text             as T++spec :: Spec+spec = do+    describe "genUncheckedText" $ do+        it "is always empty when resized to 0" $ do+            forAll (resize 0 genUncheckedText) (`shouldSatisfy` T.null)++    describe "textStartingWith" $ do+        it "is never empty" $ do+            forAll arbitrary $ \c ->+                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++    describe "textWithA" $ do+        it "contains the given character" $ do+            forAll arbitrary $ \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)+
+ test/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}