on master help sign in
Add a test for replace.

--HG-- extra : convert_revision : b63dcbafd874a95f537be8d3e93e68b6a3202f78

commit283b47d5694d1c39eada9e6941311091381a5944 authorBryan O'Sullivan <bos@serpentine.com> dateWed 8 Jul 2009, 04:30 (17 years ago) parent5c9dcae
1 file changed+17−1
tests/Properties.hs+17−1
tests/Properties.hs+17−1
@@ -1,4 +1,4 @@
1−{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
1+{-# LANGUAGE BangPatterns, FlexibleInstances, TypeSynonymInstances #-}
22{-# OPTIONS_GHC -fno-enable-rewrite-rules #-}
33
44import Test.QuickCheck
@@ -170,6 +170,21 @@ prop_T_reverse = L.reverse `eqP` (unpackS . T.reverse)
170170prop_TL_reverse = L.reverse `eqP` (unpackS . TL.reverse)
171171prop_T_reverse_short n = L.reverse `eqP` (unpackS . S.reverse . shorten n . S.stream)
172172
173+prop_T_replace s d = (L.intercalate d . split s) `eqP` (unpackS . T.replace (T.pack s) (T.pack d))
174+
175+split :: (Eq a) => [a] -> [a] -> [[a]]
176+split pat src0
177+ | l == 0 = [src0]
178+ | otherwise = go src0
179+ where
180+ l = length pat
181+ go src = search 0 src
182+ where
183+ search !n [] = [src]
184+ search !n s@(_:s')
185+ | pat `L.isPrefixOf` s = take n src : go (drop l s)
186+ | otherwise = search (n+1) s'
187+
173188prop_T_foldl f z = L.foldl f z `eqP` (T.foldl f z)
174189 where types = f :: Char -> Char -> Char
175190prop_TL_foldl f z = L.foldl f z `eqP` (TL.foldl f z)
@@ -443,6 +458,7 @@ tests = [
443458 ("prop_T_reverse", mytest prop_T_reverse),
444459 ("prop_TL_reverse", mytest prop_TL_reverse),
445460 ("prop_T_reverse_short", mytest prop_T_reverse_short),
461+ ("prop_T_replace", mytest prop_T_replace),
446462
447463 ("prop_T_foldl", mytest prop_T_foldl),
448464 ("prop_TL_foldl", mytest prop_TL_foldl),