on master help sign in
Added test for Prelude.tail
4c6279cVeladus
src/Streamly/Prelude.hs+1−1
@@ -340,7 +340,7 @@ head m =
340tail :: (Streaming t, Monad m) => t m a -> m (Maybe (t m a))
340tail :: (Streaming t, Monad m) => t m a -> m (Maybe (t m a))
341tail m =
341tail m =
342 let stop = return Nothing
342 let stop = return Nothing
343− yield _ Nothing = return Nothing
343+ yield _ Nothing = return $ Just nil
344 yield _ (Just t) = return $ Just $ fromStream t
344 yield _ (Just t) = return $ Just $ fromStream t
345 in (runStream (toStream m)) Nothing stop yield
345 in (runStream (toStream m)) Nothing stop yield
346
346
test/Main.hs+6−3
@@ -7,6 +7,7 @@ import Control.Concurrent (threadDelay)
7import Control.Monad (replicateM)
7import Control.Monad (replicateM)
8import Data.Foldable (forM_)
8import Data.Foldable (forM_)
9import Data.List (sort)
9import Data.List (sort)
10+import Data.Maybe (fromJust, isNothing)
10import Test.Hspec
11import Test.Hspec
11
12
12import Streamly
13import Streamly
@@ -675,9 +676,8 @@ streamOperations (stream, list, len) = do
675 it "dropWhile < some" $ transform (A.dropWhile (< (len `div` 2)))
676 it "dropWhile < some" $ transform (A.dropWhile (< (len `div` 2)))
676 (dropWhile (< (len `div` 2)))
677 (dropWhile (< (len `div` 2)))
677
678
678− it "scan left" $ transform (A.scan (+) 0 id) (scanl (+) 0)
679−
680 -- Transformations
679 -- Transformations
680+ it "scan left" $ transform (A.scan (+) 0 id) (scanl (+) 0)
681 it "reverse" $ transform A.reverse reverse
681 it "reverse" $ transform A.reverse reverse
682
682
683 -- Elimination
683 -- Elimination
@@ -699,15 +699,18 @@ streamOperations (stream, list, len) = do
699 it "maximum empty" $ A.maximum stream `shouldReturn` Nothing
699 it "maximum empty" $ A.maximum stream `shouldReturn` Nothing
700 it "minimum empty" $ A.minimum stream `shouldReturn` Nothing
700 it "minimum empty" $ A.minimum stream `shouldReturn` Nothing
701 it "null empty" $ A.null stream `shouldReturn` True
701 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"
702 else do
704 else do
703 it "head nonEmpty" $ A.head stream `shouldReturn` Just (head list)
705 it "head nonEmpty" $ A.head stream `shouldReturn` Just (head list)
704 it "last nonEmpty" $ A.last stream `shouldReturn` Just (last list)
706 it "last nonEmpty" $ A.last stream `shouldReturn` Just (last list)
705 it "maximum nonEmpty" $ A.maximum stream `shouldReturn` Just (maximum list)
707 it "maximum nonEmpty" $ A.maximum stream `shouldReturn` Just (maximum list)
706 it "minimum nonEmpty" $ A.minimum stream `shouldReturn` Just (minimum list)
708 it "minimum nonEmpty" $ A.minimum stream `shouldReturn` Just (minimum list)
707 it "null nonEmpty" $ A.null stream `shouldReturn` False
709 it "null nonEmpty" $ A.null stream `shouldReturn` False
710+ it "tail nonEmpty" $
711+ (A.tail stream >>= A.toList . fromJust) `shouldReturn` tail list
708
712
709 where
713 where
710−
711 -- XXX run on empty stream as well
714 -- XXX run on empty stream as well
712 transform streamOp listOp =
715 transform streamOp listOp =
713 (A.toList $ streamOp stream) `shouldReturn` listOp list
716 (A.toList $ streamOp stream) `shouldReturn` listOp list