on master help sign in
Fix a bug in splitWith.
bd24b5cBryan O'Sullivan
Data/Text.hs+2−2
@@ -984,9 +984,9 @@ splitTimesEnd k pat src =
984-- separators result in an empty component in the output. eg.
984-- separators result in an empty component in the output. eg.
985--
985--
986-- > splitWith (=='a') "aabbaca" == ["","","bb","c",""]
986-- > splitWith (=='a') "aabbaca" == ["","","bb","c",""]
987−-- > splitWith (=='a') [] == []
987+-- > splitWith (=='a') "" == [""]
988splitWith :: (Char -> Bool) -> Text -> [Text]
988splitWith :: (Char -> Bool) -> Text -> [Text]
989−splitWith _ (Text _off _arr 0) = []
989+splitWith _ t@(Text _off _arr 0) = [t]
990splitWith p t = loop t
990splitWith p t = loop t
991 where loop s | null s' = [l]
991 where loop s | null s' = [l]
992 | otherwise = l : loop (unsafeTail s')
992 | otherwise = l : loop (unsafeTail s')
tests/Properties.hs+2
@@ -305,6 +305,7 @@ prop_T_splitChar_i c = id `eq` (T.intercalate (T.singleton c) . T.splitChar c)
305prop_TL_split_i c = id `eq` (TL.intercalate (TL.singleton c) . TL.split c)
305prop_TL_split_i c = id `eq` (TL.intercalate (TL.singleton c) . TL.split c)
306
306
307prop_T_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
307prop_T_splitWith p = splitWith p `eqP` (map unpackS . T.splitWith p)
308+prop_T_splitWith_split c = T.splitWith (==c) `eq` T.split (T.singleton c)
308prop_TL_splitWith p = splitWith p `eqP` (map unpackS . TL.splitWith p)
309prop_TL_splitWith p = splitWith p `eqP` (map unpackS . TL.splitWith p)
309
310
310splitWith :: (a -> Bool) -> [a] -> [[a]]
311splitWith :: (a -> Bool) -> [a] -> [[a]]
@@ -569,6 +570,7 @@ tests = [
569 ("prop_T_splitChar_i", mytest prop_T_splitChar_i),
570 ("prop_T_splitChar_i", mytest prop_T_splitChar_i),
570 ("prop_TL_split_i", mytest prop_TL_split_i),
571 ("prop_TL_split_i", mytest prop_TL_split_i),
571 ("prop_T_splitWith", mytest prop_T_splitWith),
572 ("prop_T_splitWith", mytest prop_T_splitWith),
573+ ("prop_T_splitWith_split", mytest prop_T_splitWith_split),
572 ("prop_TL_splitWith", mytest prop_TL_splitWith),
574 ("prop_TL_splitWith", mytest prop_TL_splitWith),
573 ("prop_T_chunksOf_same_lengths", mytest prop_T_chunksOf_same_lengths),
575 ("prop_T_chunksOf_same_lengths", mytest prop_T_chunksOf_same_lengths),
574 ("prop_T_chunksOf_length", mytest prop_T_chunksOf_length),
576 ("prop_T_chunksOf_length", mytest prop_T_chunksOf_length),