@@ -52,18 +52,22 @@ prop_T_utf32BE = (E.decodeUtf32BE . E.encodeUtf32BE) `eq` id
53class Target t where
53class Target t where
54 packT :: String -> t
54 packT :: String -> t
55+ unpackT :: t -> String
55 splitAtT :: Int -> t -> (t,t)
56 splitAtT :: Int -> t -> (t,t)
57instance Target (S.Stream Char) where
58instance Target (S.Stream Char) where
58 packT = S.streamList
59 packT = S.streamList
60+ unpackT = S.unstreamList
59 splitAtT n s = (S.take n s, S.drop n s)
61 splitAtT n s = (S.take n s, S.drop n s)
61instance Target T.Text where
63instance Target T.Text where
62 packT = T.pack
64 packT = T.pack
63 splitAtT = T.splitAt
66 splitAtT = T.splitAt
65instance Target TL.Text where
68instance Target TL.Text where
66 packT = TL.pack
69 packT = TL.pack
67 splitAtT = TL.splitAt
71 splitAtT = TL.splitAt
69-- Do two functions give the same answer?
73-- Do two functions give the same answer?
@@ -101,31 +105,33 @@ eqEP a b e w = a s == b t &&
101 n = fromIntegral w
105 n = fromIntegral w
102 s = notEmpty e
106 s = notEmpty e
104−prop_S_cons x = (x:) `eqP` (S.unstreamList . S.cons x)
108+prop_S_cons x = (x:) `eqP` (unpackT . S.cons x)
105−prop_T_cons x = (x:) `eqP` (T.unpack . T.cons x)
109+prop_T_cons x = (x:) `eqP` (unpackT . T.cons x)
106prop_TL_cons x = ((x:) `eqP` (TL.unpack . TL.cons x))
110prop_TL_cons x = ((x:) `eqP` (TL.unpack . TL.cons x))
111+prop_S_snoc x = (++ [x]) `eqP` (unpackT . (flip S.snoc) x)
107−prop_T_snoc x = (++ [x]) `eqP` (T.unpack . (flip T.snoc) x)
112+prop_T_snoc x = (++ [x]) `eqP` (unpackT . (flip T.snoc) x)
113+prop_TL_snoc x = (++ [x]) `eqP` (unpackT . (flip TL.snoc) x)
108−prop_T_append s = (s++) `eqP` (T.unpack . T.append (T.pack s))
114+prop_T_append s = (s++) `eqP` (unpackT . T.append (T.pack s))
109−prop_T_appendS s = (s++) `eqP` (T.unpack . S.unstream . S.append (S.stream (T.pack s)) . S.stream)
115+prop_T_appendS s = (s++) `eqP` (unpackT . S.unstream . S.append (S.stream (T.pack s)) . S.stream)
110−prop_T_uncons s = uncons `eqP` (fmap (second T.unpack) . T.uncons)
116+prop_T_uncons s = uncons `eqP` (fmap (second unpackT) . T.uncons)
111 where uncons (x:xs) = Just (x,xs)
117 where uncons (x:xs) = Just (x,xs)
112 uncons _ = Nothing
118 uncons _ = Nothing
113 types = s :: String
119 types = s :: String
114prop_T_head = head `eqEP` T.head
120prop_T_head = head `eqEP` T.head
115prop_T_last = last `eqEP` T.last
121prop_T_last = last `eqEP` T.last
116prop_T_lastS = last `eqEP` (S.last . S.stream)
122prop_T_lastS = last `eqEP` (S.last . S.stream)
117−prop_T_tail = tail `eqEP` (T.unpack . T.tail)
123+prop_T_tail = tail `eqEP` (unpackT . T.tail)
118−prop_T_tailS = tail `eqEP` (T.unpack . S.unstream . S.tail . S.stream)
124+prop_T_tailS = tail `eqEP` (unpackT . S.unstream . S.tail . S.stream)
119−prop_T_init = init `eqEP` (T.unpack . T.init)
125+prop_T_init = init `eqEP` (unpackT . T.init)
120−prop_T_initS = init `eqEP` (T.unpack . S.unstream . S.init . S.stream)
126+prop_T_initS = init `eqEP` (unpackT . S.unstream . S.init . S.stream)
121prop_T_null = null `eqP` T.null
127prop_T_null = null `eqP` T.null
122prop_T_length = length `eqP` T.length
128prop_T_length = length `eqP` T.length
123−prop_T_map f = map f `eqP` (T.unpack . T.map f)
129+prop_T_map f = map f `eqP` (unpackT . T.map f)
124−prop_T_intercalate c = L.intercalate c `eq` (T.unpack . T.intercalate (T.pack c) . map T.pack)
130+prop_T_intercalate c = L.intercalate c `eq` (unpackT . T.intercalate (T.pack c) . map T.pack)
125−prop_T_intersperse c = L.intersperse c `eqP` (T.unpack . T.intersperse c)
131+prop_T_intersperse c = L.intersperse c `eqP` (unpackT . T.intersperse c)
126−prop_T_transpose = L.transpose `eq` (map T.unpack . T.transpose . map T.pack)
132+prop_T_transpose = L.transpose `eq` (map unpackT . T.transpose . map T.pack)
127−prop_T_reverse = L.reverse `eqP` (T.unpack . T.reverse)
133+prop_T_reverse = L.reverse `eqP` (unpackT . T.reverse)
128−prop_T_reverse_short n = L.reverse `eqP` (T.unpack . S.reverse . shorten n . S.stream)
134+prop_T_reverse_short n = L.reverse `eqP` (unpackT . S.reverse . shorten n . S.stream)
130prop_T_foldl f z = L.foldl f z `eqP` (T.foldl f z)
136prop_T_foldl f z = L.foldl f z `eqP` (T.foldl f z)
131 where types = f :: Char -> Char -> Char
137 where types = f :: Char -> Char -> Char
@@ -137,51 +143,53 @@ prop_T_foldr f z = L.foldr f z `eqP` T.foldr f z
137 where types = f :: Char -> Char -> Char
143 where types = f :: Char -> Char -> Char
138prop_T_foldr1 f = L.foldr1 f `eqEP` T.foldr1 f
144prop_T_foldr1 f = L.foldr1 f `eqEP` T.foldr1 f
140−prop_T_concat = L.concat `eq` (T.unpack . T.concat . map T.pack)
146+prop_T_concat = L.concat `eq` (unpackT . T.concat . map T.pack)
141−prop_T_concatMap f = L.concatMap f `eqP` (T.unpack . T.concatMap (T.pack . f))
147+prop_T_concatMap f = L.concatMap f `eqP` (unpackT . T.concatMap (T.pack . f))
142prop_T_any p = L.any p `eqP` T.any p
148prop_T_any p = L.any p `eqP` T.any p
143prop_T_all p = L.all p `eqP` T.all p
149prop_T_all p = L.all p `eqP` T.all p
144prop_T_maximum = L.maximum `eqEP` T.maximum
150prop_T_maximum = L.maximum `eqEP` T.maximum
145prop_T_minimum = L.minimum `eqEP` T.minimum
151prop_T_minimum = L.minimum `eqEP` T.minimum
147−prop_T_scanl f z = L.scanl f z `eqP` (T.unpack . T.scanl f z)
153+prop_T_scanl f z = L.scanl f z `eqP` (unpackT . T.scanl f z)
148−prop_T_scanl1 f = L.scanl1 f `eqP` (T.unpack . T.scanl1 f)
154+prop_T_scanl1 f = L.scanl1 f `eqP` (unpackT . T.scanl1 f)
149−prop_T_scanr f z = L.scanr f z `eqP` (T.unpack . T.scanr f z)
155+prop_T_scanr f z = L.scanr f z `eqP` (unpackT . T.scanr f z)
150−prop_T_scanr1 f = L.scanr1 f `eqP` (T.unpack . T.scanr1 f)
156+prop_T_scanr1 f = L.scanr1 f `eqP` (unpackT . T.scanr1 f)
152−prop_T_mapAccumL f z = L.mapAccumL f z `eqP` (second T.unpack . T.mapAccumL f z)
158+prop_T_mapAccumL f z = L.mapAccumL f z `eqP` (second unpackT . T.mapAccumL f z)
153 where types = f :: Int -> Char -> (Int,Char)
159 where types = f :: Int -> Char -> (Int,Char)
154−prop_T_mapAccumR f z = L.mapAccumR f z `eqP` (second T.unpack . T.mapAccumR f z)
160+prop_T_mapAccumR f z = L.mapAccumR f z `eqP` (second unpackT . T.mapAccumR f z)
155 where types = f :: Int -> Char -> (Int,Char)
161 where types = f :: Int -> Char -> (Int,Char)
157−prop_T_replicate n = L.replicate n `eq` (T.unpack . T.replicate n)
163+prop_T_replicate n = L.replicate n `eq` (unpackT . T.replicate n)
158−prop_T_unfoldr n = L.unfoldr f `eq` (T.unpack . T.unfoldr f)
164+prop_T_unfoldr n = L.unfoldr f `eq` (unpackT . T.unfoldr f)
159 where f c | fromEnum c * 100 > n = Nothing
165 where f c | fromEnum c * 100 > n = Nothing
160 | otherwise = Just (c, succ c)
166 | otherwise = Just (c, succ c)
162−prop_T_unfoldrN n m = (L.take n . L.unfoldr f) `eq` (T.unpack . T.unfoldrN n f)
168+prop_T_unfoldrN n m = (L.take n . L.unfoldr f) `eq` (unpackT . T.unfoldrN n f)
163 where f c | fromEnum c * 100 > m = Nothing
169 where f c | fromEnum c * 100 > m = Nothing
164 | otherwise = Just (c, succ c)
170 | otherwise = Just (c, succ c)
166−unpack2 = T.unpack *** T.unpack
172+unpack2 :: (Target t) => (t,t) -> (String,String)
173+unpack2 = unpackT *** unpackT
168−prop_T_take n = L.take n `eqP` (T.unpack . T.take n)
175+prop_T_take n = L.take n `eqP` (unpackT . T.take n)
169−prop_T_drop n = L.drop n `eqP` (T.unpack . T.drop n)
176+prop_T_drop n = L.drop n `eqP` (unpackT . T.drop n)
170−prop_T_takeWhile p = L.takeWhile p `eqP` (T.unpack . T.takeWhile p)
177+prop_T_takeWhile p = L.takeWhile p `eqP` (unpackT . T.takeWhile p)
171−prop_T_takeWhileS p = L.takeWhile p `eqP` (T.unpack . S.unstream . S.takeWhile p . S.stream)
178+prop_T_takeWhileS p = L.takeWhile p `eqP` (unpackT . S.unstream . S.takeWhile p . S.stream)
172−prop_T_dropWhile p = L.dropWhile p `eqP` (T.unpack . T.dropWhile p)
179+prop_T_dropWhile p = L.dropWhile p `eqP` (unpackT . T.dropWhile p)
173−prop_T_dropWhileS p = L.dropWhile p `eqP` (T.unpack . S.unstream . S.dropWhile p . S.stream)
180+prop_T_dropWhileS p = L.dropWhile p `eqP` (unpackT . S.unstream . S.dropWhile p . S.stream)
174prop_T_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)
181prop_T_splitAt n = L.splitAt n `eqP` (unpack2 . T.splitAt n)
182+prop_TL_splitAt n = L.splitAt n `eqP` (unpack2 . TL.splitAt n)
175prop_T_span p = L.span p `eqP` (unpack2 . T.span p)
183prop_T_span p = L.span p `eqP` (unpack2 . T.span p)
176prop_T_break p = L.break p `eqP` (unpack2 . T.break p)
184prop_T_break p = L.break p `eqP` (unpack2 . T.break p)
177−prop_T_group = L.group `eqP` (map T.unpack . T.group)
185+prop_T_group = L.group `eqP` (map unpackT . T.group)
178−prop_T_groupBy p = L.groupBy p `eqP` (map T.unpack . T.groupBy p)
186+prop_T_groupBy p = L.groupBy p `eqP` (map unpackT . T.groupBy p)
179−prop_T_inits = L.inits `eqP` (map T.unpack . T.inits)
187+prop_T_inits = L.inits `eqP` (map unpackT . T.inits)
180−prop_T_tails = L.tails `eqP` (map T.unpack . T.tails)
188+prop_T_tails = L.tails `eqP` (map unpackT . T.tails)
182prop_T_split_i c = id `eq` (T.intercalate (T.singleton c) . T.split c)
190prop_T_split_i c = id `eq` (T.intercalate (T.singleton c) . T.split c)
184−prop_T_splitWith p = splitWith p `eqP` (map T.unpack . T.splitWith p)
192+prop_T_splitWith p = splitWith p `eqP` (map unpackT . T.splitWith p)
186splitWith _ "" = []
194splitWith _ "" = []
187splitWith p s = if null s'
195splitWith p s = if null s'
@@ -196,9 +204,9 @@ prop_T_breakSubstringC c
196 = L.break (==c) `eqP`
204 = L.break (==c) `eqP`
197 (unpack2 . T.breakSubstring (T.singleton c))
205 (unpack2 . T.breakSubstring (T.singleton c))
199−prop_T_lines = L.lines `eqP` (map T.unpack . T.lines)
207+prop_T_lines = L.lines `eqP` (map unpackT . T.lines)
201−prop_T_lines' = lines' `eqP` (map T.unpack . T.lines')
209+prop_T_lines' = lines' `eqP` (map unpackT . T.lines')
202 where lines' "" = []
210 where lines' "" = []
203 lines' s = let (l, s') = break eol s
211 lines' s = let (l, s') = break eol s
204 in l : case s' of
212 in l : case s' of
@@ -207,9 +215,9 @@ prop_T_lines' = lines' `eqP` (map T.unpack . T.lines')
207 (_:s'') -> lines' s''
215 (_:s'') -> lines' s''
208 eol c = c == '\r' || c == '\n'
216 eol c = c == '\r' || c == '\n'
210−prop_T_words = L.words `eqP` (map T.unpack . T.words)
218+prop_T_words = L.words `eqP` (map unpackT . T.words)
211−prop_T_unlines = L.unlines `eq` (T.unpack . T.unlines . map T.pack)
219+prop_T_unlines = L.unlines `eq` (unpackT . T.unlines . map T.pack)
212−prop_T_unwords = L.unwords `eq` (T.unpack . T.unwords . map T.pack)
220+prop_T_unwords = L.unwords `eq` (unpackT . T.unwords . map T.pack)
214prop_T_isPrefixOf s = L.isPrefixOf s`eqP` T.isPrefixOf (T.pack s)
222prop_T_isPrefixOf s = L.isPrefixOf s`eqP` T.isPrefixOf (T.pack s)
215prop_T_isPrefixOfS s = L.isPrefixOf s`eqP` (S.isPrefixOf (S.stream $ T.pack s) . S.stream)
223prop_T_isPrefixOfS s = L.isPrefixOf s`eqP` (S.isPrefixOf (S.stream $ T.pack s) . S.stream)
@@ -217,7 +225,7 @@ prop_T_isSuffixOf s = L.isSuffixOf s`eqP` T.isSuffixOf (T.pack s)
217prop_T_isInfixOf s = L.isInfixOf s `eqP` T.isInfixOf (T.pack s)
225prop_T_isInfixOf s = L.isInfixOf s `eqP` T.isInfixOf (T.pack s)
219prop_T_elem c = L.elem c `eqP` T.elem c
227prop_T_elem c = L.elem c `eqP` T.elem c
220−prop_T_filter p = L.filter p `eqP` (T.unpack . T.filter p)
228+prop_T_filter p = L.filter p `eqP` (unpackT . T.filter p)
221prop_T_find p = L.find p `eqP` T.find p
229prop_T_find p = L.find p `eqP` T.find p
222prop_T_partition p = L.partition p `eqP` (unpack2 . T.partition p)
230prop_T_partition p = L.partition p `eqP` (unpack2 . T.partition p)
@@ -228,7 +236,7 @@ prop_T_findIndices p = L.findIndices p`eqP` T.findIndices p
228prop_T_elemIndex c = L.elemIndex c `eqP` T.elemIndex c
236prop_T_elemIndex c = L.elemIndex c `eqP` T.elemIndex c
229prop_T_elemIndices c = L.elemIndices c`eqP` T.elemIndices c
237prop_T_elemIndices c = L.elemIndices c`eqP` T.elemIndices c
230prop_T_count c = (L.length . L.elemIndices c) `eqP` T.count c
238prop_T_count c = (L.length . L.elemIndices c) `eqP` T.count c
231−prop_T_zipWith c s = L.zipWith c s `eqP` (T.unpack . T.zipWith c (T.pack s))
239+prop_T_zipWith c s = L.zipWith c s `eqP` (unpackT . T.zipWith c (T.pack s))
233-- Regression tests.
241-- Regression tests.
234prop_S_filter_eq s = S.filter p t == S.streamList (filter p s)
242prop_S_filter_eq s = S.filter p t == S.streamList (filter p s)
@@ -276,7 +284,9 @@ tests = [
276 ("prop_S_cons", mytest prop_S_cons),
284 ("prop_S_cons", mytest prop_S_cons),
277 ("prop_T_cons", mytest prop_T_cons),
285 ("prop_T_cons", mytest prop_T_cons),
278 ("prop_TL_cons", mytest prop_TL_cons),
286 ("prop_TL_cons", mytest prop_TL_cons),
287+ ("prop_S_snoc", mytest prop_S_snoc),
279 ("prop_T_snoc", mytest prop_T_snoc),
288 ("prop_T_snoc", mytest prop_T_snoc),
289+ ("prop_TL_snoc", mytest prop_TL_snoc),
280 ("prop_T_append", mytest prop_T_append),
290 ("prop_T_append", mytest prop_T_append),
281 ("prop_T_appendS", mytest prop_T_appendS),
291 ("prop_T_appendS", mytest prop_T_appendS),
282 ("prop_T_uncons", mytest prop_T_uncons),
292 ("prop_T_uncons", mytest prop_T_uncons),