implemented labelFields
This commit is contained in:
@@ -25,17 +25,68 @@ module Data.CSV.SipSpec (spec) where
|
||||
import Conduit (runConduit, (.|))
|
||||
import Data.Char (ord)
|
||||
import Data.Conduit.List (consume, sourceList)
|
||||
import qualified Data.Map as M
|
||||
import Test.Hspec (Spec, context, describe, it, shouldBe)
|
||||
|
||||
import Data.CSV.Sip
|
||||
|
||||
spec :: Spec
|
||||
spec = describe "Data.CSV.Sip" $ do
|
||||
labelFieldsSpec
|
||||
decodeRowsSpec
|
||||
decodeRawRowsSpec
|
||||
decodeUTF8Spec
|
||||
toBytesSpec
|
||||
|
||||
labelFieldsSpec :: Spec
|
||||
labelFieldsSpec = describe "labelFields" $ mapM_
|
||||
( \(label, input, expected) -> context label $ do
|
||||
result <- runConduit $ sourceList input .| labelFields .| consume
|
||||
let
|
||||
expLen = length expected
|
||||
resLen = length result
|
||||
it ("should have " ++ show expLen ++ " rows") $
|
||||
resLen `shouldBe` expLen
|
||||
mapM_
|
||||
( \(n, result', expected') -> context ("row " ++ show n) $
|
||||
it ("should be " ++ show expected') $
|
||||
result' `shouldBe` expected'
|
||||
) $ zip3 [(0::Int)..] result expected
|
||||
)
|
||||
|
||||
-- label, input, expected
|
||||
[ ( "empty", [], [] )
|
||||
, ( "no body", [headers], [] )
|
||||
, ( "with body", withBodyIn, withBodyRes )
|
||||
, ( "mixed cols", mixedColsIn, mixedColsRes )
|
||||
]
|
||||
|
||||
where
|
||||
headers = ["foo", "bar", "baz"] :: [String]
|
||||
|
||||
withBodyIn = headers :
|
||||
[ ["a", "b", "c"]
|
||||
, ["d", "e", "f"]
|
||||
] :: [[String]]
|
||||
|
||||
mixedColsIn =
|
||||
[ ["foo", "bar"]
|
||||
, ["a"]
|
||||
, ["b", "c"]
|
||||
, ["d", "e", "f"]
|
||||
] :: [[String]]
|
||||
|
||||
withBodyRes = map M.fromList
|
||||
[ [("foo", "a"), ("bar", "b"), ("baz", "c")]
|
||||
, [("foo", "d"), ("bar", "e"), ("baz", "f")]
|
||||
] :: [M.Map String String]
|
||||
|
||||
mixedColsRes = map M.fromList
|
||||
[ [("foo", "a")]
|
||||
, [("foo", "b"), ("bar", "c")]
|
||||
, [("foo", "d"), ("bar", "e")]
|
||||
] :: [M.Map String String]
|
||||
|
||||
decodeRowsSpec :: Spec
|
||||
decodeRowsSpec = describe "decodeRows" $ mapM_
|
||||
( \(label, input, expected) -> context label $ do
|
||||
|
||||
Reference in New Issue
Block a user