1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Test.Foundation.Conduit
( testConduit
) where
import Foundation
import Foundation.Check
import Foundation.Conduit
import Foundation.IO
testConduit :: Test
testConduit = Group "Conduit"
[ CheckPlan "sourceHandle gives same data as readFile" testSourceFile
, CheckPlan "sourceHandle/sinkHandle copies data" testCopyFile
, CheckPlan "sourceFile/sinkFile copies data" testCopyFileRes
]
where
--testSourceFile :: Assertion
testSourceFile = do
let fp = "foundation.cabal"
arrs <- pick "conduit-read" $ withFile fp ReadMode $ \h ->
runConduit $ sourceHandle h .| sinkList
arr <- pick "read-source" $ readFile fp
validate "foundation.cabal contents" $ arr == (mconcat arrs)
--testCopyFile :: Assertion
testCopyFile = do
let src = "foundation.cabal"
dst = "temp-file" -- FIXME some temp file API?
pick "conduit-duplicate" $ withFile src ReadMode $ \hin ->
withFile dst WriteMode $ \hout ->
runConduit $ sourceHandle hin .| sinkHandle hout
orig <- pick "read-source" $ readFile src
new <- pick "read-destination" $ readFile dst
validate "copied foundation.cabal contents" $ orig == new
--testCopyFileRes :: Assertion
testCopyFileRes = do
let src = "foundation.cabal"
dst = "temp-file" -- FIXME some temp file API?
pick "conduit-res" $ runConduitRes $ sourceFile src .| sinkFile dst
orig <- pick "read-soure" $ readFile src
new <- pick "read-destination" $ readFile dst
validate "copied foundation.cabal contents" $ orig == new
|