1{-# OPTIONS_GHC -Wno-deprecations #-}
3module Main (main) where
5import Data.Word (Word8)
6import Streamly.Test.Common (listEquals, chooseInt)
7import Test.Hspec (hspec, describe, shouldBe)
8import Test.Hspec.QuickCheck
9import Test.QuickCheck (forAll, Property, vectorOf, Gen, Arbitrary (arbitrary))
10import Test.QuickCheck.Monadic (assert, monadicIO, run)
12import qualified Streamly.Internal.Data.Array as Array
13import qualified Streamly.Internal.Data.Stream.Chunked as ArrayStream
14import qualified Streamly.Internal.Data.Fold as Fold
15import qualified Streamly.Internal.Data.Parser as Parser
16import qualified Streamly.Internal.Data.Stream as Stream
17import qualified Test.Hspec as Hspec
19import Prelude hiding (sequence)
21#if MIN_VERSION_QuickCheck(2,14,0)
23import Test.QuickCheck (chooseAny)
27import System.Random (Random(random))
28import Test.QuickCheck.Gen (Gen(MkGen))
30-- | Generates a random element over the natural range of `a`.
31chooseAny :: Random a => Gen a
32chooseAny = MkGen (\r _ -> let (x,_) = random r in x)
40 => Int -> Fold.Fold m a b -> Stream.Stream m a -> Stream.Stream m b
41chunksOf n f = Stream.foldMany (Fold.take n f)
46 -- ls = input list (stream)
48 -- tlen = parser take size
51 <$> vectorOf len (chooseAny :: Gen Int)
52 <*> chooseInt (1, len)
53 <*> chooseInt (0, len))
54 $ \(ls, clen, tlen) ->
59 clen (Array.writeN clen) (Stream.fromList ls)
60 parser = Parser.fromFold (Fold.take tlen Fold.toList)
61 in run $ ArrayStream.parseBreak parser input
62 ls2 <- run $ Stream.fold Fold.toList (ArrayStream.concat str)
64 Right x -> listEquals (==) (x ++ ls2) ls
65 Left _ -> assert False
67splitOnSuffix :: Word8 -> [Word8] -> [[Word8]] -> IO ()
68splitOnSuffix sep inp out = do
70 Stream.fold Fold.toList
71 $ ArrayStream.splitOnSuffix sep
72 $ chunksOf 2 (Array.writeN 2) $ Stream.fromList inp
73 fmap Array.toList res `shouldBe` out
75-------------------------------------------------------------------------------
77-------------------------------------------------------------------------------
80moduleName = "Data.Array.Stream"
82-- Instead of hard coding 10000 here we can have maxStreamLength for operations
83-- that use stream of arrays.
85concatArrayW8 :: Property
87 forAll (vectorOf 10000 (arbitrary :: Gen Word8))
89 let w8ArrList = Array.fromList . (: []) <$> w8List
90 f2 <- Stream.fold Fold.toList $ ArrayStream.concat $ Stream.fromList w8ArrList
98 modifyMaxSuccess (const maxTestCount) $ do
99 describe moduleName $ do
100 describe "Stream parsing" $ do
101 prop "parseBreak" parseBreak
102 prop "concatArrayW8" concatArrayW8
103 describe "splifOnSuffix" $ do
104 Hspec.it "splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]"
105 $ splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]
106 [[1, 2], [4], [5, 6]]
107 Hspec.it "splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6, 0]"
108 $ splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6, 0]
109 [[1, 2], [4], [5, 6]]
110 Hspec.it "splitOnSuffix 0 [0, 1, 2, 0, 4, 0, 5, 6]"
111 $ splitOnSuffix 0 [0, 1, 2, 0, 4, 0, 5, 6]
112 [[], [1, 2], [4], [5, 6]]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list