@@ -0,0 +1,33 @@
1+{-# LANGUAGE OverloadedStrings #-}
5+import ProjectM36.Relation.Show.CSV
6+import ProjectM36.Relation.Parse.CSV
7+import qualified ProjectM36.Attribute as A
8+import ProjectM36.Relation
12+ tcounts <- runTestTT $ TestList [testCSVExport]
13+ if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
15+--round-trip a basic relation through CSV
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"]]
26+ Left err -> assertFailure $ "export relation creation failure: " ++ (show err)
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'