@@ -0,0 +1,33 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+import Test.HUnit
3+import ProjectM36.Base
4+import System.Exit
5+import ProjectM36.Relation.Show.CSV
6+import ProjectM36.Relation.Parse.CSV
7+import qualified ProjectM36.Attribute as A
8+import ProjectM36.Relation
9+
10+main :: IO ()
11+main = do
12+ tcounts <- runTestTT $ TestList [testCSVExport]
13+ if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
14+
15+--round-trip a basic relation through CSV
16+testCSVExport :: Test
17+testCSVExport = TestCase $ do
18+ let attrs = A.attributesFromList [Attribute "S#" StringAtomType,
19+ Attribute "SNAME" StringAtomType,
20+ Attribute "STATUS" IntAtomType,
21+ Attribute "CITY" StringAtomType]
22+ relOrErr = mkRelationFromList attrs [
23+ [StringAtom "S9", StringAtom "Perry", IntAtom 170, StringAtom "Londonderry"],
24+ [StringAtom "S8", StringAtom "Mike", IntAtom 150, StringAtom "Boston"]]
25+ case relOrErr of
26+ Left err -> assertFailure $ "export relation creation failure: " ++ (show err)
27+ Right rel -> do
28+ case relationAsCSV rel of
29+ Left err -> assertFailure $ "export failed: " ++ (show err)
30+ Right csvData -> case csvAsRelation csvData attrs of -- import csv data back to relation
31+ Left err -> assertFailure $ "re-import failed: " ++ (show err)
32+ Right rel' -> assertEqual "relation CSV comparison" rel rel'
33+