packages feed

csv-conduit 0.3.0.1 → 0.3.0.2

raw patch · 3 files changed

+35/−25 lines, 3 filesdep ~attoparsec-conduit

Dependency ranges changed: attoparsec-conduit

Files

csv-conduit.cabal view
@@ -1,5 +1,5 @@ Name:                csv-conduit-Version:             0.3.0.1+Version:             0.3.0.2 Synopsis:            A flexible, fast, conduit-based CSV parser library for Haskell. Homepage:            http://github.com/ozataman/csv-conduit License:             BSD3@@ -70,7 +70,7 @@   hs-source-dirs: src   build-depends:       attoparsec >= 0.10-    , attoparsec-conduit+    , attoparsec-conduit >= 0.5.0.2     , base >= 4 && < 5     , bytestring     , conduit == 0.5.*@@ -78,6 +78,7 @@     , monad-control     , text   ghc-options: -funbox-strict-fields+  ghc-prof-options: -fprof-auto  test-suite test   type: exitcode-stdio-1.0
src/Data/CSV/Conduit.hs view
@@ -37,7 +37,8 @@ import           Data.ByteString.Internal           (c2w) import           Data.Conduit import           Data.Conduit.Attoparsec-import           Data.Conduit.Binary                (sinkFile, sinkIOHandle, sourceFile)+import           Data.Conduit.Binary                (sinkFile, sinkIOHandle,+                                                     sourceFile) import qualified Data.Conduit.List                  as C import qualified Data.Map                           as M import           Data.String@@ -164,9 +165,10 @@ ------------------------------------------------------------------------------- intoCSVRow :: (MonadThrow m, AttoparsecInput i)            => Parser i (Maybe o) -> GLInfConduit i m o-intoCSVRow p = conduitParser p >+> puller+intoCSVRow p = parse >+> puller   where-    puller = do+    parse = {-# SCC "conduitParser_p" #-} conduitParser p+    puller = {-# SCC "puller" #-} do       emrow <- awaitE       case emrow of         Left ures -> return ures@@ -260,14 +262,14 @@ ------------------------------------------------------------------------------- -- | Write CSV data into file. writeCSVFile-  :: (CSV ByteString a) -  => CSVSettings +  :: (CSV ByteString a)+  => CSVSettings   -- ^ CSV Settings-  -> FilePath +  -> FilePath   -- ^ Target file-  -> IOMode +  -> IOMode   -- ^ Write vs. append mode-  -> [a] +  -> [a]   -- ^ List of rows   -> IO () writeCSVFile set fo fmode rows = runResourceT $ do
test/Test.hs view
@@ -1,34 +1,38 @@-{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE OverloadedStrings   #-}+{-# LANGUAGE ScopedTypeVariables #-}  module Main where -import qualified Data.ByteString.Char8 as B-import Data.Map ((!))-import Data.Text-import System.Directory-import Test.Framework (Test, defaultMain, testGroup)-import Test.Framework.Providers.HUnit-import Test.HUnit ((@=?))+import qualified Data.ByteString.Char8          as B+import           Data.Map                       ((!))+import           Data.Text+import           System.Directory+import           Test.Framework                 (Test, defaultMain, testGroup)+import           Test.Framework.Providers.HUnit+import           Test.HUnit                     ((@=?)) -import Data.CSV.Conduit+import           Data.CSV.Conduit   main :: IO () main = defaultMain tests + tests :: [Test] tests = [testGroup "Basic Ops" baseTests] + baseTests :: [Test] baseTests =   [ testCase "mapping with id works" test_identityMap   , testCase "simple parsing works" test_simpleParse   ] + test_identityMap :: IO () test_identityMap = do-    _ <- runResourceT $ mapCSVFile csvSettings f testFile outFile-    f1 <- readFile testFile+    _ <- runResourceT $ mapCSVFile csvSettings f testFile2 outFile+    f1 <- readFile testFile2     f2 <- readFile outFile     f1 @=? f2     removeFile outFile@@ -37,10 +41,10 @@     f :: Row Text -> [Row Text]     f = return + test_simpleParse :: IO () test_simpleParse = do-  (d :: [MapRow B.ByteString]) <- runResourceT-                                $ readCSVFile csvSettings testFile+  (d :: [MapRow B.ByteString]) <- readCSVFile csvSettings testFile1   mapM_ assertRow d   where     assertRow r = v3 @=? (v1 + v2)@@ -48,12 +52,15 @@             v2 = readBS $ r ! "Col3"             v3 = readBS $ r ! "Sum" + csvSettings :: CSVSettings csvSettings = defCSVSettings { csvQuoteChar = Just '`'                              , csvOutputQuoteChar = Just '`' } -testFile :: FilePath-testFile = "test/test.csv"+testFile1, testFile2 :: FilePath+testFile1 = "test/test.csv"+testFile2 = "test/test.csv"+  readBS :: B.ByteString -> Int readBS = read . B.unpack