Permalink
Browse files

Testsuite tweaks

  • Loading branch information...
1 parent 2486c5f commit ea6d5ae3dc976c0bcdfee467c9c5dc0a0532d6c8 @ozataman committed Oct 7, 2012
Showing with 21 additions and 14 deletions.
  1. +21 −14 test/Test.hs
View
@@ -1,35 +1,38 @@
+{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
-{-# LANGUAGE OverloadedStrings #-}
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
@@ -38,22 +41,26 @@ test_identityMap = do
f :: Row Text -> [Row Text]
f = return
+
test_simpleParse :: IO ()
test_simpleParse = do
- (d :: [MapRow B.ByteString]) <- readCSVFile csvSettings testFile
+ (d :: [MapRow B.ByteString]) <- readCSVFile csvSettings testFile1
mapM_ assertRow d
where
assertRow r = v3 @=? (v1 + v2)
where v1 = readBS $ r ! "Col2"
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

0 comments on commit ea6d5ae

Please sign in to comment.