1 {-# LANGUAGE CPP, ScopedTypeVariables, BangPatterns #-}
    2 --
    3 -- Must have rules off, otherwise the rewrite rules will replace the rhs
    4 -- with the lhs, and we only end up testing lhs == lhs
    5 --
    6 
    7 --
    8 -- -fhpc interferes with rewrite rules firing.
    9 --
   10 
   11 import Foreign.Storable
   12 import Foreign.ForeignPtr
   13 import Foreign.Marshal.Alloc
   14 import Foreign.Marshal.Array
   15 import GHC.Ptr
   16 import Test.QuickCheck
   17 import Control.Applicative
   18 import Control.Monad
   19 import Control.Concurrent
   20 import Control.Exception
   21 import System.Directory
   22 
   23 import Data.List
   24 import Data.Char
   25 import Data.Word
   26 import Data.Maybe
   27 import Data.Int (Int64)
   28 import Data.Monoid
   29 
   30 import Text.Printf
   31 import Data.String
   32 
   33 import System.Environment
   34 import System.IO
   35 import System.IO.Unsafe
   36 
   37 import Data.ByteString.Lazy (ByteString(..), pack , unpack)
   38 import qualified Data.ByteString.Lazy as L
   39 import Data.ByteString.Lazy.Internal (ByteString(..))
   40 
   41 import qualified Data.ByteString            as P
   42 import qualified Data.ByteString.Internal   as P
   43 import qualified Data.ByteString.Unsafe     as P
   44 import qualified Data.ByteString.Char8      as C
   45 import qualified Data.ByteString.Short      as Short
   46 
   47 import qualified Data.ByteString.Lazy.Char8 as LC
   48 import qualified Data.ByteString.Lazy.Char8 as D
   49 
   50 import qualified Data.ByteString.Lazy.Internal as L
   51 import Prelude hiding (abs)
   52 
   53 import Rules
   54 import QuickCheckUtils
   55 #if defined(HAVE_TEST_FRAMEWORK)
   56 import Test.Framework
   57 import Test.Framework.Providers.QuickCheck2
   58 #else
   59 import TestFramework
   60 #endif
   61 
   62 toInt64 :: Int -> Int64
   63 toInt64 = fromIntegral
   64 
   65 --
   66 -- ByteString.Lazy.Char8 <=> ByteString.Char8
   67 --
   68 
   69 prop_concatCC       = D.concat                `eq1`  C.concat
   70 prop_nullCC         = D.null                  `eq1`  C.null
   71 prop_reverseCC      = D.reverse               `eq1`  C.reverse
   72 prop_transposeCC    = D.transpose             `eq1`  C.transpose
   73 prop_groupCC        = D.group                 `eq1`  C.group
   74 prop_groupByCC      = D.groupBy               `eq2`  C.groupBy
   75 prop_initsCC        = D.inits                 `eq1`  C.inits
   76 prop_tailsCC        = D.tails                 `eq1`  C.tails
   77 prop_allCC          = D.all                   `eq2`  C.all
   78 prop_anyCC          = D.any                   `eq2`  C.any
   79 prop_appendCC       = D.append                `eq2`  C.append
   80 prop_breakCC        = D.break                 `eq2`  C.break
   81 prop_concatMapCC    = forAll (sized $ \n -> resize (min 50 n) arbitrary) $
   82                       D.concatMap             `eq2`  C.concatMap
   83 prop_consCC         = D.cons                  `eq2`  C.cons
   84 prop_consCC'        = D.cons'                 `eq2`  C.cons
   85 prop_unconsCC       = D.uncons                `eq1`  C.uncons
   86 prop_unsnocCC       = D.unsnoc                `eq1`  C.unsnoc
   87 prop_countCC        = D.count                 `eq2`  ((toInt64 .) . C.count)
   88 prop_dropCC         = (D.drop . toInt64)      `eq2`  C.drop
   89 prop_dropWhileCC    = D.dropWhile             `eq2`  C.dropWhile
   90 prop_filterCC       = D.filter                `eq2`  C.filter
   91 prop_findCC         = D.find                  `eq2`  C.find
   92 prop_findIndexCC    = D.findIndex             `eq2`  ((fmap toInt64 .) . C.findIndex)
   93 prop_findIndicesCC  = D.findIndices           `eq2`  ((fmap toInt64 .) . C.findIndices)
   94 prop_isPrefixOfCC   = D.isPrefixOf            `eq2`  C.isPrefixOf
   95 prop_stripPrefixCC  = D.stripPrefix           `eq2`  C.stripPrefix
   96 prop_isSuffixOfCC   = D.isSuffixOf            `eq2`  C.isSuffixOf
   97 prop_stripSuffixCC  = D.stripSuffix           `eq2`  C.stripSuffix
   98 prop_mapCC          = D.map                   `eq2`  C.map
   99 prop_replicateCC    = forAll arbitrarySizedIntegral $
  100                       (D.replicate . toInt64) `eq2`  C.replicate
  101 prop_snocCC         = D.snoc                  `eq2`  C.snoc
  102 prop_spanCC         = D.span                  `eq2`  C.span
  103 prop_splitCC        = D.split                 `eq2`  C.split
  104 prop_splitAtCC      = (D.splitAt . toInt64)   `eq2`  C.splitAt
  105 prop_takeCC         = (D.take    . toInt64)   `eq2`  C.take
  106 prop_takeWhileCC    = D.takeWhile             `eq2`  C.takeWhile
  107 prop_elemCC         = D.elem                  `eq2`  C.elem
  108 prop_notElemCC      = D.notElem               `eq2`  C.notElem
  109 prop_elemIndexCC    = D.elemIndex             `eq2`  ((fmap toInt64 .) . C.elemIndex)
  110 prop_elemIndicesCC  = D.elemIndices           `eq2`  ((fmap toInt64 .) . C.elemIndices)
  111 prop_lengthCC       = D.length                `eq1`  (toInt64 . C.length)
  112 
  113 prop_headCC         = D.head        `eqnotnull1` C.head
  114 prop_initCC         = D.init        `eqnotnull1` C.init
  115 prop_lastCC         = D.last        `eqnotnull1` C.last
  116 prop_maximumCC      = D.maximum     `eqnotnull1` C.maximum
  117 prop_minimumCC      = D.minimum     `eqnotnull1` C.minimum
  118 prop_tailCC         = D.tail        `eqnotnull1` C.tail
  119 prop_foldl1CC       = D.foldl1      `eqnotnull2` C.foldl1
  120 prop_foldl1CC'      = D.foldl1'     `eqnotnull2` C.foldl1'
  121 prop_foldr1CC       = D.foldr1      `eqnotnull2` C.foldr1
  122 prop_foldr1CC'      = D.foldr1      `eqnotnull2` C.foldr1'
  123 prop_scanlCC        = D.scanl       `eqnotnull3` C.scanl
  124 
  125 prop_intersperseCC = D.intersperse  `eq2` C.intersperse
  126 
  127 prop_foldlCC     = eq3
  128     (D.foldl     :: (X -> Char -> X) -> X -> B -> X)
  129     (C.foldl     :: (X -> Char -> X) -> X -> P -> X)
  130 prop_foldlCC'    = eq3
  131     (D.foldl'    :: (X -> Char -> X) -> X -> B -> X)
  132     (C.foldl'    :: (X -> Char -> X) -> X -> P -> X)
  133 prop_foldrCC     = eq3
  134     (D.foldr     :: (Char -> X -> X) -> X -> B -> X)
  135     (C.foldr     :: (Char -> X -> X) -> X -> P -> X)
  136 prop_foldrCC'    = eq3
  137     (D.foldr     :: (Char -> X -> X) -> X -> B -> X)
  138     (C.foldr'    :: (Char -> X -> X) -> X -> P -> X)
  139 prop_mapAccumLCC = eq3
  140     (D.mapAccumL :: (X -> Char -> (X,Char)) -> X -> B -> (X, B))
  141     (C.mapAccumL :: (X -> Char -> (X,Char)) -> X -> P -> (X, P))
  142 
  143 --prop_mapIndexedCC = D.mapIndexed `eq2` C.mapIndexed
  144 --prop_mapIndexedPL = L.mapIndexed `eq2` P.mapIndexed
  145 
  146 --prop_mapAccumL_mapIndexedBP =
  147 --        P.mapIndexed `eq2`
  148 --        (\k p -> snd $ P.mapAccumL (\i w -> (i+1, k i w)) (0::Int) p)
  149 
  150 --
  151 -- ByteString.Lazy <=> ByteString
  152 --
  153 
  154 prop_concatBP       = forAll (sized $ \n -> resize (n `div` 2) arbitrary) $
  155                       L.concat               `eq1`  P.concat
  156 prop_nullBP         = L.null                 `eq1`  P.null
  157 prop_reverseBP      = L.reverse              `eq1`  P.reverse
  158 
  159 prop_transposeBP    = L.transpose            `eq1`  P.transpose
  160 prop_groupBP        = L.group                `eq1`  P.group
  161 prop_groupByBP      = L.groupBy              `eq2`  P.groupBy
  162 prop_initsBP        = L.inits                `eq1`  P.inits
  163 prop_tailsBP        = L.tails                `eq1`  P.tails
  164 prop_allBP          = L.all                  `eq2`  P.all
  165 prop_anyBP          = L.any                  `eq2`  P.any
  166 prop_appendBP       = L.append               `eq2`  P.append
  167 prop_breakBP        = L.break                `eq2`  P.break
  168 prop_concatMapBP    = forAll (sized $ \n -> resize (n `div` 4) arbitrary) $
  169                       L.concatMap            `eq2`  P.concatMap
  170 prop_consBP         = L.cons                 `eq2`  P.cons
  171 prop_consBP'        = L.cons'                `eq2`  P.cons
  172 prop_unconsBP       = L.uncons               `eq1`  P.uncons
  173 prop_unsnocBP       = L.unsnoc               `eq1`  P.unsnoc
  174 prop_countBP        = L.count                `eq2`  ((toInt64 .) . P.count)
  175 prop_dropBP         = (L.drop. toInt64)      `eq2`  P.drop
  176 prop_dropWhileBP    = L.dropWhile            `eq2`  P.dropWhile
  177 prop_filterBP       = L.filter               `eq2`  P.filter
  178 prop_findBP         = L.find                 `eq2`  P.find
  179 prop_findIndexBP    = L.findIndex            `eq2`  ((fmap toInt64 .) . P.findIndex)
  180 prop_findIndicesBP  = L.findIndices          `eq2`  ((fmap toInt64 .) . P.findIndices)
  181 prop_isPrefixOfBP   = L.isPrefixOf           `eq2`  P.isPrefixOf
  182 prop_stripPrefixBP  = L.stripPrefix          `eq2`  P.stripPrefix
  183 prop_isSuffixOfBP   = L.isSuffixOf           `eq2`  P.isSuffixOf
  184 prop_stripSuffixBP  = L.stripSuffix          `eq2`  P.stripSuffix
  185 prop_mapBP          = L.map                  `eq2`  P.map
  186 prop_replicateBP    = forAll arbitrarySizedIntegral $
  187                       (L.replicate. toInt64) `eq2`  P.replicate
  188 prop_snocBP         = L.snoc                 `eq2`  P.snoc
  189 prop_spanBP         = L.span                 `eq2`  P.span
  190 prop_splitBP        = L.split                `eq2`  P.split
  191 prop_splitAtBP      = (L.splitAt. toInt64)   `eq2`  P.splitAt
  192 prop_takeBP         = (L.take   . toInt64)   `eq2`  P.take
  193 prop_takeWhileBP    = L.takeWhile            `eq2`  P.takeWhile
  194 prop_elemBP         = L.elem                 `eq2`  P.elem
  195 prop_notElemBP      = L.notElem              `eq2`  P.notElem
  196 prop_elemIndexBP    = L.elemIndex            `eq2`  ((fmap toInt64 .) . P.elemIndex)
  197 prop_elemIndicesBP  = L.elemIndices          `eq2`  ((fmap toInt64 .) . P.elemIndices)
  198 prop_intersperseBP  = L.intersperse          `eq2`  P.intersperse
  199 prop_lengthBP       = L.length               `eq1`  (toInt64 . P.length)
  200 prop_readIntBP      = D.readInt              `eq1`  C.readInt
  201 prop_linesBP        = D.lines                `eq1`  C.lines
  202 
  203 -- double check:
  204 -- Currently there's a bug in the lazy bytestring version of lines, this
  205 -- catches it:
  206 prop_linesNLBP      = eq1 D.lines C.lines x
  207     where x = D.pack "one\ntwo\n\n\nfive\n\nseven\n"
  208 
  209 prop_headBP         = L.head        `eqnotnull1` P.head
  210 prop_initBP         = L.init        `eqnotnull1` P.init
  211 prop_lastBP         = L.last        `eqnotnull1` P.last
  212 prop_maximumBP      = L.maximum     `eqnotnull1` P.maximum
  213 prop_minimumBP      = L.minimum     `eqnotnull1` P.minimum
  214 prop_tailBP         = L.tail        `eqnotnull1` P.tail
  215 prop_foldl1BP       = L.foldl1      `eqnotnull2` P.foldl1
  216 prop_foldl1BP'      = L.foldl1'     `eqnotnull2` P.foldl1'
  217 prop_foldr1BP       = L.foldr1      `eqnotnull2` P.foldr1
  218 prop_foldr1BP'      = L.foldr1      `eqnotnull2` P.foldr1'
  219 prop_scanlBP        = L.scanl       `eqnotnull3` P.scanl
  220 
  221 
  222 prop_eqBP        = eq2
  223     ((==) :: B -> B -> Bool)
  224     ((==) :: P -> P -> Bool)
  225 prop_compareBP   = eq2
  226     ((compare) :: B -> B -> Ordering)
  227     ((compare) :: P -> P -> Ordering)
  228 prop_foldlBP     = eq3
  229     (L.foldl     :: (X -> W -> X) -> X -> B -> X)
  230     (P.foldl     :: (X -> W -> X) -> X -> P -> X)
  231 prop_foldlBP'    = eq3
  232     (L.foldl'    :: (X -> W -> X) -> X -> B -> X)
  233     (P.foldl'    :: (X -> W -> X) -> X -> P -> X)
  234 prop_foldrBP     = eq3
  235     (L.foldr     :: (W -> X -> X) -> X -> B -> X)
  236     (P.foldr     :: (W -> X -> X) -> X -> P -> X)
  237 prop_foldrBP'    = eq3
  238     (L.foldr     :: (W -> X -> X) -> X -> B -> X)
  239     (P.foldr'    :: (W -> X -> X) -> X -> P -> X)
  240 prop_mapAccumLBP = eq3
  241     (L.mapAccumL :: (X -> W -> (X,W)) -> X -> B -> (X, B))
  242     (P.mapAccumL :: (X -> W -> (X,W)) -> X -> P -> (X, P))
  243 
  244 prop_unfoldrBP   =
  245   forAll arbitrarySizedIntegral $
  246   eq3
  247     ((\n f a -> L.take (fromIntegral n) $
  248         L.unfoldr    f a) :: Int -> (X -> Maybe (W,X)) -> X -> B)
  249     ((\n f a ->                     fst $
  250         P.unfoldrN n f a) :: Int -> (X -> Maybe (W,X)) -> X -> P)
  251 
  252 prop_unfoldr2BP   =
  253   forAll arbitrarySizedIntegral $ \n ->
  254   forAll arbitrarySizedIntegral $ \a ->
  255   eq2
  256     ((\n a -> P.take (n*100) $
  257         P.unfoldr    (\x -> if x <= (n*100) then Just (fromIntegral x, x + 1) else Nothing) a)
  258                 :: Int -> Int -> P)
  259     ((\n a ->                     fst $
  260         P.unfoldrN (n*100) (\x -> if x <= (n*100) then Just (fromIntegral x, x + 1) else Nothing) a)
  261                 :: Int -> Int -> P)
  262     n a
  263 
  264 prop_unfoldr2CP   =
  265   forAll arbitrarySizedIntegral $ \n ->
  266   forAll arbitrarySizedIntegral $ \a ->
  267   eq2
  268     ((\n a -> C.take (n*100) $
  269         C.unfoldr    (\x -> if x <= (n*100) then Just (chr (x `mod` 256), x + 1) else Nothing) a)
  270                 :: Int -> Int -> P)
  271     ((\n a ->                     fst $
  272         C.unfoldrN (n*100) (\x -> if x <= (n*100) then Just (chr (x `mod` 256), x + 1) else Nothing) a)
  273                 :: Int -> Int -> P)
  274     n a
  275 
  276 
  277 prop_unfoldrLC   =
  278   forAll arbitrarySizedIntegral $
  279   eq3
  280     ((\n f a -> LC.take (fromIntegral n) $
  281         LC.unfoldr    f a) :: Int -> (X -> Maybe (Char,X)) -> X -> B)
  282     ((\n f a ->                     fst $
  283         C.unfoldrN n f a) :: Int -> (X -> Maybe (Char,X)) -> X -> P)
  284 
  285 prop_cycleLC  a   =
  286   not (LC.null a) ==>
  287   forAll arbitrarySizedIntegral $
  288   eq1
  289     ((\n   -> LC.take (fromIntegral n) $
  290               LC.cycle a
  291      ) :: Int -> B)
  292 
  293     ((\n   -> LC.take (fromIntegral (n::Int)) . LC.concat $
  294               unfoldr (\x ->  Just (x,x) ) a
  295      ) :: Int -> B)
  296 
  297 
  298 prop_iterateLC =
  299   forAll arbitrarySizedIntegral $
  300   eq3
  301     ((\n f a -> LC.take (fromIntegral n) $
  302         LC.iterate  f a) :: Int -> (Char -> Char) -> Char -> B)
  303     ((\n f a -> fst $
  304         C.unfoldrN n (\a -> Just (f a, f a)) a) :: Int -> (Char -> Char) -> Char -> P)
  305 
  306 prop_iterateLC_2   =
  307   forAll arbitrarySizedIntegral $
  308   eq3
  309     ((\n f a -> LC.take (fromIntegral n) $
  310         LC.iterate  f a) :: Int -> (Char -> Char) -> Char -> B)
  311     ((\n f a -> LC.take (fromIntegral n) $
  312         LC.unfoldr (\a -> Just (f a, f a)) a) :: Int -> (Char -> Char) -> Char -> B)
  313 
  314 prop_iterateL   =
  315   forAll arbitrarySizedIntegral $
  316   eq3
  317     ((\n f a -> L.take (fromIntegral n) $
  318         L.iterate  f a) :: Int -> (W -> W) -> W -> B)
  319     ((\n f a -> fst $
  320         P.unfoldrN n (\a -> Just (f a, f a)) a) :: Int -> (W -> W) -> W -> P)
  321 
  322 prop_repeatLC   =
  323   forAll arbitrarySizedIntegral $
  324   eq2
  325     ((\n a -> LC.take (fromIntegral n) $
  326         LC.repeat a) :: Int -> Char -> B)
  327     ((\n a -> fst $
  328         C.unfoldrN n (\a -> Just (a, a)) a) :: Int -> Char -> P)
  329 
  330 prop_repeatL   =
  331   forAll arbitrarySizedIntegral $
  332   eq2
  333     ((\n a -> L.take (fromIntegral n) $
  334         L.repeat a) :: Int -> W -> B)
  335     ((\n a -> fst $
  336         P.unfoldrN n (\a -> Just (a, a)) a) :: Int -> W -> P)
  337 
  338 --
  339 -- properties comparing ByteString.Lazy `eq1` List
  340 --
  341 
  342 prop_concatBL       = forAll (sized $ \n -> resize (n `div` 2) arbitrary) $
  343                       L.concat                `eq1` (concat    :: [[W]] -> [W])
  344 prop_lengthBL       = L.length                `eq1` (toInt64 . length    :: [W] -> Int64)
  345 prop_nullBL         = L.null                  `eq1` (null      :: [W] -> Bool)
  346 prop_reverseBL      = L.reverse               `eq1` (reverse   :: [W] -> [W])
  347 prop_transposeBL    = L.transpose             `eq1` (transpose :: [[W]] -> [[W]])
  348 prop_groupBL        = L.group                 `eq1` (group     :: [W] -> [[W]])
  349 prop_groupByBL      = L.groupBy               `eq2` (groupBy   :: (W -> W -> Bool) -> [W] -> [[W]])
  350 prop_initsBL        = L.inits                 `eq1` (inits     :: [W] -> [[W]])
  351 prop_tailsBL        = L.tails                 `eq1` (tails     :: [W] -> [[W]])
  352 prop_allBL          = L.all                   `eq2` (all       :: (W -> Bool) -> [W] -> Bool)
  353 prop_anyBL          = L.any                   `eq2` (any       :: (W -> Bool) -> [W] -> Bool)
  354 prop_appendBL       = L.append                `eq2` ((++)      :: [W] -> [W] -> [W])
  355 prop_breakBL        = L.break                 `eq2` (break     :: (W -> Bool) -> [W] -> ([W],[W]))
  356 prop_concatMapBL    = forAll (sized $ \n -> resize (n `div` 2) arbitrary) $
  357                       L.concatMap             `eq2` (concatMap :: (W -> [W]) -> [W] -> [W])
  358 prop_consBL         = L.cons                  `eq2` ((:)       :: W -> [W] -> [W])
  359 prop_dropBL         = (L.drop . toInt64)      `eq2` (drop      :: Int -> [W] -> [W])
  360 prop_dropWhileBL    = L.dropWhile             `eq2` (dropWhile :: (W -> Bool) -> [W] -> [W])
  361 prop_filterBL       = L.filter                `eq2` (filter    :: (W -> Bool ) -> [W] -> [W])
  362 prop_findBL         = L.find                  `eq2` (find      :: (W -> Bool) -> [W] -> Maybe W)
  363 prop_findIndicesBL  = L.findIndices           `eq2` ((fmap toInt64 .) . findIndices:: (W -> Bool) -> [W] -> [Int64])
  364 prop_findIndexBL    = L.findIndex             `eq2` ((fmap toInt64 .) . findIndex :: (W -> Bool) -> [W] -> Maybe Int64)
  365 prop_isPrefixOfBL   = L.isPrefixOf            `eq2` (isPrefixOf:: [W] -> [W] -> Bool)
  366 prop_stripPrefixBL  = L.stripPrefix           `eq2` (stripPrefix:: [W] -> [W] -> Maybe [W])
  367 prop_isSuffixOfBL   = L.isSuffixOf            `eq2` (isSuffixOf:: [W] -> [W] -> Bool)
  368 prop_stripSuffixBL  = L.stripSuffix           `eq2` (stripSuffix :: [W] -> [W] -> Maybe [W])
  369 prop_mapBL          = L.map                   `eq2` (map       :: (W -> W) -> [W] -> [W])
  370 prop_replicateBL    = forAll arbitrarySizedIntegral $
  371                       (L.replicate . toInt64) `eq2` (replicate :: Int -> W -> [W])
  372 prop_snocBL         = L.snoc                  `eq2` ((\xs x -> xs ++ [x]) :: [W] -> W -> [W])
  373 prop_spanBL         = L.span                  `eq2` (span      :: (W -> Bool) -> [W] -> ([W],[W]))
  374 prop_splitAtBL      = (L.splitAt . toInt64)   `eq2` (splitAt :: Int -> [W] -> ([W],[W]))
  375 prop_takeBL         = (L.take    . toInt64)   `eq2` (take    :: Int -> [W] -> [W])
  376 prop_takeWhileBL    = L.takeWhile             `eq2` (takeWhile :: (W -> Bool) -> [W] -> [W])
  377 prop_elemBL         = L.elem                  `eq2` (elem      :: W -> [W] -> Bool)
  378 prop_notElemBL      = L.notElem               `eq2` (notElem   :: W -> [W] -> Bool)
  379 prop_elemIndexBL    = L.elemIndex             `eq2` ((fmap toInt64 .) . elemIndex   :: W -> [W] -> Maybe Int64)
  380 prop_elemIndicesBL  = L.elemIndices           `eq2` ((fmap toInt64 .) . elemIndices :: W -> [W] -> [Int64])
  381 prop_linesBL        = D.lines                 `eq1` (lines     :: String -> [String])
  382 
  383 prop_foldl1BL       = L.foldl1  `eqnotnull2` (foldl1    :: (W -> W -> W) -> [W] -> W)
  384 prop_foldl1BL'      = L.foldl1' `eqnotnull2` (foldl1'   :: (W -> W -> W) -> [W] -> W)
  385 prop_foldr1BL       = L.foldr1  `eqnotnull2` (foldr1    :: (W -> W -> W) -> [W] -> W)
  386 prop_headBL         = L.head    `eqnotnull1` (head      :: [W] -> W)
  387 prop_initBL         = L.init    `eqnotnull1` (init      :: [W] -> [W])
  388 prop_lastBL         = L.last    `eqnotnull1` (last      :: [W] -> W)
  389 prop_maximumBL      = L.maximum `eqnotnull1` (maximum   :: [W] -> W)
  390 prop_minimumBL      = L.minimum `eqnotnull1` (minimum   :: [W] -> W)
  391 prop_tailBL         = L.tail    `eqnotnull1` (tail      :: [W] -> [W])
  392 
  393 prop_eqBL         = eq2
  394     ((==) :: B   -> B   -> Bool)
  395     ((==) :: [W] -> [W] -> Bool)
  396 prop_compareBL    = eq2
  397     ((compare) :: B   -> B   -> Ordering)
  398     ((compare) :: [W] -> [W] -> Ordering)
  399 prop_foldlBL      = eq3
  400     (L.foldl  :: (X -> W -> X) -> X -> B   -> X)
  401     (  foldl  :: (X -> W -> X) -> X -> [W] -> X)
  402 prop_foldlBL'     = eq3
  403     (L.foldl' :: (X -> W -> X) -> X -> B   -> X)
  404     (  foldl' :: (X -> W -> X) -> X -> [W] -> X)
  405 prop_foldrBL      = eq3
  406     (L.foldr  :: (W -> X -> X) -> X -> B   -> X)
  407     (  foldr  :: (W -> X -> X) -> X -> [W] -> X)
  408 prop_mapAccumLBL  = eq3
  409     (L.mapAccumL :: (X -> W -> (X,W)) -> X -> B   -> (X, B))
  410     (  mapAccumL :: (X -> W -> (X,W)) -> X -> [W] -> (X, [W]))
  411 
  412 prop_mapAccumRBL  = eq3
  413     (L.mapAccumR :: (X -> W -> (X,W)) -> X -> B   -> (X, B))
  414     (  mapAccumR :: (X -> W -> (X,W)) -> X -> [W] -> (X, [W]))
  415 
  416 prop_mapAccumRDL  = eq3
  417     (D.mapAccumR :: (X -> Char -> (X,Char)) -> X -> B   -> (X, B))
  418     (  mapAccumR :: (X -> Char -> (X,Char)) -> X -> [Char] -> (X, [Char]))
  419 
  420 prop_mapAccumRCC  = eq3
  421     (C.mapAccumR :: (X -> Char -> (X,Char)) -> X -> P   -> (X, P))
  422     (  mapAccumR :: (X -> Char -> (X,Char)) -> X -> [Char] -> (X, [Char]))
  423 
  424 prop_unfoldrBL =
  425   forAll arbitrarySizedIntegral $
  426   eq3
  427     ((\n f a -> L.take (fromIntegral n) $
  428         L.unfoldr f a) :: Int -> (X -> Maybe (W,X)) -> X -> B)
  429     ((\n f a ->                  take n $
  430           unfoldr f a) :: Int -> (X -> Maybe (W,X)) -> X -> [W])
  431 
  432 --
  433 -- And finally, check correspondance between Data.ByteString and List
  434 --
  435 
  436 prop_lengthPL     = (fromIntegral.P.length :: P -> Int) `eq1` (length :: [W] -> Int)
  437 prop_nullPL       = P.null      `eq1` (null      :: [W] -> Bool)
  438 prop_reversePL    = P.reverse   `eq1` (reverse   :: [W] -> [W])
  439 prop_transposePL  = P.transpose `eq1` (transpose :: [[W]] -> [[W]])
  440 prop_groupPL      = P.group     `eq1` (group     :: [W] -> [[W]])
  441 prop_groupByPL    = P.groupBy   `eq2` (groupBy   :: (W -> W -> Bool) -> [W] -> [[W]])
  442 prop_initsPL      = P.inits     `eq1` (inits     :: [W] -> [[W]])
  443 prop_tailsPL      = P.tails     `eq1` (tails     :: [W] -> [[W]])
  444 prop_concatPL     = forAll (sized $ \n -> resize (n `div` 2) arbitrary) $
  445                     P.concat    `eq1` (concat    :: [[W]] -> [W])
  446 prop_allPL        = P.all       `eq2` (all       :: (W -> Bool) -> [W] -> Bool)
  447 prop_anyPL        = P.any       `eq2`    (any       :: (W -> Bool) -> [W] -> Bool)
  448 prop_appendPL     = P.append    `eq2`    ((++)      :: [W] -> [W] -> [W])
  449 prop_breakPL      = P.break     `eq2`    (break     :: (W -> Bool) -> [W] -> ([W],[W]))
  450 prop_concatMapPL  = forAll (sized $ \n -> resize (n `div` 2) arbitrary) $
  451                     P.concatMap `eq2`    (concatMap :: (W -> [W]) -> [W] -> [W])
  452 prop_consPL       = P.cons      `eq2`    ((:)       :: W -> [W] -> [W])
  453 prop_dropPL       = P.drop      `eq2`    (drop      :: Int -> [W] -> [W])
  454 prop_dropWhilePL  = P.dropWhile `eq2`    (dropWhile :: (W -> Bool) -> [W] -> [W])
  455 prop_filterPL     = P.filter    `eq2`    (filter    :: (W -> Bool ) -> [W] -> [W])
  456 prop_filterPL_rule= (\x -> P.filter ((==) x))  `eq2` -- test rules
  457                     ((\x -> filter ((==) x)) :: W -> [W] -> [W])
  458 
  459 -- under lambda doesn't fire?
  460 prop_filterLC_rule= (f)  `eq2` -- test rules
  461                     ((\x -> filter ((==) x)) :: Char -> [Char] -> [Char])
  462     where
  463          f x s = LC.filter ((==) x) s
  464 
  465 prop_partitionPL  = P.partition `eq2`    (partition :: (W -> Bool ) -> [W] -> ([W],[W]))
  466 prop_partitionLL  = L.partition `eq2`    (partition :: (W -> Bool ) -> [W] -> ([W],[W]))
  467 prop_findPL       = P.find      `eq2`    (find      :: (W -> Bool) -> [W] -> Maybe W)
  468 prop_findIndexPL  = P.findIndex `eq2`    (findIndex :: (W -> Bool) -> [W] -> Maybe Int)
  469 prop_isPrefixOfPL = P.isPrefixOf`eq2`    (isPrefixOf:: [W] -> [W] -> Bool)
  470 prop_isSuffixOfPL = P.isSuffixOf`eq2`    (isSuffixOf:: [W] -> [W] -> Bool)
  471 prop_isInfixOfPL  = P.isInfixOf `eq2`    (isInfixOf:: [W] -> [W] -> Bool)
  472 prop_stripPrefixPL = P.stripPrefix`eq2`  (stripPrefix:: [W] -> [W] -> Maybe [W])
  473 prop_stripSuffixPL = P.stripSuffix`eq2`  (stripSuffix:: [W] -> [W] -> Maybe [W])
  474 prop_mapPL        = P.map       `eq2`    (map       :: (W -> W) -> [W] -> [W])
  475 prop_replicatePL  = forAll arbitrarySizedIntegral $
  476                     P.replicate `eq2`    (replicate :: Int -> W -> [W])
  477 prop_snocPL       = P.snoc      `eq2`    ((\xs x -> xs ++ [x]) :: [W] -> W -> [W])
  478 prop_spanPL       = P.span      `eq2`    (span      :: (W -> Bool) -> [W] -> ([W],[W]))
  479 prop_splitAtPL    = P.splitAt   `eq2`    (splitAt   :: Int -> [W] -> ([W],[W]))
  480 prop_takePL       = P.take      `eq2`    (take      :: Int -> [W] -> [W])
  481 prop_takeWhilePL  = P.takeWhile `eq2`    (takeWhile :: (W -> Bool) -> [W] -> [W])
  482 prop_elemPL       = P.elem      `eq2`    (elem      :: W -> [W] -> Bool)
  483 prop_notElemPL    = P.notElem   `eq2`    (notElem   :: W -> [W] -> Bool)
  484 prop_elemIndexPL  = P.elemIndex `eq2`    (elemIndex :: W -> [W] -> Maybe Int)
  485 prop_linesPL      = C.lines     `eq1`    (lines     :: String -> [String])
  486 prop_findIndicesPL= P.findIndices`eq2`   (findIndices:: (W -> Bool) -> [W] -> [Int])
  487 prop_elemIndicesPL= P.elemIndices`eq2`   (elemIndices:: W -> [W] -> [Int])
  488 prop_zipPL        = P.zip        `eq2`   (zip :: [W] -> [W] -> [(W,W)])
  489 prop_zipCL        = C.zip        `eq2`   (zip :: [Char] -> [Char] -> [(Char,Char)])
  490 prop_zipLL        = L.zip        `eq2`   (zip :: [W] -> [W] -> [(W,W)])
  491 prop_unzipPL      = P.unzip      `eq1`   (unzip :: [(W,W)] -> ([W],[W]))
  492 prop_unzipLL      = L.unzip      `eq1`   (unzip :: [(W,W)] -> ([W],[W]))
  493 prop_unzipCL      = C.unzip      `eq1`   (unzip :: [(Char,Char)] -> ([Char],[Char]))
  494 
  495 prop_foldl1PL     = P.foldl1    `eqnotnull2` (foldl1   :: (W -> W -> W) -> [W] -> W)
  496 prop_foldl1PL'    = P.foldl1'   `eqnotnull2` (foldl1' :: (W -> W -> W) -> [W] -> W)
  497 prop_foldr1PL     = P.foldr1    `eqnotnull2` (foldr1 :: (W -> W -> W) -> [W] -> W)
  498 prop_scanlPL      = P.scanl     `eqnotnull3` (scanl  :: (W -> W -> W) -> W -> [W] -> [W])
  499 prop_scanl1PL     = P.scanl1    `eqnotnull2` (scanl1 :: (W -> W -> W) -> [W] -> [W])
  500 prop_scanrPL      = P.scanr     `eqnotnull3` (scanr  :: (W -> W -> W) -> W -> [W] -> [W])
  501 prop_scanr1PL     = P.scanr1    `eqnotnull2` (scanr1 :: (W -> W -> W) -> [W] -> [W])
  502 prop_headPL       = P.head      `eqnotnull1` (head      :: [W] -> W)
  503 prop_initPL       = P.init      `eqnotnull1` (init      :: [W] -> [W])
  504 prop_lastPL       = P.last      `eqnotnull1` (last      :: [W] -> W)
  505 prop_maximumPL    = P.maximum   `eqnotnull1` (maximum   :: [W] -> W)
  506 prop_minimumPL    = P.minimum   `eqnotnull1` (minimum   :: [W] -> W)
  507 prop_tailPL       = P.tail      `eqnotnull1` (tail      :: [W] -> [W])
  508 
  509 prop_scanl1CL     = C.scanl1    `eqnotnull2` (scanl1 :: (Char -> Char -> Char) -> [Char] -> [Char])
  510 prop_scanrCL      = C.scanr     `eqnotnull3` (scanr  :: (Char -> Char -> Char) -> Char -> [Char] -> [Char])
  511 prop_scanr1CL     = C.scanr1    `eqnotnull2` (scanr1 :: (Char -> Char -> Char) -> [Char] -> [Char])
  512 
  513 -- prop_zipWithPL'   = P.zipWith'  `eq3` (zipWith :: (W -> W -> W) -> [W] -> [W] -> [W])
  514 
  515 prop_zipWithPL    = (P.zipWith  :: (W -> W -> X) -> P   -> P   -> [X]) `eq3`
  516                       (zipWith  :: (W -> W -> X) -> [W] -> [W] -> [X])
  517 
  518 prop_zipWithPL_rules   = (P.zipWith  :: (W -> W -> W) -> P -> P -> [W]) `eq3`
  519                          (zipWith    :: (W -> W -> W) -> [W] -> [W] -> [W])
  520 
  521 prop_eqPL      = eq2
  522     ((==) :: P   -> P   -> Bool)
  523     ((==) :: [W] -> [W] -> Bool)
  524 prop_comparePL = eq2
  525     ((compare) :: P   -> P   -> Ordering)
  526     ((compare) :: [W] -> [W] -> Ordering)
  527 prop_foldlPL   = eq3
  528     (P.foldl  :: (X -> W -> X) -> X -> P        -> X)
  529     (  foldl  :: (X -> W -> X) -> X -> [W]      -> X)
  530 prop_foldlPL'  = eq3
  531     (P.foldl' :: (X -> W -> X) -> X -> P        -> X)
  532     (  foldl' :: (X -> W -> X) -> X -> [W]      -> X)
  533 prop_foldrPL   = eq3
  534     (P.foldr  :: (W -> X -> X) -> X -> P        -> X)
  535     (  foldr  :: (W -> X -> X) -> X -> [W]      -> X)
  536 prop_mapAccumLPL= eq3
  537     (P.mapAccumL :: (X -> W -> (X,W)) -> X -> P -> (X, P))
  538     (  mapAccumL :: (X -> W -> (X,W)) -> X -> [W] -> (X, [W]))
  539 prop_mapAccumRPL= eq3
  540     (P.mapAccumR :: (X -> W -> (X,W)) -> X -> P -> (X, P))
  541     (  mapAccumR :: (X -> W -> (X,W)) -> X -> [W] -> (X, [W]))
  542 prop_unfoldrPL =
  543   forAll arbitrarySizedIntegral $
  544   eq3
  545     ((\n f a ->      fst $
  546         P.unfoldrN n f a) :: Int -> (X -> Maybe (W,X)) -> X -> P)
  547     ((\n f a ->   take n $
  548           unfoldr    f a) :: Int -> (X -> Maybe (W,X)) -> X -> [W])
  549 
  550 ------------------------------------------------------------------------
  551 --
  552 -- These are miscellaneous tests left over. Or else they test some
  553 -- property internal to a type (i.e. head . sort == minimum), without
  554 -- reference to a model type.
  555 --
  556 
  557 invariant :: L.ByteString -> Bool
  558 invariant Empty       = True
  559 invariant (Chunk c cs) = not (P.null c) && invariant cs
  560 
  561 prop_invariant = invariant
  562 
  563 prop_eq_refl  x     = x        == (x :: ByteString)
  564 prop_eq_symm  x y   = (x == y) == (y == (x :: ByteString))
  565 
  566 prop_eq1 xs      = xs == (unpack . pack $ xs)
  567 prop_eq2 xs      = xs == (xs :: ByteString)
  568 prop_eq3 xs ys   = (xs == ys) == (unpack xs == unpack ys)
  569 
  570 prop_compare1 xs   = (pack xs        `compare` pack xs) == EQ
  571 prop_compare2 xs c = (pack (xs++[c]) `compare` pack xs) == GT
  572 prop_compare3 xs c = (pack xs `compare` pack (xs++[c])) == LT
  573 
  574 prop_compare4 xs    = (not (null xs)) ==> (pack xs  `compare` L.empty) == GT
  575 prop_compare5 xs    = (not (null xs)) ==> (L.empty `compare` pack xs) == LT
  576 prop_compare6 xs ys = (not (null ys)) ==> (pack (xs++ys)  `compare` pack xs) == GT
  577 
  578 prop_compare7 x  y  = x  `compare` y  == (L.singleton x `compare` L.singleton y)
  579 prop_compare8 xs ys = xs `compare` ys == (L.pack xs `compare` L.pack ys)
  580 
  581 prop_compare7LL x  y  = x  `compare` y  == (LC.singleton x `compare` LC.singleton y)
  582 
  583 prop_empty1 = L.length L.empty == 0
  584 prop_empty2 = L.unpack L.empty == []
  585 
  586 prop_packunpack s = (L.unpack . L.pack) s == id s
  587 prop_unpackpack s = (L.pack . L.unpack) s == id s
  588 
  589 prop_null xs = null (L.unpack xs) == L.null xs
  590 
  591 prop_length1 xs = fromIntegral (length xs) == L.length (L.pack xs)
  592 
  593 prop_length2 xs = L.length xs == length1 xs
  594   where length1 ys
  595             | L.null ys = 0
  596             | otherwise = 1 + length1 (L.tail ys)
  597 
  598 prop_cons1 c xs = unpack (L.cons c (pack xs)) == (c:xs)
  599 prop_cons2 c    = L.singleton c == (c `L.cons` L.empty)
  600 prop_cons3 c    = unpack (L.singleton c) == (c:[])
  601 prop_cons4 c    = (c `L.cons` L.empty)  == pack (c:[])
  602 
  603 prop_snoc1 xs c = xs ++ [c] == unpack ((pack xs) `L.snoc` c)
  604 
  605 prop_head  xs = (not (null xs)) ==> head xs == (L.head . pack) xs
  606 prop_head1 xs = not (L.null xs) ==> L.head xs == head (L.unpack xs)
  607 
  608 prop_tail xs  = not (L.null xs) ==> L.tail xs == pack (tail (unpack xs))
  609 prop_tail1 xs = (not (null xs)) ==> tail xs   == (unpack . L.tail . pack) xs
  610 
  611 prop_last xs  = (not (null xs)) ==> last xs    == (L.last . pack) xs
  612 
  613 prop_init xs  =
  614     (not (null xs)) ==>
  615     init xs   == (unpack . L.init . pack) xs
  616 
  617 prop_append1 xs    = (xs ++ xs) == (unpack $ pack xs `L.append` pack xs)
  618 prop_append2 xs ys = (xs ++ ys) == (unpack $ pack xs `L.append` pack ys)
  619 prop_append3 xs ys = L.append xs ys == pack (unpack xs ++ unpack ys)
  620 
  621 prop_map1 f xs   = L.map f (pack xs)    == pack (map f xs)
  622 prop_map2 f g xs = L.map f (L.map g xs) == L.map (f . g) xs
  623 prop_map3 f xs   = map f xs == (unpack . L.map f .  pack) xs
  624 
  625 prop_filter1 c xs = (filter (/=c) xs) == (unpack $ L.filter (/=c) (pack xs))
  626 prop_filter2 p xs = (filter p xs) == (unpack $ L.filter p (pack xs))
  627 
  628 prop_reverse  xs = reverse xs          == (unpack . L.reverse . pack) xs
  629 prop_reverse1 xs = L.reverse (pack xs) == pack (reverse xs)
  630 prop_reverse2 xs = reverse (unpack xs) == (unpack . L.reverse) xs
  631 
  632 prop_transpose xs = (transpose xs) == ((map unpack) . L.transpose . (map pack)) xs
  633 
  634 prop_foldl f c xs = L.foldl f c (pack xs) == foldl f c xs
  635     where _ = c :: Char
  636 
  637 prop_foldr f c xs = L.foldl f c (pack xs) == foldl f c xs
  638     where _ = c :: Char
  639 
  640 prop_foldl_1 xs = L.foldl (\xs c -> c `L.cons` xs) L.empty xs == L.reverse xs
  641 prop_foldr_1 xs = L.foldr (\c xs -> c `L.cons` xs) L.empty xs == id xs
  642 
  643 prop_foldl1_1 xs =
  644     (not . L.null) xs ==>
  645     L.foldl1 (\x c -> if c > x then c else x)   xs ==
  646     L.foldl  (\x c -> if c > x then c else x) 0 xs
  647 
  648 prop_foldl1_2 xs =
  649     (not . L.null) xs ==>
  650     L.foldl1 const xs == L.head xs
  651 
  652 prop_foldl1_3 xs =
  653     (not . L.null) xs ==>
  654     L.foldl1 (flip const) xs == L.last xs
  655 
  656 prop_foldr1_1 xs =
  657     (not . L.null) xs ==>
  658     L.foldr1 (\c x -> if c > x then c else x)   xs ==
  659     L.foldr  (\c x -> if c > x then c else x) 0 xs
  660 
  661 prop_foldr1_2 xs =
  662     (not . L.null) xs ==>
  663     L.foldr1 (flip const) xs == L.last xs
  664 
  665 prop_foldr1_3 xs =
  666     (not . L.null) xs ==>
  667     L.foldr1 const xs == L.head xs
  668 
  669 prop_concat1 xs = (concat [xs,xs]) == (unpack $ L.concat [pack xs, pack xs])
  670 prop_concat2 xs = (concat [xs,[]]) == (unpack $ L.concat [pack xs, pack []])
  671 prop_concat3    = forAll (sized $ \n -> resize (n `div` 2) arbitrary) $ \xss ->
  672                   L.concat (map pack xss) == pack (concat xss)
  673 
  674 prop_concatMap xs = L.concatMap L.singleton xs == (pack . concatMap (:[]) . unpack) xs
  675 
  676 prop_any xs a = (any (== a) xs) == (L.any (== a) (pack xs))
  677 prop_all xs a = (all (== a) xs) == (L.all (== a) (pack xs))
  678 
  679 prop_maximum xs = (not (null xs)) ==> (maximum xs) == (L.maximum ( pack xs ))
  680 prop_minimum xs = (not (null xs)) ==> (minimum xs) == (L.minimum ( pack xs ))
  681 
  682 prop_replicate1 c =
  683     forAll arbitrary $ \(Positive n) ->
  684     unpack (L.replicate (fromIntegral n) c) == replicate n c
  685 
  686 prop_replicate2 c = unpack (L.replicate 0 c) == replicate 0 c
  687 
  688 prop_take1 i xs = L.take (fromIntegral i) (pack xs) == pack (take i xs)
  689 prop_drop1 i xs = L.drop (fromIntegral i) (pack xs) == pack (drop i xs)
  690 
  691 prop_splitAt i xs = --collect (i >= 0 && i < length xs) $
  692     L.splitAt (fromIntegral i) (pack xs) == let (a,b) = splitAt i xs in (pack a, pack b)
  693 
  694 prop_takeWhile f xs = L.takeWhile f (pack xs) == pack (takeWhile f xs)
  695 prop_dropWhile f xs = L.dropWhile f (pack xs) == pack (dropWhile f xs)
  696 
  697 prop_break f xs = L.break f (pack xs) ==
  698     let (a,b) = break f xs in (pack a, pack b)
  699 
  700 prop_breakspan xs c = L.break (==c) xs == L.span (/=c) xs
  701 
  702 prop_span xs a = (span (/=a) xs) == (let (x,y) = L.span (/=a) (pack xs) in (unpack x, unpack y))
  703 
  704 -- prop_breakByte xs c = L.break (== c) xs == L.breakByte c xs
  705 
  706 -- prop_spanByte c xs = (L.span (==c) xs) == L.spanByte c xs
  707 
  708 prop_split c xs = (map L.unpack . map checkInvariant . L.split c $ xs)
  709                == (map P.unpack . P.split c . P.pack . L.unpack $ xs)
  710 
  711 prop_splitWith f xs = (l1 == l2 || l1 == l2+1) &&
  712         sum (map L.length splits) == L.length xs - l2
  713   where splits = L.splitWith f xs
  714         l1 = fromIntegral (length splits)
  715         l2 = L.length (L.filter f xs)
  716 
  717 prop_splitWith_D f xs = (l1 == l2 || l1 == l2+1) &&
  718         sum (map D.length splits) == D.length xs - l2
  719   where splits = D.splitWith f xs
  720         l1 = fromIntegral (length splits)
  721         l2 = D.length (D.filter f xs)
  722 
  723 prop_splitWith_C f xs = (l1 == l2 || l1 == l2+1) &&
  724         sum (map C.length splits) == C.length xs - l2
  725   where splits = C.splitWith f xs
  726         l1 = fromIntegral (length splits)
  727         l2 = C.length (C.filter f xs)
  728 
  729 prop_joinsplit c xs = L.intercalate (pack [c]) (L.split c xs) == id xs
  730 
  731 prop_group xs       = group xs == (map unpack . L.group . pack) xs
  732 prop_groupBy  f xs  = groupBy f xs == (map unpack . L.groupBy f . pack) xs
  733 prop_groupBy_LC  f xs  = groupBy f xs == (map LC.unpack . LC.groupBy f .  LC.pack) xs
  734 
  735 -- prop_joinjoinByte xs ys c = L.joinWithByte c xs ys == L.join (L.singleton c) [xs,ys]
  736 
  737 prop_index xs =
  738   not (null xs) ==>
  739     forAll indices $ \i -> (xs !! i) == L.pack xs `L.index` (fromIntegral i)
  740   where indices = choose (0, length xs -1)
  741 
  742 prop_index_D xs =
  743   not (null xs) ==>
  744     forAll indices $ \i -> (xs !! i) == D.pack xs `D.index` (fromIntegral i)
  745   where indices = choose (0, length xs -1)
  746 
  747 prop_index_C xs =
  748   not (null xs) ==>
  749     forAll indices $ \i -> (xs !! i) == C.pack xs `C.index` (fromIntegral i)
  750   where indices = choose (0, length xs -1)
  751 
  752 prop_elemIndex xs c = (elemIndex c xs) == fmap fromIntegral (L.elemIndex c (pack xs))
  753 prop_elemIndexCL xs c = (elemIndex c xs) == (C.elemIndex c (C.pack xs))
  754 
  755 prop_elemIndices xs c = elemIndices c xs == map fromIntegral (L.elemIndices c (pack xs))
  756 
  757 prop_count c xs = length (L.elemIndices c xs) == fromIntegral (L.count c xs)
  758 
  759 prop_findIndex xs f = (findIndex f xs) == fmap fromIntegral (L.findIndex f (pack xs))
  760 prop_findIndicies xs f = (findIndices f xs) == map fromIntegral (L.findIndices f (pack xs))
  761 
  762 prop_elem    xs c = (c `elem` xs)    == (c `L.elem` (pack xs))
  763 prop_notElem xs c = (c `notElem` xs) == (L.notElem c (pack xs))
  764 prop_elem_notelem xs c = c `L.elem` xs == not (c `L.notElem` xs)
  765 
  766 -- prop_filterByte  xs c = L.filterByte c xs == L.filter (==c) xs
  767 -- prop_filterByte2 xs c = unpack (L.filterByte c xs) == filter (==c) (unpack xs)
  768 
  769 -- prop_filterNotByte  xs c = L.filterNotByte c xs == L.filter (/=c) xs
  770 -- prop_filterNotByte2 xs c = unpack (L.filterNotByte c xs) == filter (/=c) (unpack xs)
  771 
  772 prop_find p xs = find p xs == L.find p (pack xs)
  773 
  774 prop_find_findIndex p xs =
  775     L.find p xs == case L.findIndex p xs of
  776                                 Just n -> Just (xs `L.index` n)
  777                                 _      -> Nothing
  778 
  779 prop_isPrefixOf xs ys = isPrefixOf xs ys == (pack xs `L.isPrefixOf` pack ys)
  780 prop_stripPrefix xs ys = (pack <$> stripPrefix xs ys) == (pack xs `L.stripPrefix` pack ys)
  781 
  782 prop_isSuffixOf xs ys = isSuffixOf xs ys == (pack xs `L.isSuffixOf` pack ys)
  783 prop_stripSuffix xs ys = (pack <$> stripSuffix xs ys) == (pack xs `L.stripSuffix` pack ys)
  784 
  785 {-
  786 prop_sort1 xs = sort xs == (unpack . L.sort . pack) xs
  787 prop_sort2 xs = (not (null xs)) ==> (L.head . L.sort . pack $ xs) == minimum xs
  788 prop_sort3 xs = (not (null xs)) ==> (L.last . L.sort . pack $ xs) == maximum xs
  789 prop_sort4 xs ys =
  790         (not (null xs)) ==>
  791         (not (null ys)) ==>
  792         (L.head . L.sort) (L.append (pack xs) (pack ys)) == min (minimum xs) (minimum ys)
  793 
  794 prop_sort5 xs ys =
  795         (not (null xs)) ==>
  796         (not (null ys)) ==>
  797         (L.last . L.sort) (L.append (pack xs) (pack ys)) == max (maximum xs) (maximum ys)
  798 
  799 -}
  800 
  801 ------------------------------------------------------------------------
  802 -- Misc ByteString properties
  803 
  804 prop_nil1BB = P.length P.empty == 0
  805 prop_nil2BB = P.unpack P.empty == []
  806 prop_nil1BB_monoid = P.length mempty == 0
  807 prop_nil2BB_monoid = P.unpack mempty == []
  808 
  809 prop_nil1LL_monoid = L.length mempty == 0
  810 prop_nil2LL_monoid = L.unpack mempty == []
  811 
  812 prop_tailSBB xs = not (P.null xs) ==> P.tail xs == P.pack (tail (P.unpack xs))
  813 
  814 prop_nullBB xs = null (P.unpack xs) == P.null xs
  815 
  816 prop_lengthBB xs = P.length xs == length1 xs
  817     where
  818         length1 ys
  819             | P.null ys = 0
  820             | otherwise = 1 + length1 (P.tail ys)
  821 
  822 prop_lengthSBB xs = length xs == P.length (P.pack xs)
  823 
  824 prop_indexBB xs =
  825   not (null xs) ==>
  826     forAll indices $ \i -> (xs !! i) == P.pack xs `P.index` i
  827   where indices = choose (0, length xs -1)
  828 
  829 prop_unsafeIndexBB xs =
  830   not (null xs) ==>
  831     forAll indices $ \i -> (xs !! i) == P.pack xs `P.unsafeIndex` i
  832   where indices = choose (0, length xs -1)
  833 
  834 prop_mapfusionBB f g xs = P.map f (P.map g xs) == P.map (f . g) xs
  835 
  836 prop_filterBB f xs = P.filter f (P.pack xs) == P.pack (filter f xs)
  837 
  838 prop_filterfusionBB f g xs = P.filter f (P.filter g xs) == P.filter (\c -> f c && g c) xs
  839 
  840 prop_elemSBB x xs = P.elem x (P.pack xs) == elem x xs
  841 
  842 prop_takeSBB i xs = P.take i (P.pack xs) == P.pack (take i xs)
  843 prop_dropSBB i xs = P.drop i (P.pack xs) == P.pack (drop i xs)
  844 
  845 prop_splitAtSBB i xs = -- collect (i >= 0 && i < length xs) $
  846     P.splitAt i (P.pack xs) ==
  847     let (a,b) = splitAt i xs in (P.pack a, P.pack b)
  848 
  849 prop_foldlBB f c xs = P.foldl f c (P.pack xs) == foldl f c xs
  850   where _ = c :: Char
  851 
  852 prop_scanlfoldlBB f z xs = not (P.null xs) ==> P.last (P.scanl f z xs) == P.foldl f z xs
  853 
  854 prop_foldrBB f c xs = P.foldl f c (P.pack xs) == foldl f c xs
  855   where _ = c :: Char
  856 
  857 prop_takeWhileSBB f xs = P.takeWhile f (P.pack xs) == P.pack (takeWhile f xs)
  858 prop_dropWhileSBB f xs = P.dropWhile f (P.pack xs) == P.pack (dropWhile f xs)
  859 
  860 prop_spanSBB f xs = P.span f (P.pack xs) ==
  861     let (a,b) = span f xs in (P.pack a, P.pack b)
  862 
  863 prop_breakSBB f xs = P.break f (P.pack xs) ==
  864     let (a,b) = break f xs in (P.pack a, P.pack b)
  865 
  866 prop_breakspan_1BB xs c = P.break (== c) xs == P.span (/= c) xs
  867 
  868 prop_linesSBB xs = C.lines (C.pack xs) == map C.pack (lines xs)
  869 
  870 prop_unlinesSBB xss = C.unlines (map C.pack xss) == C.pack (unlines xss)
  871 
  872 prop_wordsSBB xs =
  873     C.words (C.pack xs) == map C.pack (words xs)
  874 
  875 prop_wordsLC xs =
  876     LC.words (LC.pack xs) == map LC.pack (words xs)
  877 
  878 prop_unwordsSBB xss = C.unwords (map C.pack xss) == C.pack (unwords xss)
  879 prop_unwordsSLC xss = LC.unwords (map LC.pack xss) == LC.pack (unwords xss)
  880 
  881 prop_splitWithBB f xs = (l1 == l2 || l1 == l2+1) &&
  882         sum (map P.length splits) == P.length xs - l2
  883   where splits = P.splitWith f xs
  884         l1 = length splits
  885         l2 = P.length (P.filter f xs)
  886 
  887 prop_joinsplitBB c xs = P.intercalate (P.pack [c]) (P.split c xs) == xs
  888 
  889 prop_intercalatePL c x y =
  890 
  891     P.intercalate (P.singleton c) (x : y : []) ==
  892  --     intercalate (singleton c) (s1 : s2 : [])
  893 
  894     P.pack (intercalate [c] [P.unpack x,P.unpack y])
  895 
  896 -- prop_linessplitBB xs =
  897 --     (not . C.null) xs ==>
  898 --     C.lines' xs == C.split '\n' xs
  899 
  900 -- false:
  901 {-
  902 prop_linessplit2BB xs =
  903    (not . C.null) xs ==>
  904     C.lines xs == C.split '\n' xs ++ (if C.last xs == '\n' then [C.empty] else [])
  905 -}
  906 
  907 prop_splitsplitWithBB c xs = P.split c xs == P.splitWith (== c) xs
  908 
  909 prop_bijectionBB  c = (P.w2c . P.c2w) c == id c
  910 prop_bijectionBB' w = (P.c2w . P.w2c) w == id w
  911 
  912 prop_packunpackBB  s = (P.unpack . P.pack) s == id s
  913 prop_packunpackBB' s = (P.pack . P.unpack) s == id s
  914 
  915 prop_eq1BB xs      = xs            == (P.unpack . P.pack $ xs)
  916 prop_eq2BB xs      = xs == (xs :: P.ByteString)
  917 prop_eq3BB xs ys   = (xs == ys) == (P.unpack xs == P.unpack ys)
  918 
  919 prop_compare1BB xs  = (P.pack xs         `compare` P.pack xs) == EQ
  920 prop_compare2BB xs c = (P.pack (xs++[c]) `compare` P.pack xs) == GT
  921 prop_compare3BB xs c = (P.pack xs `compare` P.pack (xs++[c])) == LT
  922 
  923 prop_compare4BB xs  = (not (null xs)) ==> (P.pack xs  `compare` P.empty) == GT
  924 prop_compare5BB xs  = (not (null xs)) ==> (P.empty `compare` P.pack xs) == LT
  925 prop_compare6BB xs ys= (not (null ys)) ==> (P.pack (xs++ys)  `compare` P.pack xs) == GT
  926 
  927 prop_compare7BB x  y = x `compare` y == (C.singleton x `compare` C.singleton y)
  928 prop_compare8BB xs ys = xs `compare` ys == (P.pack xs `compare` P.pack ys)
  929 
  930 prop_consBB  c xs = P.unpack (P.cons c (P.pack xs)) == (c:xs)
  931 prop_cons1BB xs   = 'X' : xs == C.unpack ('X' `C.cons` (C.pack xs))
  932 prop_cons2BB xs c = c : xs == P.unpack (c `P.cons` (P.pack xs))
  933 prop_cons3BB c    = C.unpack (C.singleton c) == (c:[])
  934 prop_cons4BB c    = (c `P.cons` P.empty)  == P.pack (c:[])
  935 
  936 prop_snoc1BB xs c = xs ++ [c] == P.unpack ((P.pack xs) `P.snoc` c)
  937 
  938 prop_head1BB xs     = (not (null xs)) ==> head  xs  == (P.head . P.pack) xs
  939 prop_head2BB xs    = (not (null xs)) ==> head xs   == (P.unsafeHead . P.pack) xs
  940 prop_head3BB xs    = not (P.null xs) ==> P.head xs == head (P.unpack xs)
  941 
  942 prop_tailBB xs     = (not (null xs)) ==> tail xs    == (P.unpack . P.tail . P.pack) xs
  943 prop_tail1BB xs    = (not (null xs)) ==> tail xs    == (P.unpack . P.unsafeTail. P.pack) xs
  944 
  945 prop_lastBB xs     = (not (null xs)) ==> last xs    == (P.last . P.pack) xs
  946 prop_last1BB xs    = (not (null xs)) ==> last xs    == (P.unsafeLast . P.pack) xs
  947 
  948 prop_initBB xs     =
  949     (not (null xs)) ==>
  950     init xs    == (P.unpack . P.init . P.pack) xs
  951 prop_init1BB xs     =
  952     (not (null xs)) ==>
  953     init xs    == (P.unpack . P.unsafeInit . P.pack) xs
  954 
  955 -- prop_null xs = (null xs) ==> null xs == (nullPS (pack xs))
  956 
  957 prop_append1BB xs    = (xs ++ xs) == (P.unpack $ P.pack xs `P.append` P.pack xs)
  958 prop_append2BB xs ys = (xs ++ ys) == (P.unpack $ P.pack xs `P.append` P.pack ys)
  959 prop_append3BB xs ys = P.append xs ys == P.pack (P.unpack xs ++ P.unpack ys)
  960 
  961 prop_append1BB_monoid xs    = (xs ++ xs) == (P.unpack $ P.pack xs `mappend` P.pack xs)
  962 prop_append2BB_monoid xs ys = (xs ++ ys) == (P.unpack $ P.pack xs `mappend` P.pack ys)
  963 prop_append3BB_monoid xs ys = mappend xs ys == P.pack (P.unpack xs ++ P.unpack ys)
  964 
  965 prop_append1LL_monoid xs    = (xs ++ xs) == (L.unpack $ L.pack xs `mappend` L.pack xs)
  966 prop_append2LL_monoid xs ys = (xs ++ ys) == (L.unpack $ L.pack xs `mappend` L.pack ys)
  967 prop_append3LL_monoid xs ys = mappend xs ys == L.pack (L.unpack xs ++ L.unpack ys)
  968 
  969 prop_map1BB f xs   = P.map f (P.pack xs)    == P.pack (map f xs)
  970 prop_map2BB f g xs = P.map f (P.map g xs) == P.map (f . g) xs
  971 prop_map3BB f xs   = map f xs == (P.unpack . P.map f .  P.pack) xs
  972 -- prop_mapBB' f xs   = P.map' f (P.pack xs) == P.pack (map f xs)
  973 
  974 prop_filter1BB xs   = (filter (=='X') xs) == (C.unpack $ C.filter (=='X') (C.pack xs))
  975 prop_filter2BB p xs = (filter p xs) == (P.unpack $ P.filter p (P.pack xs))
  976 
  977 prop_findBB p xs = find p xs == P.find p (P.pack xs)
  978 
  979 prop_find_findIndexBB p xs =
  980     P.find p xs == case P.findIndex p xs of
  981                                 Just n -> Just (xs `P.unsafeIndex` n)
  982                                 _      -> Nothing
  983 
  984 prop_foldl1BB xs a = ((foldl (\x c -> if c == a then x else c:x) [] xs)) ==
  985                    (P.unpack $ P.foldl (\x c -> if c == a then x else c `P.cons` x) P.empty (P.pack xs))
  986 prop_foldl2BB xs = P.foldl (\xs c -> c `P.cons` xs) P.empty (P.pack xs) == P.reverse (P.pack xs)
  987 
  988 prop_foldr1BB xs a = ((foldr (\c x -> if c == a then x else c:x) [] xs)) ==
  989                 (P.unpack $ P.foldr (\c x -> if c == a then x else c `P.cons` x)
  990                     P.empty (P.pack xs))
  991 
  992 prop_foldr2BB xs = P.foldr (\c xs -> c `P.cons` xs) P.empty (P.pack xs) == (P.pack xs)
  993 
  994 prop_foldl1_1BB xs =
  995     (not . P.null) xs ==>
  996     P.foldl1 (\x c -> if c > x then c else x)   xs ==
  997     P.foldl  (\x c -> if c > x then c else x) 0 xs
  998 
  999 prop_foldl1_2BB xs =
 1000     (not . P.null) xs ==>
 1001     P.foldl1 const xs == P.head xs
 1002 
 1003 prop_foldl1_3BB xs =
 1004     (not . P.null) xs ==>
 1005     P.foldl1 (flip const) xs == P.last xs
 1006 
 1007 prop_foldr1_1BB xs =
 1008     (not . P.null) xs ==>
 1009     P.foldr1 (\c x -> if c > x then c else x)   xs ==
 1010     P.foldr  (\c x -> if c > x then c else x) 0 xs
 1011 
 1012 prop_foldr1_2BB xs =
 1013     (not . P.null) xs ==>
 1014     P.foldr1 (flip const) xs == P.last xs
 1015 
 1016 prop_foldr1_3BB xs =
 1017     (not . P.null) xs ==>
 1018     P.foldr1 const xs == P.head xs
 1019 
 1020 prop_takeWhileBB xs a = (takeWhile (/= a) xs) == (P.unpack . (P.takeWhile (/= a)) . P.pack) xs
 1021 
 1022 prop_dropWhileBB xs a = (dropWhile (/= a) xs) == (P.unpack . (P.dropWhile (/= a)) . P.pack) xs
 1023 
 1024 prop_dropWhileCC_isSpace xs =
 1025         (dropWhile isSpace xs) ==
 1026        (C.unpack .  (C.dropWhile isSpace) . C.pack) xs
 1027 
 1028 prop_takeBB xs = (take 10 xs) == (P.unpack . (P.take 10) . P.pack) xs
 1029 
 1030 prop_dropBB xs = (drop 10 xs) == (P.unpack . (P.drop 10) . P.pack) xs
 1031 
 1032 prop_splitAtBB i xs = -- collect (i >= 0 && i < length xs) $
 1033     splitAt i xs ==
 1034     let (x,y) = P.splitAt i (P.pack xs) in (P.unpack x, P.unpack y)
 1035 
 1036 prop_spanBB xs a = (span (/=a) xs) == (let (x,y) = P.span (/=a) (P.pack xs)
 1037                                      in (P.unpack x, P.unpack y))
 1038 
 1039 prop_breakBB xs a = (break (/=a) xs) == (let (x,y) = P.break (/=a) (P.pack xs)
 1040                                        in (P.unpack x, P.unpack y))
 1041 
 1042 prop_reverse1BB xs = (reverse xs) == (P.unpack . P.reverse . P.pack) xs
 1043 prop_reverse2BB xs = P.reverse (P.pack xs) == P.pack (reverse xs)
 1044 prop_reverse3BB xs = reverse (P.unpack xs) == (P.unpack . P.reverse) xs
 1045 
 1046 prop_elemBB xs a = (a `elem` xs) == (a `P.elem` (P.pack xs))
 1047 
 1048 prop_notElemBB c xs = P.notElem c (P.pack xs) == notElem c xs
 1049 
 1050 -- should try to stress it
 1051 prop_concat1BB xs = (concat [xs,xs]) == (P.unpack $ P.concat [P.pack xs, P.pack xs])
 1052 prop_concat2BB xs = (concat [xs,[]]) == (P.unpack $ P.concat [P.pack xs, P.pack []])
 1053 prop_concatBB xss = P.concat (map P.pack xss) == P.pack (concat xss)
 1054 
 1055 prop_concat1BB_monoid xs = (concat [xs,xs]) == (P.unpack $ mconcat [P.pack xs, P.pack xs])
 1056 prop_concat2BB_monoid xs = (concat [xs,[]]) == (P.unpack $ mconcat [P.pack xs, P.pack []])
 1057 prop_concatBB_monoid xss = mconcat (map P.pack xss) == P.pack (concat xss)
 1058 
 1059 prop_concat1LL_monoid xs = (concat [xs,xs]) == (L.unpack $ mconcat [L.pack xs, L.pack xs])
 1060 prop_concat2LL_monoid xs = (concat [xs,[]]) == (L.unpack $ mconcat [L.pack xs, L.pack []])
 1061 prop_concatLL_monoid xss = mconcat (map L.pack xss) == L.pack (concat xss)
 1062 
 1063 prop_concatMapBB xs = C.concatMap C.singleton xs == (C.pack . concatMap (:[]) . C.unpack) xs
 1064 
 1065 prop_anyBB xs a = (any (== a) xs) == (P.any (== a) (P.pack xs))
 1066 prop_allBB xs a = (all (== a) xs) == (P.all (== a) (P.pack xs))
 1067 
 1068 prop_linesBB xs = (lines xs) == ((map C.unpack) . C.lines . C.pack) xs
 1069 
 1070 prop_unlinesBB xs = (unlines.lines) xs == (C.unpack. C.unlines . C.lines .C.pack) xs
 1071 prop_unlinesLC xs = (unlines.lines) xs == (LC.unpack. LC.unlines .  LC.lines .LC.pack) xs
 1072 
 1073 prop_wordsBB xs =
 1074     (words xs) == ((map C.unpack) . C.words . C.pack) xs
 1075 -- prop_wordstokensBB xs = C.words xs == C.tokens isSpace xs
 1076 
 1077 prop_unwordsBB xs =
 1078     (C.pack.unwords.words) xs == (C.unwords . C.words .C.pack) xs
 1079 
 1080 prop_groupBB xs   = group xs == (map P.unpack . P.group . P.pack) xs
 1081 
 1082 prop_groupByBB  xs = groupBy (==) xs == (map P.unpack . P.groupBy (==) . P.pack) xs
 1083 prop_groupBy1CC xs = groupBy (==) xs == (map C.unpack . C.groupBy (==) . C.pack) xs
 1084 prop_groupBy1BB xs = groupBy (/=) xs == (map P.unpack . P.groupBy (/=) . P.pack) xs
 1085 prop_groupBy2CC xs = groupBy (/=) xs == (map C.unpack . C.groupBy (/=) . C.pack) xs
 1086 
 1087 prop_joinBB xs ys = (concat . (intersperse ys) . lines) xs ==
 1088                (C.unpack $ C.intercalate (C.pack ys) (C.lines (C.pack xs)))
 1089 
 1090 prop_elemIndex1BB xs   = (elemIndex 'X' xs) == (C.elemIndex 'X' (C.pack xs))
 1091 prop_elemIndex2BB xs c = (elemIndex c xs) == (C.elemIndex c (C.pack xs))
 1092 
 1093 -- prop_lineIndices1BB xs = C.elemIndices '\n' xs == C.lineIndices xs
 1094 
 1095 prop_countBB c xs = length (P.elemIndices c xs) == P.count c xs
 1096 
 1097 prop_elemIndexEnd1BB c xs = (P.elemIndexEnd c (P.pack xs)) ==
 1098                            (case P.elemIndex c (P.pack (reverse xs)) of
 1099                                 Nothing -> Nothing
 1100                                 Just i  -> Just (length xs -1 -i))
 1101 
 1102 prop_elemIndexEnd1CC c xs = (C.elemIndexEnd c (C.pack xs)) ==
 1103                            (case C.elemIndex c (C.pack (reverse xs)) of
 1104                                 Nothing -> Nothing
 1105                                 Just i  -> Just (length xs -1 -i))
 1106 
 1107 prop_elemIndexEnd2BB c xs = (P.elemIndexEnd c (P.pack xs)) ==
 1108                            ((-) (length xs - 1) `fmap` P.elemIndex c (P.pack $ reverse xs))
 1109 
 1110 prop_elemIndexEnd1LL c xs = (L.elemIndexEnd c (L.pack xs)) ==
 1111                            (case L.elemIndex c (L.pack (reverse xs)) of
 1112                                 Nothing -> Nothing
 1113                                 Just i  -> Just (fromIntegral (length xs) -1 -i))
 1114 
 1115 prop_elemIndexEnd2LL c xs = (L.elemIndexEnd c (L.pack xs)) ==
 1116                            ((-) (fromIntegral (length xs) - 1) `fmap` L.elemIndex c (L.pack $ reverse xs))
 1117 
 1118 prop_elemIndicesBB xs c = elemIndices c xs == P.elemIndices c (P.pack xs)
 1119 
 1120 prop_findIndexBB xs a = (findIndex (==a) xs) == (P.findIndex (==a) (P.pack xs))
 1121 
 1122 prop_findIndiciesBB xs c = (findIndices (==c) xs) == (P.findIndices (==c) (P.pack xs))
 1123 
 1124 -- example properties from QuickCheck.Batch
 1125 prop_sort1BB xs = sort xs == (P.unpack . P.sort . P.pack) xs
 1126 prop_sort2BB xs = (not (null xs)) ==> (P.head . P.sort . P.pack $ xs) == minimum xs
 1127 prop_sort3BB xs = (not (null xs)) ==> (P.last . P.sort . P.pack $ xs) == maximum xs
 1128 prop_sort4BB xs ys =
 1129         (not (null xs)) ==>
 1130         (not (null ys)) ==>
 1131         (P.head . P.sort) (P.append (P.pack xs) (P.pack ys)) == min (minimum xs) (minimum ys)
 1132 prop_sort5BB xs ys =
 1133         (not (null xs)) ==>
 1134         (not (null ys)) ==>
 1135         (P.last . P.sort) (P.append (P.pack xs) (P.pack ys)) == max (maximum xs) (maximum ys)
 1136 
 1137 prop_intersperseBB c xs = (intersperse c xs) == (P.unpack $ P.intersperse c (P.pack xs))
 1138 
 1139 -- prop_transposeBB xs = (transpose xs) == ((map P.unpack) . P.transpose .  (map P.pack)) xs
 1140 
 1141 prop_maximumBB xs = (not (null xs)) ==> (maximum xs) == (P.maximum ( P.pack xs ))
 1142 prop_minimumBB xs = (not (null xs)) ==> (minimum xs) == (P.minimum ( P.pack xs ))
 1143 
 1144 -- prop_dropSpaceBB xs    = dropWhile isSpace xs == C.unpack (C.dropSpace (C.pack xs))
 1145 -- prop_dropSpaceEndBB xs = (C.reverse . (C.dropWhile isSpace) . C.reverse) (C.pack xs) ==
 1146 --                        (C.dropSpaceEnd (C.pack xs))
 1147 
 1148 -- prop_breakSpaceBB xs =
 1149 --     (let (x,y) = C.breakSpace (C.pack xs)
 1150 --      in (C.unpack x, C.unpack y)) == (break isSpace xs)
 1151 
 1152 prop_spanEndBB xs =
 1153         (C.spanEnd (not . isSpace) (C.pack xs)) ==
 1154         (let (x,y) = C.span (not.isSpace) (C.reverse (C.pack xs)) in (C.reverse y,C.reverse x))
 1155 
 1156 prop_breakEndBB p xs = P.breakEnd (not.p) xs == P.spanEnd p xs
 1157 prop_breakEndCC p xs = C.breakEnd (not.p) xs == C.spanEnd p xs
 1158 
 1159 {-
 1160 prop_breakCharBB c xs =
 1161         (break (==c) xs) ==
 1162         (let (x,y) = C.breakChar c (C.pack xs) in (C.unpack x, C.unpack y))
 1163 
 1164 prop_spanCharBB c xs =
 1165         (break (/=c) xs) ==
 1166         (let (x,y) = C.spanChar c (C.pack xs) in (C.unpack x, C.unpack y))
 1167 
 1168 prop_spanChar_1BB c xs =
 1169         (C.span (==c) xs) == C.spanChar c xs
 1170 
 1171 prop_wordsBB' xs =
 1172     (C.unpack . C.unwords  . C.words' . C.pack) xs ==
 1173     (map (\c -> if isSpace c then ' ' else c) xs)
 1174 
 1175 -- prop_linesBB' xs = (C.unpack . C.unlines' . C.lines' . C.pack) xs == (xs)
 1176 -}
 1177 
 1178 prop_unfoldrBB c =
 1179     forAll arbitrarySizedIntegral $ \n ->
 1180       (fst $ C.unfoldrN n fn c) == (C.pack $ take n $ unfoldr fn c)
 1181   where
 1182     fn x = Just (x, chr (ord x + 1))
 1183 
 1184 prop_prefixBB xs ys = isPrefixOf xs ys == (P.pack xs `P.isPrefixOf` P.pack ys)
 1185 prop_prefixLL xs ys = isPrefixOf xs ys == (L.pack xs `L.isPrefixOf` L.pack ys)
 1186 prop_suffixBB xs ys = isSuffixOf xs ys == (P.pack xs `P.isSuffixOf` P.pack ys)
 1187 prop_suffixLL xs ys = isSuffixOf xs ys == (L.pack xs `L.isSuffixOf` L.pack ys)
 1188 
 1189 prop_stripPrefixBB xs ys = (P.pack <$> stripPrefix xs ys) == (P.pack xs `P.stripPrefix` P.pack ys)
 1190 prop_stripPrefixLL xs ys = (L.pack <$> stripPrefix xs ys) == (L.pack xs `L.stripPrefix` L.pack ys)
 1191 prop_stripSuffixBB xs ys = (P.pack <$> stripSuffix xs ys) == (P.pack xs `P.stripSuffix` P.pack ys)
 1192 prop_stripSuffixLL xs ys = (L.pack <$> stripSuffix xs ys) == (L.pack xs `L.stripSuffix` L.pack ys)
 1193 
 1194 prop_copyBB xs = let p = P.pack xs in P.copy p == p
 1195 prop_copyLL xs = let p = L.pack xs in L.copy p == p
 1196 
 1197 prop_initsBB xs = inits xs == map P.unpack (P.inits (P.pack xs))
 1198 
 1199 prop_tailsBB xs = tails xs == map P.unpack (P.tails (P.pack xs))
 1200 
 1201 prop_findSubstringsBB s x l
 1202     = C.findSubstrings (C.pack p) (C.pack s) == naive_findSubstrings p s
 1203   where
 1204     _ = l :: Int
 1205     _ = x :: Int
 1206 
 1207     -- we look for some random substring of the test string
 1208     p = take (model l) $ drop (model x) s
 1209 
 1210     -- naive reference implementation
 1211     naive_findSubstrings :: String -> String -> [Int]
 1212     naive_findSubstrings p s = [x | x <- [0..length s], p `isPrefixOf` drop x s]
 1213 
 1214 prop_findSubstringBB s x l
 1215     = C.findSubstring (C.pack p) (C.pack s) == naive_findSubstring p s
 1216   where
 1217     _ = l :: Int
 1218     _ = x :: Int
 1219 
 1220     -- we look for some random substring of the test string
 1221     p = take (model l) $ drop (model x) s
 1222 
 1223     -- naive reference implementation
 1224     naive_findSubstring :: String -> String -> Maybe Int
 1225     naive_findSubstring p s = listToMaybe [x | x <- [0..length s], p `isPrefixOf` drop x s]
 1226 
 1227 -- correspondance between break and breakSubstring
 1228 prop_breakSubstringBB c l
 1229     = P.break (== c) l == P.breakSubstring (P.singleton c) l
 1230 
 1231 prop_breakSubstring_isInfixOf s l
 1232     = P.isInfixOf s l == if P.null s then True
 1233                                      else case P.breakSubstring s l of
 1234                                             (x,y) | P.null y  -> False
 1235                                                   | otherwise -> True
 1236 
 1237 prop_breakSubstring_findSubstring s l
 1238     = P.findSubstring s l == if P.null s then Just 0
 1239                                        else case P.breakSubstring s l of
 1240                                             (x,y) | P.null y  -> Nothing
 1241                                                   | otherwise -> Just (P.length x)
 1242 
 1243 prop_replicate1BB c = forAll arbitrarySizedIntegral $ \n ->
 1244                       P.unpack (P.replicate n c) == replicate n c
 1245 prop_replicate2BB c = forAll arbitrarySizedIntegral $ \n ->
 1246                       P.replicate n c == fst (P.unfoldrN n (\u -> Just (u,u)) c)
 1247 
 1248 prop_replicate3BB c = P.unpack (P.replicate 0 c) == replicate 0 c
 1249 
 1250 prop_readintBB n = (fst . fromJust . C.readInt . C.pack . show) n == (n :: Int)
 1251 prop_readintLL n = (fst . fromJust . D.readInt . D.pack . show) n == (n :: Int)
 1252 
 1253 prop_readBB x = (read . show) x == (x :: P.ByteString)
 1254 prop_readLL x = (read . show) x == (x :: L.ByteString)
 1255 
 1256 prop_readint2BB s =
 1257     let s' = filter (\c -> c `notElem` ['0'..'9']) s
 1258     in C.readInt (C.pack s') == Nothing
 1259 
 1260 prop_readintegerBB n = (fst . fromJust . C.readInteger . C.pack . show) n == (n :: Integer)
 1261 prop_readintegerLL n = (fst . fromJust . D.readInteger . D.pack . show) n == (n :: Integer)
 1262 
 1263 prop_readinteger2BB s =
 1264     let s' = filter (\c -> c `notElem` ['0'..'9']) s
 1265     in C.readInteger (C.pack s') == Nothing
 1266 
 1267 -- prop_filterChar1BB c xs = (filter (==c) xs) == ((C.unpack . C.filterChar c . C.pack) xs)
 1268 -- prop_filterChar2BB c xs = (C.filter (==c) (C.pack xs)) == (C.filterChar c (C.pack xs))
 1269 -- prop_filterChar3BB c xs = C.filterChar c xs == C.replicate (C.count c xs) c
 1270 
 1271 -- prop_filterNotChar1BB c xs = (filter (/=c) xs) == ((C.unpack . C.filterNotChar c . C.pack) xs)
 1272 -- prop_filterNotChar2BB c xs = (C.filter (/=c) (C.pack xs)) == (C.filterNotChar c (C.pack xs))
 1273 
 1274 -- prop_joinjoinpathBB xs ys c = C.joinWithChar c xs ys == C.join (C.singleton c) [xs,ys]
 1275 
 1276 prop_zipBB  xs ys = zip xs ys == P.zip (P.pack xs) (P.pack ys)
 1277 prop_zipLC  xs ys = zip xs ys == LC.zip (LC.pack xs) (LC.pack ys)
 1278 prop_zip1BB xs ys = P.zip xs ys == zip (P.unpack xs) (P.unpack ys)
 1279 
 1280 prop_zipWithBB xs ys = P.zipWith (,) xs ys == P.zip xs ys
 1281 prop_zipWithCC xs ys = C.zipWith (,) xs ys == C.zip xs ys
 1282 prop_zipWithLC xs ys = LC.zipWith (,) xs ys == LC.zip xs ys
 1283 -- prop_zipWith'BB xs ys = P.pack (P.zipWith (+) xs ys) == P.zipWith' (+) xs ys
 1284 
 1285 prop_unzipBB x = let (xs,ys) = unzip x in (P.pack xs, P.pack ys) == P.unzip x
 1286 
 1287 
 1288 -- prop_zipwith_spec f p q =
 1289 --   P.pack (P.zipWith f p q) == P.zipWith' f p q
 1290 --   where _ = f :: Word8 -> Word8 -> Word8
 1291 
 1292 -- prop_join_spec c s1 s2 =
 1293 --  P.join (P.singleton c) (s1 : s2 : []) == P.joinWithByte c s1 s2
 1294 
 1295 -- prop_break_spec x s =
 1296 --     P.break ((==) x) s == P.breakByte x s
 1297 
 1298 -- prop_span_spec x s =
 1299 --     P.span ((==) x) s == P.spanByte x s
 1300 
 1301 ------------------------------------------------------------------------
 1302 
 1303 -- Test IsString, Show, Read, pack, unpack
 1304 prop_isstring x = C.unpack (fromString x :: C.ByteString) == x
 1305 prop_isstring_lc x = LC.unpack (fromString x :: LC.ByteString) == x
 1306 
 1307 prop_showP1 x = show x == show (C.unpack x)
 1308 prop_showL1 x = show x == show (LC.unpack x)
 1309 
 1310 prop_readP1 x = read (show x) == (x :: P.ByteString)
 1311 prop_readP2 x = read (show x) == C.pack (x :: String)
 1312 
 1313 prop_readL1 x = read (show x) == (x :: L.ByteString)
 1314 prop_readL2 x = read (show x) == LC.pack (x :: String)
 1315 
 1316 prop_packunpack_s x = (P.unpack . P.pack) x == x
 1317 prop_unpackpack_s x = (P.pack . P.unpack) x == x
 1318 
 1319 prop_packunpack_c x = (C.unpack . C.pack) x == x
 1320 prop_unpackpack_c x = (C.pack . C.unpack) x == x
 1321 
 1322 prop_packunpack_l x = (L.unpack . L.pack) x == x
 1323 prop_unpackpack_l x = (L.pack . L.unpack) x == x
 1324 
 1325 prop_packunpack_lc x = (LC.unpack . LC.pack) x == x
 1326 prop_unpackpack_lc x = (LC.pack . LC.unpack) x == x
 1327 
 1328 prop_toFromChunks x = (L.fromChunks . L.toChunks) x == x
 1329 prop_fromToChunks x = (L.toChunks . L.fromChunks) x == filter (not . P.null) x
 1330 
 1331 prop_toFromStrict x = (L.fromStrict . L.toStrict) x == x
 1332 prop_fromToStrict x = (L.toStrict . L.fromStrict) x == x
 1333 
 1334 prop_packUptoLenBytes cs =
 1335     forAll (choose (0, length cs + 1)) $ \n ->
 1336       let (bs, cs') = P.packUptoLenBytes n cs
 1337        in P.length bs == min n (length cs)
 1338        && take n cs == P.unpack bs
 1339        && P.pack (take n cs) == bs
 1340        && drop n cs == cs'
 1341 
 1342 prop_packUptoLenChars cs =
 1343     forAll (choose (0, length cs + 1)) $ \n ->
 1344       let (bs, cs') = P.packUptoLenChars n cs
 1345        in P.length bs == min n (length cs)
 1346        && take n cs == C.unpack bs
 1347        && C.pack (take n cs) == bs
 1348        && drop n cs == cs'
 1349 
 1350 prop_unpack_s cs =
 1351     forAll (choose (0, length cs)) $ \n ->
 1352       P.unpack (P.drop n $ P.pack cs) == drop n cs
 1353 prop_unpack_c cs =
 1354     forAll (choose (0, length cs)) $ \n ->
 1355       C.unpack (C.drop n $ C.pack cs) == drop n cs
 1356 
 1357 prop_unpack_l  cs =
 1358     forAll (choose (0, length cs)) $ \n ->
 1359       L.unpack (L.drop (fromIntegral n) $ L.pack cs) == drop n cs
 1360 prop_unpack_lc cs =
 1361     forAll (choose (0, length cs)) $ \n ->
 1362       LC.unpack (L.drop (fromIntegral n) $ LC.pack cs) == drop n cs
 1363 
 1364 prop_unpackBytes cs =
 1365     forAll (choose (0, length cs)) $ \n ->
 1366       P.unpackBytes (P.drop n $ P.pack cs) == drop n cs
 1367 prop_unpackChars cs =
 1368     forAll (choose (0, length cs)) $ \n ->
 1369       P.unpackChars (P.drop n $ C.pack cs) == drop n cs
 1370 
 1371 prop_unpackBytes_l =
 1372     forAll (sized $ \n -> resize (n * 10) arbitrary) $ \cs ->
 1373     forAll (choose (0, length cs)) $ \n ->
 1374       L.unpackBytes (L.drop (fromIntegral n) $ L.pack cs) == drop n cs
 1375 prop_unpackChars_l =
 1376     forAll (sized $ \n -> resize (n * 10) arbitrary) $ \cs ->
 1377     forAll (choose (0, length cs)) $ \n ->
 1378       L.unpackChars (L.drop (fromIntegral n) $ LC.pack cs) == drop n cs
 1379 
 1380 prop_unpackAppendBytesLazy cs' =
 1381     forAll (sized $ \n -> resize (n * 10) arbitrary) $ \cs ->
 1382     forAll (choose (0, 2)) $ \n ->
 1383       P.unpackAppendBytesLazy (P.drop n $ P.pack cs) cs' == drop n cs ++ cs'
 1384 prop_unpackAppendCharsLazy cs' =
 1385     forAll (sized $ \n -> resize (n * 10) arbitrary) $ \cs ->
 1386     forAll (choose (0, 2)) $ \n ->
 1387       P.unpackAppendCharsLazy (P.drop n $ C.pack cs) cs' == drop n cs ++ cs'
 1388 
 1389 prop_unpackAppendBytesStrict cs cs' =
 1390     forAll (choose (0, length cs)) $ \n ->
 1391       P.unpackAppendBytesStrict (P.drop n $ P.pack cs) cs' == drop n cs ++ cs'
 1392 
 1393 prop_unpackAppendCharsStrict cs cs' =
 1394     forAll (choose (0, length cs)) $ \n ->
 1395       P.unpackAppendCharsStrict (P.drop n $ C.pack cs) cs' == drop n cs ++ cs'
 1396 
 1397 ------------------------------------------------------------------------
 1398 -- Unsafe functions
 1399 
 1400 -- Test unsafePackAddress
 1401 prop_unsafePackAddress (CByteString x) = unsafePerformIO $ do
 1402         let (p,_,_) = P.toForeignPtr (x `P.snoc` 0)
 1403         y <- withForeignPtr p $ \(Ptr addr) ->
 1404             P.unsafePackAddress addr
 1405         return (y == x)
 1406 
 1407 -- Test unsafePackAddressLen
 1408 prop_unsafePackAddressLen x = unsafePerformIO $ do
 1409         let i = P.length x
 1410             (p,_,_) = P.toForeignPtr (x `P.snoc` 0)
 1411         y <- withForeignPtr p $ \(Ptr addr) ->
 1412             P.unsafePackAddressLen i addr
 1413         return (y == x)
 1414 
 1415 prop_unsafeUseAsCString x = unsafePerformIO $ do
 1416         let n = P.length x
 1417         y <- P.unsafeUseAsCString x $ \cstr ->
 1418                     sequence [ do a <- peekElemOff cstr i
 1419                                   let b = x `P.index` i
 1420                                   return (a == fromIntegral b)
 1421                              | i <- [0.. n-1]     ]
 1422         return (and y)
 1423 
 1424 prop_unsafeUseAsCStringLen x = unsafePerformIO $ do
 1425         let n = P.length x
 1426         y <- P.unsafeUseAsCStringLen x $ \(cstr,_) ->
 1427                     sequence [ do a <- peekElemOff cstr i
 1428                                   let b = x `P.index` i
 1429                                   return (a == fromIntegral b)
 1430                              | i <- [0.. n-1]     ]
 1431         return (and y)
 1432 
 1433 prop_internal_invariant x = L.invariant x
 1434 
 1435 prop_useAsCString x = unsafePerformIO $ do
 1436         let n = P.length x
 1437         y <- P.useAsCString x $ \cstr ->
 1438                     sequence [ do a <- peekElemOff cstr i
 1439                                   let b = x `P.index` i
 1440                                   return (a == fromIntegral b)
 1441                              | i <- [0.. n-1]     ]
 1442         return (and y)
 1443 
 1444 prop_packCString (CByteString x) = unsafePerformIO $ do
 1445         y <- P.useAsCString x $ P.unsafePackCString
 1446         return (y == x)
 1447 
 1448 prop_packCString_safe (CByteString x) = unsafePerformIO $ do
 1449         y <- P.useAsCString x $ P.packCString
 1450         return (y == x)
 1451 
 1452 prop_packCStringLen x = unsafePerformIO $ do
 1453         y <- P.useAsCStringLen x $ P.unsafePackCStringLen
 1454         return (y == x && P.length y == P.length x)
 1455 
 1456 prop_packCStringLen_safe x = unsafePerformIO $ do
 1457         y <- P.useAsCStringLen x $ P.packCStringLen
 1458         return (y == x && P.length y == P.length x)
 1459 
 1460 prop_packMallocCString (CByteString x) = unsafePerformIO $ do
 1461 
 1462          let (fp,_,_) = P.toForeignPtr x
 1463          ptr <- mallocArray0 (P.length x) :: IO (Ptr Word8)
 1464          forM_ [0 .. P.length x] $ \n -> pokeElemOff ptr n 0
 1465          withForeignPtr fp $ \qtr -> copyArray ptr qtr (P.length x)
 1466          y   <- P.unsafePackMallocCString (castPtr ptr)
 1467 
 1468          let !z = y == x
 1469          free ptr `seq` return z
 1470 
 1471 prop_unsafeFinalize    x =
 1472     P.length x > 0 ==>
 1473       unsafePerformIO $ do
 1474         x <- P.unsafeFinalize x
 1475         return (x == ())
 1476 
 1477 prop_packCStringFinaliser x = unsafePerformIO $ do
 1478         y <- P.useAsCString x $ \cstr -> P.unsafePackCStringFinalizer (castPtr cstr) (P.length x) (return ())
 1479         return (y == x)
 1480 
 1481 prop_fromForeignPtr x = (let (a,b,c) = (P.toForeignPtr x)
 1482                                 in P.fromForeignPtr a b c) == x
 1483 
 1484 ------------------------------------------------------------------------
 1485 -- IO
 1486 
 1487 prop_read_write_file_P x = unsafePerformIO $ do
 1488     tid <- myThreadId
 1489     let f = "qc-test-"++show tid
 1490     bracket
 1491         (do P.writeFile f x)
 1492         (const $ do removeFile f)
 1493         (const $ do y <- P.readFile f
 1494                     return (x==y))
 1495 
 1496 prop_read_write_file_C x = unsafePerformIO $ do
 1497     tid <- myThreadId
 1498     let f = "qc-test-"++show tid
 1499     bracket
 1500         (do C.writeFile f x)
 1501         (const $ do removeFile f)
 1502         (const $ do y <- C.readFile f
 1503                     return (x==y))
 1504 
 1505 prop_read_write_file_L x = unsafePerformIO $ do
 1506     tid <- myThreadId
 1507     let f = "qc-test-"++show tid
 1508     bracket
 1509         (do L.writeFile f x)
 1510         (const $ do removeFile f)
 1511         (const $ do y <- L.readFile f
 1512                     return (x==y))
 1513 
 1514 prop_read_write_file_D x = unsafePerformIO $ do
 1515     tid <- myThreadId
 1516     let f = "qc-test-"++show tid
 1517     bracket
 1518         (do D.writeFile f x)
 1519         (const $ do removeFile f)
 1520         (const $ do y <- D.readFile f
 1521                     return (x==y))
 1522 
 1523 ------------------------------------------------------------------------
 1524 
 1525 prop_append_file_P x y = unsafePerformIO $ do
 1526     tid <- myThreadId
 1527     let f = "qc-test-"++show tid
 1528     bracket
 1529         (do P.writeFile f x
 1530             P.appendFile f y)
 1531         (const $ do removeFile f)
 1532         (const $ do z <- P.readFile f
 1533                     return (z==(x `P.append` y)))
 1534 
 1535 prop_append_file_C x y = unsafePerformIO $ do
 1536     tid <- myThreadId
 1537     let f = "qc-test-"++show tid
 1538     bracket
 1539         (do C.writeFile f x
 1540             C.appendFile f y)
 1541         (const $ do removeFile f)
 1542         (const $ do z <- C.readFile f
 1543                     return (z==(x `C.append` y)))
 1544 
 1545 prop_append_file_L x y = unsafePerformIO $ do
 1546     tid <- myThreadId
 1547     let f = "qc-test-"++show tid
 1548     bracket
 1549         (do L.writeFile f x
 1550             L.appendFile f y)
 1551         (const $ do removeFile f)
 1552         (const $ do z <- L.readFile f
 1553                     return (z==(x `L.append` y)))
 1554 
 1555 prop_append_file_D x y = unsafePerformIO $ do
 1556     tid <- myThreadId
 1557     let f = "qc-test-"++show tid
 1558     bracket
 1559         (do D.writeFile f x
 1560             D.appendFile f y)
 1561         (const $ do removeFile f)
 1562         (const $ do z <- D.readFile f
 1563                     return (z==(x `D.append` y)))
 1564 
 1565 prop_packAddress = C.pack "this is a test"
 1566             ==
 1567                    C.pack "this is a test"
 1568 
 1569 prop_isSpaceWord8 (w :: Word8) = isSpace c == P.isSpaceChar8 c
 1570    where c = chr (fromIntegral w)
 1571 
 1572 
 1573 ------------------------------------------------------------------------
 1574 -- ByteString.Short
 1575 --
 1576 
 1577 prop_short_pack_unpack xs =
 1578     (Short.unpack . Short.pack) xs == xs
 1579 prop_short_toShort_fromShort bs =
 1580     (Short.fromShort . Short.toShort) bs == bs
 1581 
 1582 prop_short_toShort_unpack bs =
 1583     (Short.unpack . Short.toShort) bs == P.unpack bs
 1584 prop_short_pack_fromShort xs =
 1585     (Short.fromShort . Short.pack) xs == P.pack xs
 1586 
 1587 prop_short_empty =
 1588     Short.empty == Short.toShort P.empty
 1589  && Short.empty == Short.pack []
 1590  && Short.null (Short.toShort P.empty)
 1591  && Short.null (Short.pack [])
 1592  && Short.null Short.empty
 1593 
 1594 prop_short_null_toShort bs =
 1595     P.null bs == Short.null (Short.toShort bs)
 1596 prop_short_null_pack xs =
 1597     null xs == Short.null (Short.pack xs)
 1598 
 1599 prop_short_length_toShort bs =
 1600     P.length bs == Short.length (Short.toShort bs)
 1601 prop_short_length_pack xs =
 1602     length xs == Short.length (Short.pack xs)
 1603 
 1604 prop_short_index_pack xs =
 1605     all (\i -> Short.pack xs `Short.index` i == xs !! i)
 1606         [0 .. length xs - 1]
 1607 prop_short_index_toShort bs =
 1608     all (\i -> Short.toShort bs `Short.index` i == bs `P.index` i)
 1609         [0 .. P.length bs - 1]
 1610 
 1611 prop_short_eq xs ys =
 1612     (xs == ys) == (Short.pack xs == Short.pack ys)
 1613 prop_short_ord xs ys =
 1614     (xs `compare` ys) == (Short.pack xs `compare` Short.pack ys)
 1615 
 1616 prop_short_mappend_empty_empty =
 1617     Short.empty `mappend` Short.empty  == Short.empty
 1618 prop_short_mappend_empty xs =
 1619     Short.empty `mappend` Short.pack xs == Short.pack xs
 1620  && Short.pack xs `mappend` Short.empty == Short.pack xs
 1621 prop_short_mappend xs ys =
 1622     (xs `mappend` ys) == Short.unpack (Short.pack xs `mappend` Short.pack ys)
 1623 prop_short_mconcat xss =
 1624     mconcat xss == Short.unpack (mconcat (map Short.pack xss))
 1625 
 1626 prop_short_fromString s =
 1627     fromString s == Short.fromShort (fromString s)
 1628 
 1629 prop_short_show xs =
 1630     show (Short.pack xs) == show (map P.w2c xs)
 1631 prop_short_show' xs =
 1632     show (Short.pack xs) == show (P.pack xs)
 1633 
 1634 prop_short_read xs =
 1635     read (show (Short.pack xs)) == Short.pack xs
 1636 
 1637 stripSuffix :: [W] -> [W] -> Maybe [W]
 1638 stripSuffix xs ys = reverse <$> stripPrefix (reverse xs) (reverse ys)
 1639 
 1640 short_tests =
 1641     [ testProperty "pack/unpack"              prop_short_pack_unpack
 1642     , testProperty "toShort/fromShort"        prop_short_toShort_fromShort
 1643     , testProperty "toShort/unpack"           prop_short_toShort_unpack
 1644     , testProperty "pack/fromShort"           prop_short_pack_fromShort
 1645     , testProperty "empty"                    prop_short_empty
 1646     , testProperty "null/toShort"             prop_short_null_toShort
 1647     , testProperty "null/pack"                prop_short_null_pack
 1648     , testProperty "length/toShort"           prop_short_length_toShort
 1649     , testProperty "length/pack"              prop_short_length_pack
 1650     , testProperty "index/pack"               prop_short_index_pack
 1651     , testProperty "index/toShort"            prop_short_index_toShort
 1652     , testProperty "Eq"                       prop_short_eq
 1653     , testProperty "Ord"                      prop_short_ord
 1654     , testProperty "mappend/empty/empty"      prop_short_mappend_empty_empty
 1655     , testProperty "mappend/empty"            prop_short_mappend_empty
 1656     , testProperty "mappend"                  prop_short_mappend
 1657     , testProperty "mconcat"                  prop_short_mconcat
 1658     , testProperty "fromString"               prop_short_fromString
 1659     , testProperty "show"                     prop_short_show
 1660     , testProperty "show'"                    prop_short_show'
 1661     , testProperty "read"                     prop_short_read
 1662     ]
 1663 
 1664 ------------------------------------------------------------------------
 1665 -- The entry point
 1666 
 1667 main :: IO ()
 1668 main = defaultMainWithArgs tests ["-o 3"] -- timeout if a test runs for >3 secs
 1669 
 1670 --
 1671 -- And now a list of all the properties to test.
 1672 --
 1673 
 1674 tests = misc_tests
 1675      ++ bl_tests
 1676      ++ cc_tests
 1677      ++ bp_tests
 1678      ++ pl_tests
 1679      ++ bb_tests
 1680      ++ ll_tests
 1681      ++ io_tests
 1682      ++ short_tests
 1683      ++ rules
 1684 
 1685 --
 1686 -- 'morally sound' IO
 1687 --
 1688 io_tests =
 1689     [ testProperty "readFile.writeFile" prop_read_write_file_P
 1690     , testProperty "readFile.writeFile" prop_read_write_file_C
 1691     , testProperty "readFile.writeFile" prop_read_write_file_L
 1692     , testProperty "readFile.writeFile" prop_read_write_file_D
 1693 
 1694     , testProperty "appendFile        " prop_append_file_P
 1695     , testProperty "appendFile        " prop_append_file_C
 1696     , testProperty "appendFile        " prop_append_file_L
 1697     , testProperty "appendFile        " prop_append_file_D
 1698 
 1699     , testProperty "packAddress       " prop_packAddress
 1700 
 1701     ]
 1702 
 1703 misc_tests =
 1704     [ testProperty "packunpack"             prop_packunpack_s
 1705     , testProperty "unpackpack"             prop_unpackpack_s
 1706     , testProperty "packunpack"             prop_packunpack_c
 1707     , testProperty "unpackpack"             prop_unpackpack_c
 1708     , testProperty "packunpack"             prop_packunpack_l
 1709     , testProperty "unpackpack"             prop_unpackpack_l
 1710     , testProperty "packunpack"             prop_packunpack_lc
 1711     , testProperty "unpackpack"             prop_unpackpack_lc
 1712     , testProperty "unpack"                 prop_unpack_s
 1713     , testProperty "unpack"                 prop_unpack_c
 1714     , testProperty "unpack"                 prop_unpack_l
 1715     , testProperty "unpack"                 prop_unpack_lc
 1716     , testProperty "packUptoLenBytes"       prop_packUptoLenBytes
 1717     , testProperty "packUptoLenChars"       prop_packUptoLenChars
 1718     , testProperty "unpackBytes"            prop_unpackBytes
 1719     , testProperty "unpackChars"            prop_unpackChars
 1720     , testProperty "unpackBytes"            prop_unpackBytes_l
 1721     , testProperty "unpackChars"            prop_unpackChars_l
 1722     , testProperty "unpackAppendBytesLazy"  prop_unpackAppendBytesLazy
 1723     , testProperty "unpackAppendCharsLazy"  prop_unpackAppendCharsLazy
 1724     , testProperty "unpackAppendBytesStrict"prop_unpackAppendBytesStrict
 1725     , testProperty "unpackAppendCharsStrict"prop_unpackAppendCharsStrict
 1726     , testProperty "toFromChunks"           prop_toFromChunks
 1727     , testProperty "fromToChunks"           prop_fromToChunks
 1728     , testProperty "toFromStrict"           prop_toFromStrict
 1729     , testProperty "fromToStrict"           prop_fromToStrict
 1730 
 1731     , testProperty "invariant"              prop_invariant
 1732     , testProperty "unsafe pack address"    prop_unsafePackAddress
 1733     , testProperty "unsafe pack address len"prop_unsafePackAddressLen
 1734     , testProperty "unsafeUseAsCString"     prop_unsafeUseAsCString
 1735     , testProperty "unsafeUseAsCStringLen"  prop_unsafeUseAsCStringLen
 1736     , testProperty "useAsCString"           prop_useAsCString
 1737     , testProperty "packCString"            prop_packCString
 1738     , testProperty "packCString safe"       prop_packCString_safe
 1739     , testProperty "packCStringLen"         prop_packCStringLen
 1740     , testProperty "packCStringLen safe"    prop_packCStringLen_safe
 1741     , testProperty "packCStringFinaliser"   prop_packCStringFinaliser
 1742     , testProperty "packMallocString"       prop_packMallocCString
 1743     , testProperty "unsafeFinalise"         prop_unsafeFinalize
 1744     , testProperty "invariant"              prop_internal_invariant
 1745     , testProperty "show 1"                 prop_showP1
 1746     , testProperty "show 2"                 prop_showL1
 1747     , testProperty "read 1"                 prop_readP1
 1748     , testProperty "read 2"                 prop_readP2
 1749     , testProperty "read 3"                 prop_readL1
 1750     , testProperty "read 4"                 prop_readL2
 1751     , testProperty "fromForeignPtr"         prop_fromForeignPtr
 1752     ]
 1753 
 1754 ------------------------------------------------------------------------
 1755 -- ByteString.Lazy <=> List
 1756 
 1757 bl_tests =
 1758     [ testProperty "all"         prop_allBL
 1759     , testProperty "any"         prop_anyBL
 1760     , testProperty "append"      prop_appendBL
 1761     , testProperty "compare"     prop_compareBL
 1762     , testProperty "concat"      prop_concatBL
 1763     , testProperty "cons"        prop_consBL
 1764     , testProperty "eq"          prop_eqBL
 1765     , testProperty "filter"      prop_filterBL
 1766     , testProperty "find"        prop_findBL
 1767     , testProperty "findIndex"   prop_findIndexBL
 1768     , testProperty "findIndices" prop_findIndicesBL
 1769     , testProperty "foldl"       prop_foldlBL
 1770     , testProperty "foldl'"      prop_foldlBL'
 1771     , testProperty "foldl1"      prop_foldl1BL
 1772     , testProperty "foldl1'"     prop_foldl1BL'
 1773     , testProperty "foldr"       prop_foldrBL
 1774     , testProperty "foldr1"      prop_foldr1BL
 1775     , testProperty "mapAccumL"   prop_mapAccumLBL
 1776     , testProperty "mapAccumR"   prop_mapAccumRBL
 1777     , testProperty "mapAccumR"   prop_mapAccumRDL
 1778     , testProperty "mapAccumR"   prop_mapAccumRCC
 1779     , testProperty "unfoldr"     prop_unfoldrBL
 1780     , testProperty "unfoldr"     prop_unfoldrLC
 1781     , testProperty "unfoldr"     prop_cycleLC
 1782     , testProperty "iterate"     prop_iterateLC
 1783     , testProperty "iterate"     prop_iterateLC_2
 1784     , testProperty "iterate"     prop_iterateL
 1785     , testProperty "repeat"      prop_repeatLC
 1786     , testProperty "repeat"      prop_repeatL
 1787     , testProperty "head"        prop_headBL
 1788     , testProperty "init"        prop_initBL
 1789     , testProperty "isPrefixOf"  prop_isPrefixOfBL
 1790     , testProperty "isSuffixOf"  prop_isSuffixOfBL
 1791     , testProperty "stripPrefix" prop_stripPrefixBL
 1792     , testProperty "stripSuffix" prop_stripSuffixBL
 1793     , testProperty "last"        prop_lastBL
 1794     , testProperty "length"      prop_lengthBL
 1795     , testProperty "map"         prop_mapBL
 1796     , testProperty "maximum"     prop_maximumBL
 1797     , testProperty "minimum"     prop_minimumBL
 1798     , testProperty "null"        prop_nullBL
 1799     , testProperty "reverse"     prop_reverseBL
 1800     , testProperty "snoc"        prop_snocBL
 1801     , testProperty "tail"        prop_tailBL
 1802     , testProperty "transpose"   prop_transposeBL
 1803     , testProperty "replicate"   prop_replicateBL
 1804     , testProperty "take"        prop_takeBL
 1805     , testProperty "drop"        prop_dropBL
 1806     , testProperty "splitAt"     prop_splitAtBL
 1807     , testProperty "takeWhile"   prop_takeWhileBL
 1808     , testProperty "dropWhile"   prop_dropWhileBL
 1809     , testProperty "break"       prop_breakBL
 1810     , testProperty "span"        prop_spanBL
 1811     , testProperty "group"       prop_groupBL
 1812     , testProperty "groupBy"     prop_groupByBL
 1813     , testProperty "inits"       prop_initsBL
 1814     , testProperty "tails"       prop_tailsBL
 1815     , testProperty "elem"        prop_elemBL
 1816     , testProperty "notElem"     prop_notElemBL
 1817     , testProperty "lines"       prop_linesBL
 1818     , testProperty "elemIndex"   prop_elemIndexBL
 1819     , testProperty "elemIndices" prop_elemIndicesBL
 1820     , testProperty "concatMap"   prop_concatMapBL
 1821     ]
 1822 
 1823 ------------------------------------------------------------------------
 1824 -- ByteString.Lazy <=> ByteString
 1825 
 1826 cc_tests =
 1827     [ testProperty "prop_concatCC"      prop_concatCC
 1828     , testProperty "prop_nullCC"        prop_nullCC
 1829     , testProperty "prop_reverseCC"     prop_reverseCC
 1830     , testProperty "prop_transposeCC"   prop_transposeCC
 1831     , testProperty "prop_groupCC"       prop_groupCC
 1832     , testProperty "prop_groupByCC"     prop_groupByCC
 1833     , testProperty "prop_initsCC"       prop_initsCC
 1834     , testProperty "prop_tailsCC"       prop_tailsCC
 1835     , testProperty "prop_allCC"         prop_allCC
 1836     , testProperty "prop_anyCC"         prop_anyCC
 1837     , testProperty "prop_appendCC"      prop_appendCC
 1838     , testProperty "prop_breakCC"       prop_breakCC
 1839     , testProperty "prop_concatMapCC"   prop_concatMapCC
 1840     , testProperty "prop_consCC"        prop_consCC
 1841     , testProperty "prop_consCC'"       prop_consCC'
 1842     , testProperty "prop_unconsCC"      prop_unconsCC
 1843     , testProperty "prop_unsnocCC"      prop_unsnocCC
 1844     , testProperty "prop_countCC"       prop_countCC
 1845     , testProperty "prop_dropCC"        prop_dropCC
 1846     , testProperty "prop_dropWhileCC"   prop_dropWhileCC
 1847     , testProperty "prop_filterCC"      prop_filterCC
 1848     , testProperty "prop_findCC"        prop_findCC
 1849     , testProperty "prop_findIndexCC"   prop_findIndexCC
 1850     , testProperty "prop_findIndicesCC" prop_findIndicesCC
 1851     , testProperty "prop_isPrefixCC"    prop_isPrefixOfCC
 1852     , testProperty "prop_isSuffixCC"    prop_isSuffixOfCC
 1853     , testProperty "prop_stripPrefixCC" prop_stripPrefixCC
 1854     , testProperty "prop_stripSuffixCC" prop_stripSuffixCC
 1855     , testProperty "prop_mapCC"         prop_mapCC
 1856     , testProperty "prop_replicateCC"   prop_replicateCC
 1857     , testProperty "prop_snocCC"        prop_snocCC
 1858     , testProperty "prop_spanCC"        prop_spanCC
 1859     , testProperty "prop_splitCC"       prop_splitCC
 1860     , testProperty "prop_splitAtCC"     prop_splitAtCC
 1861     , testProperty "prop_takeCC"        prop_takeCC
 1862     , testProperty "prop_takeWhileCC"   prop_takeWhileCC
 1863     , testProperty "prop_elemCC"        prop_elemCC
 1864     , testProperty "prop_notElemCC"     prop_notElemCC
 1865     , testProperty "prop_elemIndexCC"   prop_elemIndexCC
 1866     , testProperty "prop_elemIndicesCC" prop_elemIndicesCC
 1867     , testProperty "prop_lengthCC"      prop_lengthCC
 1868     , testProperty "prop_headCC"        prop_headCC
 1869     , testProperty "prop_initCC"        prop_initCC
 1870     , testProperty "prop_lastCC"        prop_lastCC
 1871     , testProperty "prop_maximumCC"     prop_maximumCC
 1872     , testProperty "prop_minimumCC"     prop_minimumCC
 1873     , testProperty "prop_tailCC"        prop_tailCC
 1874     , testProperty "prop_foldl1CC"      prop_foldl1CC
 1875     , testProperty "prop_foldl1CC'"     prop_foldl1CC'
 1876     , testProperty "prop_foldr1CC"      prop_foldr1CC
 1877     , testProperty "prop_foldr1CC'"     prop_foldr1CC'
 1878     , testProperty "prop_scanlCC"       prop_scanlCC
 1879     , testProperty "prop_intersperseCC" prop_intersperseCC
 1880 
 1881     , testProperty "prop_foldlCC"       prop_foldlCC
 1882     , testProperty "prop_foldlCC'"      prop_foldlCC'
 1883     , testProperty "prop_foldrCC"       prop_foldrCC
 1884     , testProperty "prop_foldrCC'"      prop_foldrCC'
 1885     , testProperty "prop_mapAccumLCC"   prop_mapAccumLCC
 1886 --    , testProperty "prop_mapIndexedCC" prop_mapIndexedCC
 1887 --    , testProperty "prop_mapIndexedPL" prop_mapIndexedPL
 1888     ]
 1889 
 1890 bp_tests =
 1891     [ testProperty "all"         prop_allBP
 1892     , testProperty "any"         prop_anyBP
 1893     , testProperty "append"      prop_appendBP
 1894     , testProperty "compare"     prop_compareBP
 1895     , testProperty "concat"      prop_concatBP
 1896     , testProperty "cons"        prop_consBP
 1897     , testProperty "cons'"       prop_consBP'
 1898     , testProperty "uncons"      prop_unconsBP
 1899     , testProperty "unsnoc"      prop_unsnocBP
 1900     , testProperty "eq"          prop_eqBP
 1901     , testProperty "filter"      prop_filterBP
 1902     , testProperty "find"        prop_findBP
 1903     , testProperty "findIndex"   prop_findIndexBP
 1904     , testProperty "findIndices" prop_findIndicesBP
 1905     , testProperty "foldl"       prop_foldlBP
 1906     , testProperty "foldl'"      prop_foldlBP'
 1907     , testProperty "foldl1"      prop_foldl1BP
 1908     , testProperty "foldl1'"     prop_foldl1BP'
 1909     , testProperty "foldr"       prop_foldrBP
 1910     , testProperty "foldr'"      prop_foldrBP'
 1911     , testProperty "foldr1"      prop_foldr1BP
 1912     , testProperty "foldr1'"     prop_foldr1BP'
 1913     , testProperty "mapAccumL"   prop_mapAccumLBP
 1914 --  , testProperty "mapAccumL"   prop_mapAccumL_mapIndexedBP
 1915     , testProperty "unfoldr"     prop_unfoldrBP
 1916     , testProperty "unfoldr 2"   prop_unfoldr2BP
 1917     , testProperty "unfoldr 2"   prop_unfoldr2CP
 1918     , testProperty "head"        prop_headBP
 1919     , testProperty "init"        prop_initBP
 1920     , testProperty "isPrefixOf"  prop_isPrefixOfBP
 1921     , testProperty "isSuffixOf"  prop_isSuffixOfBP
 1922     , testProperty "stripPrefix" prop_stripPrefixBP
 1923     , testProperty "stripSuffix" prop_stripSuffixBP
 1924     , testProperty "last"        prop_lastBP
 1925     , testProperty "length"      prop_lengthBP
 1926     , testProperty "readInt"     prop_readIntBP
 1927     , testProperty "lines"       prop_linesBP
 1928     , testProperty "lines \\n"   prop_linesNLBP
 1929     , testProperty "map"         prop_mapBP
 1930     , testProperty "maximum   "  prop_maximumBP
 1931     , testProperty "minimum"     prop_minimumBP
 1932     , testProperty "null"        prop_nullBP
 1933     , testProperty "reverse"     prop_reverseBP
 1934     , testProperty "snoc"        prop_snocBP
 1935     , testProperty "tail"        prop_tailBP
 1936     , testProperty "scanl"       prop_scanlBP
 1937     , testProperty "transpose"   prop_transposeBP
 1938     , testProperty "replicate"   prop_replicateBP
 1939     , testProperty "take"        prop_takeBP
 1940     , testProperty "drop"        prop_dropBP
 1941     , testProperty "splitAt"     prop_splitAtBP
 1942     , testProperty "takeWhile"   prop_takeWhileBP
 1943     , testProperty "dropWhile"   prop_dropWhileBP
 1944     , testProperty "break"       prop_breakBP
 1945     , testProperty "span"        prop_spanBP
 1946     , testProperty "split"       prop_splitBP
 1947     , testProperty "count"       prop_countBP
 1948     , testProperty "group"       prop_groupBP
 1949     , testProperty "groupBy"     prop_groupByBP
 1950     , testProperty "inits"       prop_initsBP
 1951     , testProperty "tails"       prop_tailsBP
 1952     , testProperty "elem"        prop_elemBP
 1953     , testProperty "notElem"     prop_notElemBP
 1954     , testProperty "elemIndex"   prop_elemIndexBP
 1955     , testProperty "elemIndices" prop_elemIndicesBP
 1956     , testProperty "intersperse" prop_intersperseBP
 1957     , testProperty "concatMap"   prop_concatMapBP
 1958     ]
 1959 
 1960 ------------------------------------------------------------------------
 1961 -- ByteString <=> List
 1962 
 1963 pl_tests =
 1964     [ testProperty "all"         prop_allPL
 1965     , testProperty "any"         prop_anyPL
 1966     , testProperty "append"      prop_appendPL
 1967     , testProperty "compare"     prop_comparePL
 1968     , testProperty "concat"      prop_concatPL
 1969     , testProperty "cons"        prop_consPL
 1970     , testProperty "eq"          prop_eqPL
 1971     , testProperty "filter"      prop_filterPL
 1972     , testProperty "filter rules"prop_filterPL_rule
 1973     , testProperty "filter rules"prop_filterLC_rule
 1974     , testProperty "partition"   prop_partitionPL
 1975     , testProperty "partition"   prop_partitionLL
 1976     , testProperty "find"        prop_findPL
 1977     , testProperty "findIndex"   prop_findIndexPL
 1978     , testProperty "findIndices" prop_findIndicesPL
 1979     , testProperty "foldl"       prop_foldlPL
 1980     , testProperty "foldl'"      prop_foldlPL'
 1981     , testProperty "foldl1"      prop_foldl1PL
 1982     , testProperty "foldl1'"     prop_foldl1PL'
 1983     , testProperty "foldr1"      prop_foldr1PL
 1984     , testProperty "foldr"       prop_foldrPL
 1985     , testProperty "mapAccumL"   prop_mapAccumLPL
 1986     , testProperty "mapAccumR"   prop_mapAccumRPL
 1987     , testProperty "unfoldr"     prop_unfoldrPL
 1988     , testProperty "scanl"       prop_scanlPL
 1989     , testProperty "scanl1"      prop_scanl1PL
 1990     , testProperty "scanl1"      prop_scanl1CL
 1991     , testProperty "scanr"       prop_scanrCL
 1992     , testProperty "scanr"       prop_scanrPL
 1993     , testProperty "scanr1"      prop_scanr1PL
 1994     , testProperty "scanr1"      prop_scanr1CL
 1995     , testProperty "head"        prop_headPL
 1996     , testProperty "init"        prop_initPL
 1997     , testProperty "last"        prop_lastPL
 1998     , testProperty "maximum"     prop_maximumPL
 1999     , testProperty "minimum"     prop_minimumPL
 2000     , testProperty "tail"        prop_tailPL
 2001     , testProperty "zip"         prop_zipPL
 2002     , testProperty "zip"         prop_zipLL
 2003     , testProperty "zip"         prop_zipCL
 2004     , testProperty "unzip"       prop_unzipPL
 2005     , testProperty "unzip"       prop_unzipLL
 2006     , testProperty "unzip"       prop_unzipCL
 2007     , testProperty "zipWith"          prop_zipWithPL
 2008 --  , testProperty "zipWith"          prop_zipWithCL
 2009     , testProperty "zipWith rules"   prop_zipWithPL_rules
 2010 --  , testProperty "zipWith/zipWith'" prop_zipWithPL'
 2011 
 2012     , testProperty "isPrefixOf"  prop_isPrefixOfPL
 2013     , testProperty "isSuffixOf"  prop_isSuffixOfPL
 2014     , testProperty "isInfixOf"   prop_isInfixOfPL
 2015     , testProperty "stripPrefix" prop_stripPrefixPL
 2016     , testProperty "stripSuffix" prop_stripSuffixPL
 2017     , testProperty "length"      prop_lengthPL
 2018     , testProperty "map"         prop_mapPL
 2019     , testProperty "null"        prop_nullPL
 2020     , testProperty "reverse"     prop_reversePL
 2021     , testProperty "snoc"        prop_snocPL
 2022     , testProperty "transpose"   prop_transposePL
 2023     , testProperty "replicate"   prop_replicatePL
 2024     , testProperty "take"        prop_takePL
 2025     , testProperty "drop"        prop_dropPL
 2026     , testProperty "splitAt"     prop_splitAtPL
 2027     , testProperty "takeWhile"   prop_takeWhilePL
 2028     , testProperty "dropWhile"   prop_dropWhilePL
 2029     , testProperty "break"       prop_breakPL
 2030     , testProperty "span"        prop_spanPL
 2031     , testProperty "group"       prop_groupPL
 2032     , testProperty "groupBy"     prop_groupByPL
 2033     , testProperty "inits"       prop_initsPL
 2034     , testProperty "tails"       prop_tailsPL
 2035     , testProperty "elem"        prop_elemPL
 2036     , testProperty "notElem"     prop_notElemPL
 2037     , testProperty "lines"       prop_linesPL
 2038     , testProperty "elemIndex"   prop_elemIndexPL
 2039     , testProperty "elemIndex"   prop_elemIndexCL
 2040     , testProperty "elemIndices" prop_elemIndicesPL
 2041     , testProperty "concatMap"   prop_concatMapPL
 2042     , testProperty "IsString"    prop_isstring
 2043     , testProperty "IsString LC" prop_isstring_lc
 2044     ]
 2045 
 2046 ------------------------------------------------------------------------
 2047 -- extra ByteString properties
 2048 
 2049 bb_tests =
 2050     [ testProperty "bijection"      prop_bijectionBB
 2051     , testProperty "bijection'"     prop_bijectionBB'
 2052     , testProperty "pack/unpack"    prop_packunpackBB
 2053     , testProperty "unpack/pack"    prop_packunpackBB'
 2054     , testProperty "eq 1"           prop_eq1BB
 2055     , testProperty "eq 2"           prop_eq2BB
 2056     , testProperty "eq 3"           prop_eq3BB
 2057     , testProperty "compare 1"      prop_compare1BB
 2058     , testProperty "compare 2"      prop_compare2BB
 2059     , testProperty "compare 3"      prop_compare3BB
 2060     , testProperty "compare 4"      prop_compare4BB
 2061     , testProperty "compare 5"      prop_compare5BB
 2062     , testProperty "compare 6"      prop_compare6BB
 2063     , testProperty "compare 7"      prop_compare7BB
 2064     , testProperty "compare 7"      prop_compare7LL
 2065     , testProperty "compare 8"      prop_compare8BB
 2066     , testProperty "empty 1"        prop_nil1BB
 2067     , testProperty "empty 2"        prop_nil2BB
 2068     , testProperty "empty 1 monoid" prop_nil1LL_monoid
 2069     , testProperty "empty 2 monoid" prop_nil2LL_monoid
 2070     , testProperty "empty 1 monoid" prop_nil1BB_monoid
 2071     , testProperty "empty 2 monoid" prop_nil2BB_monoid
 2072 
 2073     , testProperty "null"           prop_nullBB
 2074     , testProperty "length 1"       prop_lengthBB
 2075     , testProperty "length 2"       prop_lengthSBB
 2076     , testProperty "cons 1"         prop_consBB
 2077     , testProperty "cons 2"         prop_cons1BB
 2078     , testProperty "cons 3"         prop_cons2BB
 2079     , testProperty "cons 4"         prop_cons3BB
 2080     , testProperty "cons 5"         prop_cons4BB
 2081     , testProperty "snoc"           prop_snoc1BB
 2082     , testProperty "head 1"         prop_head1BB
 2083     , testProperty "head 2"         prop_head2BB
 2084     , testProperty "head 3"         prop_head3BB
 2085     , testProperty "tail"           prop_tailBB
 2086     , testProperty "tail 1"         prop_tail1BB
 2087     , testProperty "last"           prop_lastBB
 2088     , testProperty "last 1"         prop_last1BB
 2089     , testProperty "init"           prop_initBB
 2090     , testProperty "init 1"         prop_init1BB
 2091     , testProperty "append 1"       prop_append1BB
 2092     , testProperty "append 2"       prop_append2BB
 2093     , testProperty "append 3"       prop_append3BB
 2094     , testProperty "mappend 1"      prop_append1BB_monoid
 2095     , testProperty "mappend 2"      prop_append2BB_monoid
 2096     , testProperty "mappend 3"      prop_append3BB_monoid
 2097 
 2098     , testProperty "map 1"          prop_map1BB
 2099     , testProperty "map 2"          prop_map2BB
 2100     , testProperty "map 3"          prop_map3BB
 2101     , testProperty "filter1"        prop_filter1BB
 2102     , testProperty "filter2"        prop_filter2BB
 2103     , testProperty "map fusion"     prop_mapfusionBB
 2104     , testProperty "filter fusion"  prop_filterfusionBB
 2105     , testProperty "reverse 1"      prop_reverse1BB
 2106     , testProperty "reverse 2"      prop_reverse2BB
 2107     , testProperty "reverse 3"      prop_reverse3BB
 2108     , testProperty "foldl 1"        prop_foldl1BB
 2109     , testProperty "foldl 2"        prop_foldl2BB
 2110     , testProperty "foldr 1"        prop_foldr1BB
 2111     , testProperty "foldr 2"        prop_foldr2BB
 2112     , testProperty "foldl1 1"       prop_foldl1_1BB
 2113     , testProperty "foldl1 2"       prop_foldl1_2BB
 2114     , testProperty "foldl1 3"       prop_foldl1_3BB
 2115     , testProperty "foldr1 1"       prop_foldr1_1BB
 2116     , testProperty "foldr1 2"       prop_foldr1_2BB
 2117     , testProperty "foldr1 3"       prop_foldr1_3BB
 2118     , testProperty "scanl/foldl"    prop_scanlfoldlBB
 2119     , testProperty "all"            prop_allBB
 2120     , testProperty "any"            prop_anyBB
 2121     , testProperty "take"           prop_takeBB
 2122     , testProperty "drop"           prop_dropBB
 2123     , testProperty "takeWhile"      prop_takeWhileBB
 2124     , testProperty "dropWhile"      prop_dropWhileBB
 2125     , testProperty "dropWhile"      prop_dropWhileCC_isSpace
 2126     , testProperty "splitAt"        prop_splitAtBB
 2127     , testProperty "span"           prop_spanBB
 2128     , testProperty "break"          prop_breakBB
 2129     , testProperty "elem"           prop_elemBB
 2130     , testProperty "notElem"        prop_notElemBB
 2131 
 2132     , testProperty "concat 1"       prop_concat1BB
 2133     , testProperty "concat 2"       prop_concat2BB
 2134     , testProperty "concat 3"       prop_concatBB
 2135     , testProperty "mconcat 1"      prop_concat1BB_monoid
 2136     , testProperty "mconcat 2"      prop_concat2BB_monoid
 2137     , testProperty "mconcat 3"      prop_concatBB_monoid
 2138 
 2139     , testProperty "mconcat 1"      prop_concat1LL_monoid
 2140     , testProperty "mconcat 2"      prop_concat2LL_monoid
 2141     , testProperty "mconcat 3"      prop_concatLL_monoid
 2142 
 2143     , testProperty "lines"          prop_linesBB
 2144     , testProperty "unlines"        prop_unlinesBB
 2145     , testProperty "unlines"        prop_unlinesLC
 2146     , testProperty "words"          prop_wordsBB
 2147     , testProperty "words"          prop_wordsLC
 2148     , testProperty "unwords"        prop_unwordsBB
 2149     , testProperty "group"          prop_groupBB
 2150     , testProperty "groupBy 0"      prop_groupByBB
 2151     , testProperty "groupBy 1"      prop_groupBy1CC
 2152     , testProperty "groupBy 2"      prop_groupBy1BB
 2153     , testProperty "groupBy 3"      prop_groupBy2CC
 2154     , testProperty "join"           prop_joinBB
 2155     , testProperty "elemIndex 1"    prop_elemIndex1BB
 2156     , testProperty "elemIndex 2"    prop_elemIndex2BB
 2157     , testProperty "findIndex"      prop_findIndexBB
 2158     , testProperty "findIndicies"   prop_findIndiciesBB
 2159     , testProperty "elemIndices"    prop_elemIndicesBB
 2160     , testProperty "find"           prop_findBB
 2161     , testProperty "find/findIndex" prop_find_findIndexBB
 2162     , testProperty "sort 1"         prop_sort1BB
 2163     , testProperty "sort 2"         prop_sort2BB
 2164     , testProperty "sort 3"         prop_sort3BB
 2165     , testProperty "sort 4"         prop_sort4BB
 2166     , testProperty "sort 5"         prop_sort5BB
 2167     , testProperty "intersperse"    prop_intersperseBB
 2168     , testProperty "maximum"        prop_maximumBB
 2169     , testProperty "minimum"        prop_minimumBB
 2170 --  , testProperty "breakChar"      prop_breakCharBB
 2171 --  , testProperty "spanChar 1"     prop_spanCharBB
 2172 --  , testProperty "spanChar 2"     prop_spanChar_1BB
 2173 --  , testProperty "breakSpace"     prop_breakSpaceBB
 2174 --  , testProperty "dropSpace"      prop_dropSpaceBB
 2175     , testProperty "spanEnd"        prop_spanEndBB
 2176     , testProperty "breakEnd"       prop_breakEndBB
 2177     , testProperty "breakEnd"       prop_breakEndCC
 2178     , testProperty "elemIndexEnd 1" prop_elemIndexEnd1BB
 2179     , testProperty "elemIndexEnd 1" prop_elemIndexEnd1CC
 2180     , testProperty "elemIndexEnd 2" prop_elemIndexEnd2BB
 2181     , testProperty "elemIndexEnd 1" prop_elemIndexEnd1LL
 2182     , testProperty "elemIndexEnd 2" prop_elemIndexEnd2LL
 2183 --  , testProperty "words'"         prop_wordsBB'
 2184 --  , testProperty "lines'"         prop_linesBB'
 2185 --  , testProperty "dropSpaceEnd"   prop_dropSpaceEndBB
 2186     , testProperty "unfoldr"        prop_unfoldrBB
 2187     , testProperty "prefix"         prop_prefixBB
 2188     , testProperty "prefix"         prop_prefixLL
 2189     , testProperty "suffix"         prop_suffixBB
 2190     , testProperty "suffix"         prop_suffixLL
 2191     , testProperty "stripPrefix"    prop_stripPrefixBB
 2192     , testProperty "stripPrefix"    prop_stripPrefixLL
 2193     , testProperty "stripSuffix"    prop_stripSuffixBB
 2194     , testProperty "stripSuffix"    prop_stripSuffixLL
 2195     , testProperty "copy"           prop_copyBB
 2196     , testProperty "copy"           prop_copyLL
 2197     , testProperty "inits"          prop_initsBB
 2198     , testProperty "tails"          prop_tailsBB
 2199     , testProperty "findSubstrings "prop_findSubstringsBB
 2200     , testProperty "findSubstring "prop_findSubstringBB
 2201     , testProperty "breakSubstring 1"prop_breakSubstringBB
 2202     , testProperty "breakSubstring 2"prop_breakSubstring_findSubstring
 2203     , testProperty "breakSubstring 3"prop_breakSubstring_isInfixOf
 2204 
 2205     , testProperty "replicate1"     prop_replicate1BB
 2206     , testProperty "replicate2"     prop_replicate2BB
 2207     , testProperty "replicate3"     prop_replicate3BB
 2208     , testProperty "readInt"        prop_readintBB
 2209     , testProperty "readInt 2"      prop_readint2BB
 2210     , testProperty "readInteger"    prop_readintegerBB
 2211     , testProperty "readInteger 2"  prop_readinteger2BB
 2212     , testProperty "read"           prop_readLL
 2213     , testProperty "read"           prop_readBB
 2214     , testProperty "Lazy.readInt"   prop_readintLL
 2215     , testProperty "Lazy.readInt"   prop_readintLL
 2216     , testProperty "Lazy.readInteger" prop_readintegerLL
 2217     , testProperty "mconcat 1"      prop_append1LL_monoid
 2218     , testProperty "mconcat 2"      prop_append2LL_monoid
 2219     , testProperty "mconcat 3"      prop_append3LL_monoid
 2220 --  , testProperty "filterChar1"    prop_filterChar1BB
 2221 --  , testProperty "filterChar2"    prop_filterChar2BB
 2222 --  , testProperty "filterChar3"    prop_filterChar3BB
 2223 --  , testProperty "filterNotChar1" prop_filterNotChar1BB
 2224 --  , testProperty "filterNotChar2" prop_filterNotChar2BB
 2225     , testProperty "tail"           prop_tailSBB
 2226     , testProperty "index"          prop_indexBB
 2227     , testProperty "unsafeIndex"    prop_unsafeIndexBB
 2228 --  , testProperty "map'"           prop_mapBB'
 2229     , testProperty "filter"         prop_filterBB
 2230     , testProperty "elem"           prop_elemSBB
 2231     , testProperty "take"           prop_takeSBB
 2232     , testProperty "drop"           prop_dropSBB
 2233     , testProperty "splitAt"        prop_splitAtSBB
 2234     , testProperty "foldl"          prop_foldlBB
 2235     , testProperty "foldr"          prop_foldrBB
 2236     , testProperty "takeWhile "     prop_takeWhileSBB
 2237     , testProperty "dropWhile "     prop_dropWhileSBB
 2238     , testProperty "span "          prop_spanSBB
 2239     , testProperty "break "         prop_breakSBB
 2240     , testProperty "breakspan"      prop_breakspan_1BB
 2241     , testProperty "lines "         prop_linesSBB
 2242     , testProperty "unlines "       prop_unlinesSBB
 2243     , testProperty "words "         prop_wordsSBB
 2244     , testProperty "unwords "       prop_unwordsSBB
 2245     , testProperty "unwords "       prop_unwordsSLC
 2246 --     , testProperty "wordstokens"    prop_wordstokensBB
 2247     , testProperty "splitWith"      prop_splitWithBB
 2248     , testProperty "joinsplit"      prop_joinsplitBB
 2249     , testProperty "intercalate"    prop_intercalatePL
 2250 --     , testProperty "lineIndices"    prop_lineIndices1BB
 2251     , testProperty "count"          prop_countBB
 2252 --  , testProperty "linessplit"     prop_linessplit2BB
 2253     , testProperty "splitsplitWith" prop_splitsplitWithBB
 2254 --  , testProperty "joinjoinpath"   prop_joinjoinpathBB
 2255     , testProperty "zip"            prop_zipBB
 2256     , testProperty "zip"            prop_zipLC
 2257     , testProperty "zip1"           prop_zip1BB
 2258     , testProperty "zipWith"        prop_zipWithBB
 2259     , testProperty "zipWith"        prop_zipWithCC
 2260     , testProperty "zipWith"        prop_zipWithLC
 2261 --  , testProperty "zipWith'"       prop_zipWith'BB
 2262     , testProperty "unzip"          prop_unzipBB
 2263     , testProperty "concatMap"      prop_concatMapBB
 2264 --  , testProperty "join/joinByte"  prop_join_spec
 2265 --  , testProperty "span/spanByte"  prop_span_spec
 2266 --  , testProperty "break/breakByte"prop_break_spec
 2267     ]
 2268 
 2269 
 2270 ------------------------------------------------------------------------
 2271 -- Extra lazy properties
 2272 
 2273 ll_tests =
 2274     [ testProperty "eq 1"               prop_eq1
 2275     , testProperty "eq 2"               prop_eq2
 2276     , testProperty "eq 3"               prop_eq3
 2277     , testProperty "eq refl"            prop_eq_refl
 2278     , testProperty "eq symm"            prop_eq_symm
 2279     , testProperty "compare 1"          prop_compare1
 2280     , testProperty "compare 2"          prop_compare2
 2281     , testProperty "compare 3"          prop_compare3
 2282     , testProperty "compare 4"          prop_compare4
 2283     , testProperty "compare 5"          prop_compare5
 2284     , testProperty "compare 6"          prop_compare6
 2285     , testProperty "compare 7"          prop_compare7
 2286     , testProperty "compare 8"          prop_compare8
 2287     , testProperty "empty 1"            prop_empty1
 2288     , testProperty "empty 2"            prop_empty2
 2289     , testProperty "pack/unpack"        prop_packunpack
 2290     , testProperty "unpack/pack"        prop_unpackpack
 2291     , testProperty "null"               prop_null
 2292     , testProperty "length 1"           prop_length1
 2293     , testProperty "length 2"           prop_length2
 2294     , testProperty "cons 1"             prop_cons1
 2295     , testProperty "cons 2"             prop_cons2
 2296     , testProperty "cons 3"             prop_cons3
 2297     , testProperty "cons 4"             prop_cons4
 2298     , testProperty "snoc"               prop_snoc1
 2299     , testProperty "head/pack"          prop_head
 2300     , testProperty "head/unpack"        prop_head1
 2301     , testProperty "tail/pack"          prop_tail
 2302     , testProperty "tail/unpack"        prop_tail1
 2303     , testProperty "last"               prop_last
 2304     , testProperty "init"               prop_init
 2305     , testProperty "append 1"           prop_append1
 2306     , testProperty "append 2"           prop_append2
 2307     , testProperty "append 3"           prop_append3
 2308     , testProperty "map 1"              prop_map1
 2309     , testProperty "map 2"              prop_map2
 2310     , testProperty "map 3"              prop_map3
 2311     , testProperty "filter 1"           prop_filter1
 2312     , testProperty "filter 2"           prop_filter2
 2313     , testProperty "reverse"            prop_reverse
 2314     , testProperty "reverse1"           prop_reverse1
 2315     , testProperty "reverse2"           prop_reverse2
 2316     --, testProperty "transpose"          prop_transpose
 2317     , testProperty "foldl"              prop_foldl
 2318     , testProperty "foldl/reverse"      prop_foldl_1
 2319     , testProperty "foldr"              prop_foldr
 2320     , testProperty "foldr/id"           prop_foldr_1
 2321     , testProperty "foldl1/foldl"       prop_foldl1_1
 2322     , testProperty "foldl1/head"        prop_foldl1_2
 2323     , testProperty "foldl1/tail"        prop_foldl1_3
 2324     , testProperty "foldr1/foldr"       prop_foldr1_1
 2325     , testProperty "foldr1/last"        prop_foldr1_2
 2326     , testProperty "foldr1/head"        prop_foldr1_3
 2327     , testProperty "concat 1"           prop_concat1
 2328     , testProperty "concat 2"           prop_concat2
 2329     , testProperty "concat/pack"        prop_concat3
 2330     , testProperty "any"                prop_any
 2331     , testProperty "all"                prop_all
 2332     , testProperty "maximum"            prop_maximum
 2333     , testProperty "minimum"            prop_minimum
 2334     , testProperty "replicate 1"        prop_replicate1
 2335     , testProperty "replicate 2"        prop_replicate2
 2336     , testProperty "take"               prop_take1
 2337     , testProperty "drop"               prop_drop1
 2338     , testProperty "splitAt"            prop_drop1
 2339     , testProperty "takeWhile"          prop_takeWhile
 2340     , testProperty "dropWhile"          prop_dropWhile
 2341     , testProperty "break"              prop_break
 2342     , testProperty "span"               prop_span
 2343     , testProperty "splitAt"            prop_splitAt
 2344     , testProperty "break/span"         prop_breakspan
 2345 --  , testProperty "break/breakByte"    prop_breakByte
 2346 --  , testProperty "span/spanByte"      prop_spanByte
 2347     , testProperty "split"              prop_split
 2348     , testProperty "splitWith"          prop_splitWith
 2349     , testProperty "splitWith"          prop_splitWith_D
 2350     , testProperty "splitWith"          prop_splitWith_C
 2351     , testProperty "join.split/id"      prop_joinsplit
 2352 --  , testProperty "join/joinByte"      prop_joinjoinByte
 2353     , testProperty "group"              prop_group
 2354     , testProperty "groupBy"            prop_groupBy
 2355     , testProperty "groupBy"            prop_groupBy_LC
 2356     , testProperty "index"              prop_index
 2357     , testProperty "index"              prop_index_D
 2358     , testProperty "index"              prop_index_C
 2359     , testProperty "elemIndex"          prop_elemIndex
 2360     , testProperty "elemIndices"        prop_elemIndices
 2361     , testProperty "count/elemIndices"  prop_count
 2362     , testProperty "findIndex"          prop_findIndex
 2363     , testProperty "findIndices"        prop_findIndicies
 2364     , testProperty "find"               prop_find
 2365     , testProperty "find/findIndex"     prop_find_findIndex
 2366     , testProperty "elem"               prop_elem
 2367     , testProperty "notElem"            prop_notElem
 2368     , testProperty "elem/notElem"       prop_elem_notelem
 2369 --  , testProperty "filterByte 1"       prop_filterByte
 2370 --  , testProperty "filterByte 2"       prop_filterByte2
 2371 --  , testProperty "filterNotByte 1"    prop_filterNotByte
 2372 --  , testProperty "filterNotByte 2"    prop_filterNotByte2
 2373     , testProperty "isPrefixOf"         prop_isPrefixOf
 2374     , testProperty "isSuffixOf"         prop_isSuffixOf
 2375     , testProperty "stripPrefix"        prop_stripPrefix
 2376     , testProperty "stripSuffix"        prop_stripSuffix
 2377     , testProperty "concatMap"          prop_concatMap
 2378     , testProperty "isSpace"            prop_isSpaceWord8
 2379     ]
 2380 
 2381