on f7fc888 help sign in
29 lines 1.2 kB history raw
1import Test.HUnit
2import ProjectM36.Base
3import TutorialD.Interpreter.Import.TutorialD
4import System.Exit
5import System.IO.Temp
6import qualified Data.Map as M
7import System.IO
8import qualified Data.ByteString as BS
9import qualified Data.Text.Encoding as TE
11main :: IO ()
12main = do
13 tcounts <- runTestTT $ TestList [testTutdImport]
14 if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
16testTutdImport :: Test
17testTutdImport = TestCase $
18 withSystemTempFile "m.tutd" $ \tempPath handle -> do
19 BS.hPut handle (TE.encodeUtf8 "x:=relation{tuple{a 5,b \"spam\"}}; y:=relation{tuple{b \"漢字\"}}")
20 hClose handle
21 let expectedExpr = MultipleExpr [
22 Assign "x" (MakeRelationFromExprs Nothing
23 $ TupleExprs () [TupleExpr (M.fromList [("a", NakedAtomExpr $ IntegerAtom 5),
24 ("b", NakedAtomExpr $ TextAtom "spam")])]),
25 Assign "y" (MakeRelationFromExprs Nothing
26 $ TupleExprs () [TupleExpr (M.fromList [("b", NakedAtomExpr (TextAtom "漢字"))])])]
27 imported <- importTutorialD tempPath
28 assertEqual "import tutd" (Right expectedExpr) imported