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 (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.IsStream 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)
42 -- ls = input list (stream)
44 -- tlen = parser take size
47 <$> vectorOf len (chooseAny :: Gen Int)
48 <*> chooseInt (1, len)
49 <*> chooseInt (0, len))
50 $ \(ls, clen, tlen) ->
55 clen (Array.writeN clen) (Stream.fromList ls)
56 parser = Parser.fromFold (Fold.take tlen Fold.toList)
57 in run $ ArrayStream.parseBreak parser input
58 ls2 <- run $ Stream.toList $ ArrayStream.concat str
59 listEquals (==) (ls1 ++ ls2) ls
61splitOnSuffix :: Word8 -> [Word8] -> [[Word8]] -> IO ()
62splitOnSuffix sep inp out = do
65 $ ArrayStream.splitOnSuffix sep
66 $ Stream.chunksOf 2 (Array.writeN 2) $ Stream.fromList inp
67 fmap Array.toList res `shouldBe` out
69-------------------------------------------------------------------------------
71-------------------------------------------------------------------------------
74moduleName = "Data.Array.Stream"
76-- Instead of hard coding 10000 here we can have maxStreamLength for operations
77-- that use stream of arrays.
79concatArrayW8 :: Property
81 forAll (vectorOf 10000 (arbitrary :: Gen Word8))
83 let w8ArrList = Array.fromList . (: []) <$> w8List
84 f2 <- Stream.toList $ ArrayStream.concat $ Stream.fromList w8ArrList
92 modifyMaxSuccess (const maxTestCount) $ do
93 describe moduleName $ do
94 describe "Stream parsing" $ do
95 prop "parseBreak" parseBreak
96 prop "concatArrayW8" concatArrayW8
97 describe "splifOnSuffix" $ do
98 Hspec.it "splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]"
99 $ splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]
100 [[1, 2], [4], [5, 6]]
101 Hspec.it "splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6, 0]"
102 $ splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6, 0]
103 [[1, 2], [4], [5, 6]]
104 Hspec.it "splitOnSuffix 0 [0, 1, 2, 0, 4, 0, 5, 6]"
105 $ splitOnSuffix 0 [0, 1, 2, 0, 4, 0, 5, 6]
106 [[], [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