wrote basic structure of decodeRows

This commit is contained in:
2022-04-19 16:03:14 -04:00
parent 365dc3995b
commit 08c77d4d0f
5 changed files with 70 additions and 4 deletions

View File

@@ -18,11 +18,45 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
-}
{-# LANGUAGE OverloadedStrings #-}
module Data.CSV.SlurpSpec (spec) where
import Test.Hspec (Spec, describe)
import Conduit (runConduit, (.|))
import Data.Conduit.List (consume, sourceList)
import Test.Hspec (Spec, context, describe, shouldBe, xit)
import Data.CSV.Slurp
spec :: Spec
spec = describe "Data.CSV.Slurp" $ return ()
spec = describe "Data.CSV.Slurp"
decodeRowsSpec
decodeRowsSpec :: Spec
decodeRowsSpec = describe "decodeRows" $ mapM_
( \(label, input, expected) -> context label $ do
result <- runConduit $ sourceList input .| decodeRows .| consume
let
expLen = length expected
resLen = length result
xit ("should have " ++ show expLen ++ " rows") $
resLen `shouldBe` expLen
mapM_
( \(n, expected', result') -> context ("row " ++ show n) $
xit ("should be " ++ show expected') $
result' `shouldBe` expected'
) $ zip3 [(0::Int)..] expected result
)
-- label, input, expected
[ ( "valid", validIn, validRes )
, ( "invalid", invalidIn, [] )
, ( "empty", [], [] )
]
where
validIn = ["foo,bar\r\n", "baz,quuux\r\n"]
invalidIn = ["\"a"]
validRes = [["foo", "bar"], ["baz", "quux"]]
--jl

View File

@@ -25,6 +25,6 @@ import Test.Hspec (hspec)
import qualified Data.CSV.SlurpSpec as Slurp
main :: IO ()
main = hspec $ Slurp.spec
main = hspec Slurp.spec
--jl