on master help sign in
Added test for Prelude.tail
commit4c6279ca88917300497f0550e40ad6e1f7439fb3 authorVeladus <veladus@web.de> dateThu 15 Mar 2018, 22:23 (9 years ago) parentf7b9841
2 files changed+7−4
src/Streamly/Prelude.hs+1−1 test/Main.hs+6−3
src/Streamly/Prelude.hs+1−1
@@ -340,7 +340,7 @@ head m =
340340tail :: (Streaming t, Monad m) => t m a -> m (Maybe (t m a))
341341tail m =
342342 let stop = return Nothing
343− yield _ Nothing = return Nothing
343+ yield _ Nothing = return $ Just nil
344344 yield _ (Just t) = return $ Just $ fromStream t
345345 in (runStream (toStream m)) Nothing stop yield
346346
test/Main.hs+6−3
@@ -7,6 +7,7 @@ import Control.Concurrent (threadDelay)
77import Control.Monad (replicateM)
88import Data.Foldable (forM_)
99import Data.List (sort)
10+import Data.Maybe (fromJust, isNothing)
1011import Test.Hspec
1112
1213import Streamly
@@ -675,9 +676,8 @@ streamOperations (stream, list, len) = do
675676 it "dropWhile < some" $ transform (A.dropWhile (< (len `div` 2)))
676677 (dropWhile (< (len `div` 2)))
677678
678− it "scan left" $ transform (A.scan (+) 0 id) (scanl (+) 0)
679−
680679 -- Transformations
680+ it "scan left" $ transform (A.scan (+) 0 id) (scanl (+) 0)
681681 it "reverse" $ transform A.reverse reverse
682682
683683 -- Elimination
@@ -699,15 +699,18 @@ streamOperations (stream, list, len) = do
699699 it "maximum empty" $ A.maximum stream `shouldReturn` Nothing
700700 it "minimum empty" $ A.minimum stream `shouldReturn` Nothing
701701 it "null empty" $ A.null stream `shouldReturn` True
702+ it "tail empty" $ A.tail stream >>=
703+ \t -> if isNothing t then return () else expectationFailure "failed"
702704 else do
703705 it "head nonEmpty" $ A.head stream `shouldReturn` Just (head list)
704706 it "last nonEmpty" $ A.last stream `shouldReturn` Just (last list)
705707 it "maximum nonEmpty" $ A.maximum stream `shouldReturn` Just (maximum list)
706708 it "minimum nonEmpty" $ A.minimum stream `shouldReturn` Just (minimum list)
707709 it "null nonEmpty" $ A.null stream `shouldReturn` False
710+ it "tail nonEmpty" $
711+ (A.tail stream >>= A.toList . fromJust) `shouldReturn` tail list
708712
709713 where
710−
711714 -- XXX run on empty stream as well
712715 transform streamOp listOp =
713716 (A.toList $ streamOp stream) `shouldReturn` listOp list