@@ -4,19 +4,23 @@ import TutorialD.Interpreter.Import.TutorialD
4import System.Exit
4import System.Exit
5import qualified Data.Text as T
5import qualified Data.Text as T
6import System.IO.Temp
6import System.IO.Temp
7import qualified Data.Map as M
8import qualified Data.Map as M
8import System.IO
9import System.IO
10+import System.Directory
9import qualified Data.ByteString as BS
11import qualified Data.ByteString as BS
10import qualified Data.Text.Encoding as TE
12import qualified Data.Text.Encoding as TE
11−import Text.URI
13+import Text.URI hiding (makeAbsolute)
13main :: IO ()
15main :: IO ()
15− tcounts <- runTestTT $ TestList [testTutdFileImport, testTutdHTTPSImport]
17+ tcounts <- runTestTT $ TestList [testTutdFileImport
16 if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
20 if errors tcounts + failures tcounts > 0 then exitFailure else exitSuccess
18testTutdFileImport :: Test
22testTutdFileImport :: Test
19−testTutdFileImport = TestCase $
23+testTutdFileImport = TestCase $
20 withSystemTempFile "m.tutd" $ \tempPath handle -> do
24 withSystemTempFile "m.tutd" $ \tempPath handle -> do
21 BS.hPut handle (TE.encodeUtf8 "x:=relation{tuple{a 5,b \"spam\"}}; y:=relation{tuple{b \"漢字\"}}")
25 BS.hPut handle (TE.encodeUtf8 "x:=relation{tuple{a 5,b \"spam\"}}; y:=relation{tuple{b \"漢字\"}}")
22 hClose handle
26 hClose handle
@@ -26,7 +30,9 @@ testTutdFileImport = TestCase $
26 ("b", NakedAtomExpr $ TextAtom "spam")])]),
30 ("b", NakedAtomExpr $ TextAtom "spam")])]),
27 Assign "y" (MakeRelationFromExprs Nothing
31 Assign "y" (MakeRelationFromExprs Nothing
28 $ TupleExprs () [TupleExpr (M.fromList [("b", NakedAtomExpr (TextAtom "漢字"))])])]
32 $ TupleExprs () [TupleExpr (M.fromList [("b", NakedAtomExpr (TextAtom "漢字"))])])]
33+ --on Windows, the file URI should not include the drive letter "/c/Users..." -> "/Users"
34+ let uri = "file://" <> map (\c -> if c == '\\' then '/' else c) ( joinDrive "/" (dropDrive (tempPath)))
29− fileURI <- mkURI (T.pack ("file://" <> tempPath))
35+ fileURI <- mkURI (T.pack uri)
30 imported <- importTutorialDFromFile fileURI Nothing
36 imported <- importTutorialDFromFile fileURI Nothing
31 assertEqual "import tutd" (Right expectedExpr) imported
37 assertEqual "import tutd" (Right expectedExpr) imported