packages feed

quickcheck-string-random (empty) → 0.1.0.0

raw patch · 5 files changed

+145/−0 lines, 5 filesdep +QuickCheckdep +basedep +quickcheck-string-randomsetup-changed

Dependencies added: QuickCheck, base, quickcheck-string-random, string-random, tasty, tasty-quickcheck, text

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright hiratara (c) 2016++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither hiratara nor Masahiro Honma+      may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ quickcheck-string-random.cabal view
@@ -0,0 +1,42 @@+name:                quickcheck-string-random+version:             0.1.0.0+synopsis:            Helper to build generators with Text.StringRandom+description:         Define a generator of Text that matches regular+                     expressions. This package is useful for creating Arbitrary+                     instances of Text type restricted by newtype.+homepage:            https://github.com/hiratara/hs-string-random#readme+license:             BSD3+license-file:        LICENSE+author:              Masahiro Honma+maintainer:          hiratara@cpan.org+copyright:           Copyright (C) 2016- hiratara+category:            Test+build-type:          Simple+cabal-version:       >=1.10+tested-with:         GHC ==8.0.1++library+  hs-source-dirs:      src+  exposed-modules:     Test.QuickCheck.StringRandom+  build-depends:       base >= 4.9 && < 5+                     , QuickCheck >=2.8.2 && <2.9+                     , string-random ==0.1.*+                     , text >=1.2.2.1 && <1.3+  default-language:    Haskell2010++test-suite quickcheck-string-random-test+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             quickcheck-string-random-test.hs+  build-depends:       base+                     , QuickCheck+                     , quickcheck-string-random+                     , tasty+                     , tasty-quickcheck+                     , text+  ghc-options:         -threaded -rtsopts -with-rtsopts=-N+  default-language:    Haskell2010++source-repository head+  type:     git+  location: https://github.com/hiratara/hs-string-random
+ src/Test/QuickCheck/StringRandom.hs view
@@ -0,0 +1,45 @@+{-|+Module      : Text.QuickCheck.StringRandom+Description : A generator of text which matches regexp+Copyright   : Copyright (C) 2016- hiratara+License     : GPL-3+Maintainer  : hiratara@cpan.org+Stability   : experimental++A text generator that generates a string that matches a regular expression.++@+    {-# LANGUAGE OverloadedStrings #-}+    import qualified Test.QuickCheck as QC+    import Test.QuickCheck.StringRandom (matchRegexp)++    prop_generateDigit :: QC.Property+    prop_generateDigit = QC.forAll (matchRegexp "\\d") $ \digit -> ...++    -- or++    newtype Upper = Upper Text.Text deriving (Eq, Show)++    instance QC.Arbitrary Upper where+      arbitrary = Upper <$> matchRegexp "[A-Z]"++    prop_generateUpper :: Upper -> Bool+    prop_generateUpper (Upper upper) = ...+@++The shrink function has not been defined yet.+-}++module Test.QuickCheck.StringRandom+  ( matchRegexp+  ) where++import qualified Data.Text as Text+import qualified Test.QuickCheck.Gen as QC+import qualified Test.QuickCheck.Random as QC+import qualified Text.StringRandom as StringRandom++-- | The 'matchRegexp pat' defines a generator that produces a text that+-- | matches a regular expression 'pat'+matchRegexp :: Text.Text -> QC.Gen Text.Text+matchRegexp txt = QC.MkGen $ \(QC.QCGen g) _ -> StringRandom.stringRandom g txt
+ test/quickcheck-string-random-test.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE Strict #-}+import qualified Data.Char as Char+import qualified Data.Text as Text+import qualified Test.QuickCheck as QC+import Test.QuickCheck.StringRandom (matchRegexp)+import qualified Test.Tasty as Tasty+import qualified Test.Tasty.QuickCheck as TastyQC++main :: IO ()+main = Tasty.defaultMain $ Tasty.testGroup "by quickcheck"+  [ TastyQC.testProperty "generate digit" prop_generateDigit+  , TastyQC.testProperty "generate upper case" prop_generateUpper+  ]++prop_generateDigit :: QC.Property+prop_generateDigit = QC.forAll (matchRegexp "\\d") $ \digit ->+  Text.length digit == 1 && Char.isDigit (Text.head digit)++newtype Upper = Upper Text.Text deriving (Eq, Show)++instance QC.Arbitrary Upper where+  arbitrary = Upper <$> matchRegexp "[A-Z]"++prop_generateUpper :: Upper -> Bool+prop_generateUpper (Upper up) = Text.length up == 1 && Char.isUpper (Text.head up)