1module Main (main) where
3import Data.Word (Word8)
4import Streamly.Test.Common (listEquals, chooseInt)
5import Test.Hspec (hspec, describe, shouldBe)
6import Test.Hspec.QuickCheck
7import Test.QuickCheck (forAll, Property, vectorOf, Gen)
8import Test.QuickCheck.Monadic (monadicIO, run)
10import qualified Streamly.Internal.Data.Array.Unboxed as Array
11import qualified Streamly.Internal.Data.Array.Stream.Foreign as ArrayStream
12import qualified Streamly.Internal.Data.Fold as Fold
13import qualified Streamly.Internal.Data.Parser as Parser
14import qualified Streamly.Internal.Data.Stream.IsStream as Stream
15import qualified Test.Hspec as Hspec
17import Prelude hiding (sequence)
19#if MIN_VERSION_QuickCheck(2,14,0)
21import Test.QuickCheck (chooseAny)
25import System.Random (Random(random))
26import Test.QuickCheck.Gen (Gen(MkGen))
28-- | Generates a random element over the natural range of `a`.
29chooseAny :: Random a => Gen a
30chooseAny = MkGen (\r _ -> let (x,_) = random r in x)
40 -- ls = input list (stream)
42 -- tlen = parser take size
45 <$> vectorOf len (chooseAny :: Gen Int)
46 <*> chooseInt (1, len)
47 <*> chooseInt (0, len))
48 $ \(ls, clen, tlen) ->
53 clen (Array.writeN clen) (Stream.fromList ls)
54 parser = Parser.fromFold (Fold.take tlen Fold.toList)
55 in run $ ArrayStream.parseBreak parser input
56 ls2 <- run $ Stream.toList $ ArrayStream.concat str
57 listEquals (==) (ls1 ++ ls2) ls
59splitOnSuffix :: Word8 -> [Word8] -> [[Word8]] -> IO ()
60splitOnSuffix sep inp out = do
63 $ ArrayStream.splitOnSuffix sep
64 $ Stream.chunksOf 2 (Array.writeN 2) $ Stream.fromList inp
65 fmap Array.toList res `shouldBe` out
67-------------------------------------------------------------------------------
69-------------------------------------------------------------------------------
72moduleName = "Data.Array.Stream.Foreign"
78 modifyMaxSuccess (const maxTestCount) $ do
79 describe moduleName $ do
80 describe "Stream parsing" $ do
81 prop "parseBreak" parseBreak
82 describe "splifOnSuffix" $ do
83 Hspec.it "splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]"
84 $ splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6]
86 Hspec.it "splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6, 0]"
87 $ splitOnSuffix 0 [1, 2, 0, 4, 0, 5, 6, 0]
89 Hspec.it "splitOnSuffix 0 [0, 1, 2, 0, 4, 0, 5, 6]"
90 $ splitOnSuffix 0 [0, 1, 2, 0, 4, 0, 5, 6]
91 [[], [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