Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. module Combinators where
  2.  
  3. import Control.Monad (forM_)
  4. import Test.Hspec
  5. import Test.QuickCheck
  6. import Text.RE.PCRE
  7.  
  8. alphabetical :: Gen Char
  9. alphabetical = elements $ ['A'..'Z'] ++ ['a'..'z']
  10.  
  11. lower :: Gen Char
  12. lower = elements ['a'..'z']
  13.  
  14. mkSpecificTests :: [String] -> [String] -> RE -> Spec
  15. mkSpecificTests positives negatives myRegex =
  16. describe "specific tests" $ do
  17. describe "positives" $ do
  18. forM_ positives $ \str -> do
  19. it ("matches " ++ str) $
  20. (str ?=~ myRegex) `shouldSatisfy` matched
  21. describe "negatives" $ do
  22. forM_ negatives $ \str -> do
  23. it ("fails " ++ str) $
  24. (str ?=~ myRegex) `shouldNotSatisfy` matched
  25.  
  26. repeatedWord :: Gen String
  27. repeatedWord = do
  28. w <- word
  29. n <- arbitrary `suchThat` (>= 1) :: Gen Int
  30. return $ foldl (\accumulator _ -> accumulator ++ " " ++ w) w [1 .. n]
  31.  
  32. word :: Gen String
  33. word = listOf1 alphabetical
  34.  
  35. -- wordChar :: Gen Char
  36. -- wordChar = elements $ ['A'..'Z'] ++ ['a'..'z'] ++ ['0'..'9'] ++ "_"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement