File: FileReadSpec.hs

package info (click to toggle)
haskell-streaming-commons 0.2.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 284 kB
  • sloc: haskell: 2,547; ansic: 297; makefile: 7
file content (20 lines) | stat: -rw-r--r-- 663 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Data.Streaming.FileReadSpec (spec) where

import Test.Hspec
import qualified Data.ByteString as S
import qualified Data.Streaming.FileRead as F
import Control.Exception (bracket)

spec :: Spec
spec = describe "Data.Streaming.FileRead" $ do
    it "works" $ do
        let fp = "LICENSE"
        expected <- S.readFile fp
        actual <- bracket (F.openFile fp) F.closeFile $ \fh -> do
            let loop front = do
                    bs <- F.readChunk fh
                    if S.null bs
                        then return $ S.concat $ front []
                        else loop (front . (bs:))
            loop id
        actual `shouldBe` expected