Commit 16dcc766 authored by Bodigrim's avatar Bodigrim
Browse files

Use applyFun instead of blind instance Show (a -> b)

parent aafec726
-- | Test basic text functions
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Tests.Properties.Basics
( testBasics
......@@ -7,9 +9,8 @@ module Tests.Properties.Basics
import Control.Arrow (first, second)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Test.Tasty.QuickCheck (testProperty, applyFun)
import Tests.QuickCheckUtils
import Text.Show.Functions ()
import qualified Data.List as L
import qualified Data.Text as T
import qualified Data.Text.Internal.Fusion as S
......@@ -19,7 +20,8 @@ import qualified Data.Text.Lazy as TL
s_cons x = (x:) `eqP` (unpackS . S.cons x)
s_cons_s x = (x:) `eqP` (unpackS . S.unstream . S.cons x)
sf_cons p x = ((x:) . L.filter p) `eqP` (unpackS . S.cons x . S.filter p)
sf_cons (applyFun -> p) x
= ((x:) . L.filter p) `eqP` (unpackS . S.cons x . S.filter p)
t_cons x = (x:) `eqP` (unpackS . T.cons x)
tl_cons x = (x:) `eqP` (unpackS . TL.cons x)
t_length_cons x = (L.length . (x:)) `eqP` (T.length . T.cons x)
......@@ -34,7 +36,8 @@ tl_length_snoc x = (L.genericLength . (++ [x])) `eqP` (TL.length . flip TL.snoc
s_append s = (s++) `eqP` (unpackS . S.append (S.streamList s))
s_append_s s = (s++) `eqP`
(unpackS . S.unstream . S.append (S.streamList s))
sf_append p s = (L.filter p s++) `eqP`
sf_append (applyFun -> p) s
= (L.filter p s++) `eqP`
(unpackS . S.append (S.filter p $ S.streamList s))
t_append s = (s++) `eqP` (unpackS . T.append (packS s))
......@@ -42,7 +45,8 @@ uncons (x:xs) = Just (x,xs)
uncons _ = Nothing
s_uncons = uncons `eqP` (fmap (second unpackS) . S.uncons)
sf_uncons p = (uncons . L.filter p) `eqP`
sf_uncons (applyFun -> p)
= (uncons . L.filter p) `eqP`
(fmap (second unpackS) . S.uncons . S.filter p)
t_uncons = uncons `eqP` (fmap (second unpackS) . T.uncons)
tl_uncons = uncons `eqP` (fmap (second unpackS) . TL.uncons)
......@@ -54,29 +58,29 @@ t_unsnoc = unsnoc `eqP` (fmap (first unpackS) . T.unsnoc)
tl_unsnoc = unsnoc `eqP` (fmap (first unpackS) . TL.unsnoc)
s_head = head `eqP` S.head
sf_head p = (head . L.filter p) `eqP` (S.head . S.filter p)
sf_head (applyFun -> p) = (head . L.filter p) `eqP` (S.head . S.filter p)
t_head = head `eqP` T.head
tl_head = head `eqP` TL.head
s_last = last `eqP` S.last
sf_last p = (last . L.filter p) `eqP` (S.last . S.filter p)
sf_last (applyFun -> p) = (last . L.filter p) `eqP` (S.last . S.filter p)
t_last = last `eqP` T.last
tl_last = last `eqP` TL.last
s_tail = tail `eqP` (unpackS . S.tail)
s_tail_s = tail `eqP` (unpackS . S.unstream . S.tail)
sf_tail p = (tail . L.filter p) `eqP` (unpackS . S.tail . S.filter p)
sf_tail (applyFun -> p) = (tail . L.filter p) `eqP` (unpackS . S.tail . S.filter p)
t_tail = tail `eqP` (unpackS . T.tail)
tl_tail = tail `eqP` (unpackS . TL.tail)
s_init = init `eqP` (unpackS . S.init)
s_init_s = init `eqP` (unpackS . S.unstream . S.init)
sf_init p = (init . L.filter p) `eqP` (unpackS . S.init . S.filter p)
sf_init (applyFun -> p) = (init . L.filter p) `eqP` (unpackS . S.init . S.filter p)
t_init = init `eqP` (unpackS . T.init)
tl_init = init `eqP` (unpackS . TL.init)
s_null = null `eqP` S.null
sf_null p = (null . L.filter p) `eqP` (S.null . S.filter p)
sf_null (applyFun -> p) = (null . L.filter p) `eqP` (S.null . S.filter p)
t_null = null `eqP` T.null
tl_null = null `eqP` TL.null
s_length = length `eqP` S.length
sf_length p = (length . L.filter p) `eqP` (S.length . S.filter p)
sf_length (applyFun -> p) = (length . L.filter p) `eqP` (S.length . S.filter p)
sl_length = (fromIntegral . length) `eqP` SL.length
t_length = length `eqP` T.length
tl_length = L.genericLength `eqP` TL.length
......
......@@ -14,7 +14,6 @@ import Test.QuickCheck
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Tests.QuickCheckUtils
import Text.Show.Functions ()
import qualified Data.List as L
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Builder as TB
......
-- | Test folds, scans, and unfolds
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Tests.Properties.Folds
( testFolds
......@@ -8,9 +10,8 @@ module Tests.Properties.Folds
import Control.Arrow (second)
import Data.Word (Word8, Word16)
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty, Small(..), (===))
import Test.Tasty.QuickCheck (testProperty, Small(..), (===), applyFun, applyFun2)
import Tests.QuickCheckUtils
import Text.Show.Functions ()
import qualified Data.List as L
import qualified Data.Text as T
import qualified Data.Text.Internal.Fusion as S
......@@ -19,79 +20,95 @@ import qualified Data.Text.Lazy as TL
-- Folds
sf_foldl p f z = (L.foldl f z . L.filter p) `eqP` (S.foldl f z . S.filter p)
sf_foldl (applyFun -> p) (applyFun2 -> f) z =
(L.foldl f z . L.filter p) `eqP` (S.foldl f z . S.filter p)
where _types = f :: Char -> Char -> Char
t_foldl f z = L.foldl f z `eqP` (T.foldl f z)
t_foldl (applyFun2 -> f) z = L.foldl f z `eqP` (T.foldl f z)
where _types = f :: Char -> Char -> Char
tl_foldl f z = L.foldl f z `eqP` (TL.foldl f z)
tl_foldl (applyFun2 -> f) z = L.foldl f z `eqP` (TL.foldl f z)
where _types = f :: Char -> Char -> Char
sf_foldl' p f z = (L.foldl' f z . L.filter p) `eqP`
(S.foldl' f z . S.filter p)
sf_foldl' (applyFun -> p) (applyFun2 -> f) z =
(L.foldl' f z . L.filter p) `eqP` (S.foldl' f z . S.filter p)
where _types = f :: Char -> Char -> Char
t_foldl' f z = L.foldl' f z `eqP` T.foldl' f z
t_foldl' (applyFun2 -> f) z = L.foldl' f z `eqP` T.foldl' f z
where _types = f :: Char -> Char -> Char
tl_foldl' f z = L.foldl' f z `eqP` TL.foldl' f z
tl_foldl' (applyFun2 -> f) z = L.foldl' f z `eqP` TL.foldl' f z
where _types = f :: Char -> Char -> Char
sf_foldl1 p f = (L.foldl1 f . L.filter p) `eqP` (S.foldl1 f . S.filter p)
t_foldl1 f = L.foldl1 f `eqP` T.foldl1 f
tl_foldl1 f = L.foldl1 f `eqP` TL.foldl1 f
sf_foldl1' p f = (L.foldl1' f . L.filter p) `eqP` (S.foldl1' f . S.filter p)
t_foldl1' f = L.foldl1' f `eqP` T.foldl1' f
tl_foldl1' f = L.foldl1' f `eqP` TL.foldl1' f
sf_foldr p f z = (L.foldr f z . L.filter p) `eqP` (S.foldr f z . S.filter p)
sf_foldl1 (applyFun -> p) (applyFun2 -> f) =
(L.foldl1 f . L.filter p) `eqP` (S.foldl1 f . S.filter p)
t_foldl1 (applyFun2 -> f) = L.foldl1 f `eqP` T.foldl1 f
tl_foldl1 (applyFun2 -> f) = L.foldl1 f `eqP` TL.foldl1 f
sf_foldl1' (applyFun -> p) (applyFun2 -> f) =
(L.foldl1' f . L.filter p) `eqP` (S.foldl1' f . S.filter p)
t_foldl1' (applyFun2 -> f) = L.foldl1' f `eqP` T.foldl1' f
tl_foldl1' (applyFun2 -> f) = L.foldl1' f `eqP` TL.foldl1' f
sf_foldr (applyFun -> p) (applyFun2 -> f) z =
(L.foldr f z . L.filter p) `eqP` (S.foldr f z . S.filter p)
where _types = f :: Char -> Char -> Char
t_foldr f z = L.foldr f z `eqP` T.foldr f z
t_foldr (applyFun2 -> f) z = L.foldr f z `eqP` T.foldr f z
where _types = f :: Char -> Char -> Char
tl_foldr f z = L.foldr f z `eqPSqrt` TL.foldr f z
tl_foldr (applyFun2 -> f) z = L.foldr f z `eqPSqrt` TL.foldr f z
where _types = f :: Char -> Char -> Char
sf_foldr1 p f = (L.foldr1 f . L.filter p) `eqPSqrt` (S.foldr1 f . S.filter p)
t_foldr1 f = L.foldr1 f `eqP` T.foldr1 f
tl_foldr1 f = L.foldr1 f `eqPSqrt` TL.foldr1 f
sf_foldr1 (applyFun -> p) (applyFun2 -> f) =
(L.foldr1 f . L.filter p) `eqPSqrt` (S.foldr1 f . S.filter p)
t_foldr1 (applyFun2 -> f) = L.foldr1 f `eqP` T.foldr1 f
tl_foldr1 (applyFun2 -> f) = L.foldr1 f `eqPSqrt` TL.foldr1 f
-- Special folds
s_concat_s = (L.concat . unSqrt) `eq` (unpackS . S.unstream . S.concat . map packS . unSqrt)
sf_concat p = (L.concat . map (L.filter p) . unSqrt) `eq`
sf_concat (applyFun -> p)
= (L.concat . map (L.filter p) . unSqrt) `eq`
(unpackS . S.concat . map (S.filter p . packS) . unSqrt)
t_concat = (L.concat . unSqrt) `eq` (unpackS . T.concat . map packS . unSqrt)
tl_concat = (L.concat . unSqrt) `eq` (unpackS . TL.concat . map TL.pack . unSqrt)
sf_concatMap p f = (L.concatMap f . L.filter p) `eqPSqrt`
(unpackS . S.concatMap (packS . f) . S.filter p)
t_concatMap f = L.concatMap f `eqPSqrt` (unpackS . T.concatMap (packS . f))
tl_concatMap f = L.concatMap f `eqPSqrt` (unpackS . TL.concatMap (TL.pack . f))
sf_any q p = (L.any p . L.filter q) `eqP` (S.any p . S.filter q)
t_any p = L.any p `eqP` T.any p
tl_any p = L.any p `eqP` TL.any p
sf_all q p = (L.all p . L.filter q) `eqP` (S.all p . S.filter q)
t_all p = L.all p `eqP` T.all p
tl_all p = L.all p `eqP` TL.all p
sf_maximum p = (L.maximum . L.filter p) `eqP` (S.maximum . S.filter p)
sf_concatMap (applyFun -> p) (applyFun -> f) =
(L.concatMap f . L.filter p) `eqPSqrt` (unpackS . S.concatMap (packS . f) . S.filter p)
t_concatMap (applyFun -> f)
= L.concatMap f `eqPSqrt` (unpackS . T.concatMap (packS . f))
tl_concatMap (applyFun -> f)
= L.concatMap f `eqPSqrt` (unpackS . TL.concatMap (TL.pack . f))
sf_any (applyFun -> q) (applyFun -> p)
= (L.any p . L.filter q) `eqP` (S.any p . S.filter q)
t_any (applyFun -> p)
= L.any p `eqP` T.any p
tl_any (applyFun -> p)
= L.any p `eqP` TL.any p
sf_all (applyFun -> q) (applyFun -> p)
= (L.all p . L.filter q) `eqP` (S.all p . S.filter q)
t_all (applyFun -> p)
= L.all p `eqP` T.all p
tl_all (applyFun -> p)
= L.all p `eqP` TL.all p
sf_maximum (applyFun -> p)
= (L.maximum . L.filter p) `eqP` (S.maximum . S.filter p)
t_maximum = L.maximum `eqP` T.maximum
tl_maximum = L.maximum `eqP` TL.maximum
sf_minimum p = (L.minimum . L.filter p) `eqP` (S.minimum . S.filter p)
sf_minimum (applyFun -> p)
= (L.minimum . L.filter p) `eqP` (S.minimum . S.filter p)
t_minimum = L.minimum `eqP` T.minimum
tl_minimum = L.minimum `eqP` TL.minimum
-- Scans
sf_scanl p f z = (L.scanl f z . L.filter p) `eqP`
(unpackS . S.scanl f z . S.filter p)
t_scanl f z = L.scanl f z `eqP` (unpackS . T.scanl f z)
tl_scanl f z = L.scanl f z `eqP` (unpackS . TL.scanl f z)
t_scanl1 f = L.scanl1 f `eqP` (unpackS . T.scanl1 f)
tl_scanl1 f = L.scanl1 f `eqP` (unpackS . TL.scanl1 f)
t_scanr f z = L.scanr f z `eqP` (unpackS . T.scanr f z)
tl_scanr f z = L.scanr f z `eqP` (unpackS . TL.scanr f z)
t_scanr1 f = L.scanr1 f `eqP` (unpackS . T.scanr1 f)
tl_scanr1 f = L.scanr1 f `eqP` (unpackS . TL.scanr1 f)
t_mapAccumL f z = L.mapAccumL f z `eqP` (second unpackS . T.mapAccumL f z)
sf_scanl (applyFun -> p) (applyFun2 -> f) z =
(L.scanl f z . L.filter p) `eqP` (unpackS . S.scanl f z . S.filter p)
t_scanl (applyFun2 -> f) z = L.scanl f z `eqP` (unpackS . T.scanl f z)
tl_scanl (applyFun2 -> f) z = L.scanl f z `eqP` (unpackS . TL.scanl f z)
t_scanl1 (applyFun2 -> f) = L.scanl1 f `eqP` (unpackS . T.scanl1 f)
tl_scanl1 (applyFun2 -> f) = L.scanl1 f `eqP` (unpackS . TL.scanl1 f)
t_scanr (applyFun2 -> f) z = L.scanr f z `eqP` (unpackS . T.scanr f z)
tl_scanr (applyFun2 -> f) z = L.scanr f z `eqP` (unpackS . TL.scanr f z)
t_scanr1 (applyFun2 -> f) = L.scanr1 f `eqP` (unpackS . T.scanr1 f)
tl_scanr1 (applyFun2 -> f) = L.scanr1 f `eqP` (unpackS . TL.scanr1 f)
t_mapAccumL (applyFun2 -> f) z = L.mapAccumL f z `eqP` (second unpackS . T.mapAccumL f z)
where _types = f :: Int -> Char -> (Int,Char)
tl_mapAccumL f z = L.mapAccumL f z `eqP` (second unpackS . TL.mapAccumL f z)
tl_mapAccumL (applyFun2 -> f) z = L.mapAccumL f z `eqP` (second unpackS . TL.mapAccumL f z)
where _types = f :: Int -> Char -> (Int,Char)
t_mapAccumR f z = L.mapAccumR f z `eqP` (second unpackS . T.mapAccumR f z)
t_mapAccumR (applyFun2 -> f) z = L.mapAccumR f z `eqP` (second unpackS . T.mapAccumR f z)
where _types = f :: Int -> Char -> (Int,Char)
tl_mapAccumR f z = L.mapAccumR f z `eqP` (second unpackS . TL.mapAccumR f z)
tl_mapAccumR (applyFun2 -> f) z = L.mapAccumR f z `eqP` (second unpackS . TL.mapAccumR f z)
where _types = f :: Int -> Char -> (Int,Char)
-- Unfolds
......@@ -122,7 +139,8 @@ tl_cycle n = (L.take m . L.cycle) `eq`
(unpackS . TL.take (fromIntegral m) . TL.cycle . packS)
where m = fromIntegral (n :: Word8)
tl_iterate f n = (L.take m . L.iterate f) `eq`
tl_iterate (applyFun -> f) n
= (L.take m . L.iterate f) `eq`
(unpackS . TL.take (fromIntegral m) . TL.iterate f)
where m = fromIntegral (n :: Word8)
......
-- | Test instances
{-# LANGUAGE CPP #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Tests.Properties.Instances
( testInstances
......@@ -11,7 +11,6 @@ import Test.QuickCheck
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Tests.QuickCheckUtils
import Text.Show.Functions ()
import qualified Data.List as L
import qualified Data.Text as T
import qualified Data.Text.Internal.Fusion.Common as S
......@@ -19,14 +18,14 @@ import qualified Data.Text.Lazy as TL
s_Eq s = (s==) `eq` ((S.streamList s==) . S.streamList)
where _types = s :: String
sf_Eq p s =
sf_Eq (applyFun -> p) s =
((L.filter p s==) . L.filter p) `eq`
(((S.filter p $ S.streamList s)==) . S.filter p . S.streamList)
t_Eq s = (s==) `eq` ((T.pack s==) . T.pack)
tl_Eq s = (s==) `eq` ((TL.pack s==) . TL.pack)
s_Ord s = (compare s) `eq` (compare (S.streamList s) . S.streamList)
where _types = s :: String
sf_Ord p s =
sf_Ord (applyFun -> p) s =
((compare $ L.filter p s) . L.filter p) `eq`
(compare (S.filter p $ S.streamList s) . S.filter p . S.streamList)
t_Ord s = (compare s) `eq` (compare (T.pack s) . T.pack)
......
......@@ -12,7 +12,6 @@ import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Test.QuickCheck
import Tests.QuickCheckUtils ()
import Text.Show.Functions ()
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import qualified Data.Text.Lazy.Read as TL
......
-- | Tests for substring functions (@take@, @split@, @isInfixOf@, etc.)
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Tests.Properties.Substrings
( testSubstrings
......@@ -10,7 +12,6 @@ import Test.QuickCheck
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Tests.QuickCheckUtils
import Text.Show.Functions ()
import qualified Data.List as L
import qualified Data.Text as T
import qualified Data.Text.Internal.Fusion as S
......@@ -22,7 +23,8 @@ import qualified Tests.SlowFunctions as Slow
s_take n = L.take n `eqP` (unpackS . S.take n)
s_take_s m = L.take n `eqP` (unpackS . S.unstream . S.take n)
where n = small m
sf_take p n = (L.take n . L.filter p) `eqP`
sf_take (applyFun -> p) n
= (L.take n . L.filter p) `eqP`
(unpackS . S.take n . S.filter p)
t_take n = L.take n `eqP` (unpackS . T.take n)
t_takeEnd n = (L.reverse . L.take n . L.reverse) `eqP`
......@@ -33,8 +35,8 @@ tl_takeEnd n = (L.reverse . L.take (fromIntegral n) . L.reverse) `eqP`
s_drop n = L.drop n `eqP` (unpackS . S.drop n)
s_drop_s m = L.drop n `eqP` (unpackS . S.unstream . S.drop n)
where n = small m
sf_drop p n = (L.drop n . L.filter p) `eqP`
(unpackS . S.drop n . S.filter p)
sf_drop (applyFun -> p) n
= (L.drop n . L.filter p) `eqP` (unpackS . S.drop n . S.filter p)
t_drop n = L.drop n `eqP` (unpackS . T.drop n)
t_dropEnd n = (L.reverse . L.drop n . L.reverse) `eqP`
(unpackS . T.dropEnd n)
......@@ -46,10 +48,12 @@ s_take_drop m = (L.take n . L.drop n) `eqP` (unpackS . S.take n . S.drop n)
s_take_drop_s m = (L.take n . L.drop n) `eqP`
(unpackS . S.unstream . S.take n . S.drop n)
where n = small m
s_takeWhile p = L.takeWhile p `eqP` (unpackS . S.takeWhile p)
s_takeWhile_s p = L.takeWhile p `eqP` (unpackS . S.unstream . S.takeWhile p)
sf_takeWhile q p = (L.takeWhile p . L.filter q) `eqP`
(unpackS . S.takeWhile p . S.filter q)
s_takeWhile (applyFun -> p)
= L.takeWhile p `eqP` (unpackS . S.takeWhile p)
s_takeWhile_s (applyFun -> p)
= L.takeWhile p `eqP` (unpackS . S.unstream . S.takeWhile p)
sf_takeWhile (applyFun -> q) (applyFun -> p)
= (L.takeWhile p . L.filter q) `eqP` (unpackS . S.takeWhile p . S.filter q)
data NoMatch = NoMatch Char Char
deriving (Eq, Show)
......@@ -62,29 +66,42 @@ instance Arbitrary NoMatch where
shrink (NoMatch c d) = fmap (NoMatch c) (filter (/= c) (shrink d))
++ fmap (`NoMatch` d) (filter (/= d) (shrink c))
t_takeWhile p = L.takeWhile p `eqP` (unpackS . T.takeWhile p)
tl_takeWhile p = L.takeWhile p `eqP` (unpackS . TL.takeWhile p)
t_takeWhileEnd p = (L.reverse . L.takeWhile p . L.reverse) `eqP`
t_takeWhile (applyFun -> p)
= L.takeWhile p `eqP` (unpackS . T.takeWhile p)
tl_takeWhile (applyFun -> p)
= L.takeWhile p `eqP` (unpackS . TL.takeWhile p)
t_takeWhileEnd (applyFun -> p)
= (L.reverse . L.takeWhile p . L.reverse) `eqP`
(unpackS . T.takeWhileEnd p)
t_takeWhileEnd_null t (NoMatch c d) = T.null $
T.takeWhileEnd (==d) (T.snoc t c)
tl_takeWhileEnd p = (L.reverse . L.takeWhile p . L.reverse) `eqP`
t_takeWhileEnd_null t (NoMatch c d)
= T.null $ T.takeWhileEnd (==d) (T.snoc t c)
tl_takeWhileEnd (applyFun -> p)
= (L.reverse . L.takeWhile p . L.reverse) `eqP`
(unpackS . TL.takeWhileEnd p)
tl_takeWhileEnd_null t (NoMatch c d) = TL.null $
TL.takeWhileEnd (==d) (TL.snoc t c)
s_dropWhile p = L.dropWhile p `eqP` (unpackS . S.dropWhile p)
s_dropWhile_s p = L.dropWhile p `eqP` (unpackS . S.unstream . S.dropWhile p)
sf_dropWhile q p = (L.dropWhile p . L.filter q) `eqP`
tl_takeWhileEnd_null t (NoMatch c d)
= TL.null $ TL.takeWhileEnd (==d) (TL.snoc t c)
s_dropWhile (applyFun -> p)
= L.dropWhile p `eqP` (unpackS . S.dropWhile p)
s_dropWhile_s (applyFun -> p)
= L.dropWhile p `eqP` (unpackS . S.unstream . S.dropWhile p)
sf_dropWhile (applyFun -> q) (applyFun -> p)
= (L.dropWhile p . L.filter q) `eqP`
(unpackS . S.dropWhile p . S.filter q)
t_dropWhile p = L.dropWhile p `eqP` (unpackS . T.dropWhile p)
tl_dropWhile p = L.dropWhile p `eqP` (unpackS . S.dropWhile p)
t_dropWhileEnd p = (L.reverse . L.dropWhile p . L.reverse) `eqP`
t_dropWhile (applyFun -> p)
= L.dropWhile p `eqP` (unpackS . T.dropWhile p)
tl_dropWhile (applyFun -> p)
= L.dropWhile p `eqP` (unpackS . S.dropWhile p)
t_dropWhileEnd (applyFun -> p)
= (L.reverse . L.dropWhile p . L.reverse) `eqP`
(unpackS . T.dropWhileEnd p)
tl_dropWhileEnd p = (L.reverse . L.dropWhile p . L.reverse) `eqP`
tl_dropWhileEnd (applyFun -> p)
= (L.reverse . L.dropWhile p . L.reverse) `eqP`
(unpackS . TL.dropWhileEnd p)
t_dropAround p = (L.dropWhile p . L.reverse . L.dropWhile p . L.reverse)
t_dropAround (applyFun -> p)
= (L.dropWhile p . L.reverse . L.dropWhile p . L.reverse)
`eqP` (unpackS . T.dropAround p)
tl_dropAround p = (L.dropWhile p . L.reverse . L.dropWhile p . L.reverse)
tl_dropAround (applyFun -> p)
= (L.dropWhile p . L.reverse . L.dropWhile p . L.reverse)
`eqP` (unpackS . TL.dropAround p)
t_stripStart = T.dropWhile isSpace `eq` T.stripStart
tl_stripStart = TL.dropWhile isSpace `eq` TL.stripStart
......@@ -94,8 +111,8 @@ t_strip = T.dropAround isSpace `eq` T.strip
tl_strip = TL.dropAround isSpace `eq` TL.strip
t_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)
tl_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt (fromIntegral n))
t_span p = L.span p `eqP` (unpack2 . T.span p)
tl_span p = L.span p `eqP` (unpack2 . TL.span p)
t_span (applyFun -> p) = L.span p `eqP` (unpack2 . T.span p)
tl_span (applyFun -> p) = L.span p `eqP` (unpack2 . TL.span p)
t_breakOn_id s = squid `eq` (uncurry T.append . T.breakOn s)
where squid t | T.null s = error "empty"
......@@ -115,12 +132,16 @@ t_breakOnEnd_end (NotEmpty s) t =
tl_breakOnEnd_end (NotEmpty s) t =
let (m,k) = TL.breakOnEnd s t
in k `TL.isSuffixOf` t && (TL.null m || s `TL.isSuffixOf` m)
t_break p = L.break p `eqP` (unpack2 . T.break p)
tl_break p = L.break p `eqP` (unpack2 . TL.break p)
t_break (applyFun -> p)
= L.break p `eqP` (unpack2 . T.break p)
tl_break (applyFun -> p)
= L.break p `eqP` (unpack2 . TL.break p)
t_group = L.group `eqP` (map unpackS . T.group)
tl_group = L.group `eqP` (map unpackS . TL.group)
t_groupBy p = L.groupBy p `eqP` (map unpackS . T.groupBy p)
tl_groupBy p = L.groupBy p `eqP` (map unpackS . TL.groupBy p)
t_groupBy (applyFun2 -> p)
= L.groupBy p `eqP` (map unpackS . T.groupBy p)
tl_groupBy (applyFun2 -> p)
= L.groupBy p `eqP` (map unpackS . TL.groupBy p)
t_inits = L.inits `eqP` (map unpackS . T.inits)
tl_inits = L.inits `eqP` (map unpackS . TL.inits)
t_tails = L.tails `eqP` (map unpackS . T.tails)
......@@ -145,11 +166,11 @@ tl_splitOn_split s = ((TL.splitOn (TL.fromStrict s) . TL.fromStrict) `eq`
t_splitOn_i (NotEmpty t) = id `eq` (T.intercalate t . T.splitOn t)
tl_splitOn_i (NotEmpty t) = id `eq` (TL.intercalate t . TL.splitOn t)
t_split p = split p `eqP` (map unpackS . T.split p)
t_split (applyFun -> p) = split p `eqP` (map unpackS . T.split p)
t_split_count c = (L.length . T.split (==c)) `eq`
((1+) . T.count (T.singleton c))
t_split_splitOn c = T.split (==c) `eq` T.splitOn (T.singleton c)
tl_split p = split p `eqP` (map unpackS . TL.split p)
tl_split (applyFun -> p) = split p `eqP` (map unpackS . TL.split p)
split :: (a -> Bool) -> [a] -> [[a]]
split _ [] = [[]]
......@@ -185,7 +206,8 @@ tl_unwords = (L.unwords . unSqrt) `eq` (unpackS . TL.unwords . map packS
s_isPrefixOf s = L.isPrefixOf s `eqP`
(S.isPrefixOf (S.stream $ packS s) . S.stream)
sf_isPrefixOf p s = (L.isPrefixOf s . L.filter p) `eqP`
sf_isPrefixOf (applyFun -> p) s
= (L.isPrefixOf s . L.filter p) `eqP`
(S.isPrefixOf (S.stream $ packS s) . S.filter p . S.stream)
t_isPrefixOf s = L.isPrefixOf s`eqP` T.isPrefixOf (packS s)
tl_isPrefixOf s = L.isPrefixOf s`eqP` TL.isPrefixOf (packS s)
......
-- | Tests for operations that don't fit in the other @Test.Properties.*@ modules.
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ViewPatterns #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
module Tests.Properties.Text
( testText
......@@ -14,7 +15,6 @@ import Test.QuickCheck
import Test.Tasty (TestTree, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Tests.QuickCheckUtils
import Text.Show.Functions ()
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Text as T
......@@ -38,16 +38,16 @@ tl_unstreamChunks x = f 11 x === f 1000 x
tl_chunk_unchunk = (TL.fromChunks . TL.toChunks) `eq` id
tl_from_to_strict = (TL.fromStrict . TL.toStrict) `eq` id
s_map f = map f `eqP` (unpackS . S.map f)
s_map_s f = map f `eqP` (unpackS . S.unstream . S.map f)
sf_map p f = (map f . L.filter p) `eqP` (unpackS . S.map f . S.filter p)
s_map (applyFun -> f) = map f `eqP` (unpackS . S.map f)
s_map_s (applyFun -> f) = map f `eqP` (unpackS . S.unstream . S.map f)
sf_map (applyFun -> p) (applyFun -> f) = (map f . L.filter p) `eqP` (unpackS . S.map f . S.filter p)
t_map f = map f `eqP` (unpackS . T.map f)
tl_map f = map f `eqP` (unpackS . TL.map f)
t_map_map f g = (map f . map g) `eqP` (unpackS . T.map f . T.map g)
tl_map_map f g = (map f . map g) `eqP` (unpackS . TL.map f . TL.map g)
t_length_map f = (L.length . map f) `eqP` (T.length . T.map f)
tl_length_map f = (L.genericLength . map f) `eqP` (TL.length . TL.map f)
t_map (applyFun -> f) = map f `eqP` (unpackS . T.map f)
tl_map (applyFun -> f) = map f `eqP` (unpackS . TL.map f)
t_map_map (applyFun -> f) (applyFun -> g) = (map f . map g) `eqP` (unpackS . T.map f . T.map g)
tl_map_map (applyFun -> f) (applyFun -> g) = (map f . map g) `eqP` (unpackS . TL.map f . TL.map g)
t_length_map (applyFun -> f) = (L.length . map f) `eqP` (T.length . T.map f)
tl_length_map (applyFun -> f) = (L.genericLength . map f) `eqP` (TL.length . TL.map f)
s_intercalate c = (L.intercalate c . unSqrt) `eq`
(unpackS . S.intercalate (packS c) . map packS . unSqrt)
......@@ -63,7 +63,8 @@ s_intersperse c = L.intersperse c `eqP`
(unpackS . S.intersperse c)
s_intersperse_s c = L.intersperse c `eqP`
(unpackS . S.unstream . S.intersperse c)
sf_intersperse p c= (L.intersperse c . L.filter p) `eqP`
sf_intersperse (applyFun -> p) c
= (L.intersperse c . L.filter p) `eqP`
(unpackS . S.intersperse c . S.filter p)
t_intersperse c = L.intersperse c `eqPSqrt` (unpackS . T.intersperse c)
tl_intersperse c = L.intersperse c `eqPSqrt` (unpackS . TL.intersperse c)
......@@ -95,7 +96,7 @@ splitOn pat src0
s_toCaseFold_length xs = S.length (S.toCaseFold s) >= length xs
where s = S.streamList xs
sf_toCaseFold_length p xs =
sf_toCaseFold_length (applyFun -> p) xs =
(S.length . S.toCaseFold . S.filter p $ s) >= (length . L.filter p $ xs)
where s = S.streamList xs
t_toCaseFold_length t = T.length (T.toCaseFold t) >= T.length t
......@@ -142,7 +143,8 @@ s_justifyLeft k c = justifyLeft j c `eqP` (unpackS . S.justifyLeftI j c)
s_justifyLeft_s k c = justifyLeft j c `eqP`
(unpackS . S.unstream . S.justifyLeftI j c)
where j = fromIntegral (k :: Word8)
sf_justifyLeft p k c = (justifyLeft j c . L.filter p) `eqP`
sf_justifyLeft (applyFun -> p) k c
= (justifyLeft j c . L.filter p) `eqP`