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.Array.Stream 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) ->
60 clen (Array.writeN clen) (Stream.fromList ls)
61 parser = Parser.fromFold (Fold.take tlen Fold.toList)
62 in run $ ArrayStream.parseBreak parser input
63 ls2 <- run $ Stream.fold Fold.toList (ArrayStream.concat $ Stream.fromStreamK str)
65 Right x -> listEquals (==) (x ++ ls2) ls
66 Left _ -> assert False
68splitOnSuffix :: Word8 -> [Word8] -> [[Word8]] -> IO ()
69splitOnSuffix sep inp out = do
71 Stream.fold Fold.toList
72 $ ArrayStream.splitOnSuffix sep
73 $ chunksOf 2 (Array.writeN 2) $ Stream.fromList inp
74 fmap Array.toList res `shouldBe` out
76-------------------------------------------------------------------------------
78-------------------------------------------------------------------------------
81moduleName = "Data.Array.Stream"
83-- Instead of hard coding 10000 here we can have maxStreamLength for operations
84-- that use stream of arrays.
86concatArrayW8 :: Property
88 forAll (vectorOf 10000 (arbitrary :: Gen Word8))
90 let w8ArrList = Array.fromList . (: []) <$> w8List
91 f2 <- Stream.fold Fold.toList $ ArrayStream.concat $ Stream.fromList w8ArrList
99 modifyMaxSuccess (const maxTestCount) $ do
100 describe moduleName $ do
101 describe "Stream parsing" $ do
102 prop "parseBreak" parseBreak
103 prop "concatArrayW8" concatArrayW8
104 describe "splifOnSuffix" $ do
105 Hspec.it "splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]"
106 $ splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]
107 [[1, 2], [4], [5, 6]]
108 Hspec.it "splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6, 0]"
109 $ splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6, 0]
110 [[1, 2], [4], [5, 6]]
111 Hspec.it "splitOnSuffix 0 [0, 1, 2, 0, 4, 0, 5, 6]"
112 $ splitOnSuffix 0 [0, 1, 2, 0, 4, 0, 5, 6]
113 [[], [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