@@ -1,67 +1,8 @@
1−module Test.Main where
1+module Test.Main (main) where
22
3−import Prelude (Unit, ($), (==), (>>=), unit, pure, bind, const)
4−import Control.Apply ((*>))
5−import Control.Monad.Error.Class (throwError, liftMaybe)
6−import Control.Monad.Reader.Trans (ReaderT, ask, runReaderT)
7−import Control.Monad.Trans.Class (lift)
8−import Effect
9−import Effect.Aff (Aff, bracket)
10−import Effect.Class (liftEffect)
11−import Effect.Exception (error)
12−import HTTPure.Request (Request)
13−import HTTPure.Response (ok)
14−import HTTPure.Server (serve)
15−import HTTPure.Body (class Body)
16−import HTTPure.Lookup ((!!))
17−import HTTPure.Method (Method(Post))
18−import Test.Unit (suite, test)
19−import Test.Unit.Main (runTest)
20−import Test.Unit.Assert (equal)
21−import Main (Settings, Code, runCompiler)
22−
23−type ServerMock = ReaderT Code (ReaderT Request Aff)
24−
25−askCode :: ServerMock Code
26−askCode = ask
27−
28−askReq :: ServerMock Request
29−askReq = lift ask
30−
31−settings :: Settings
32−settings = { protocol: "http", hostname: "localhost", port: 3000 }
33−
34−validatePath :: ServerMock Unit
35−validatePath = do
36− let invalidPath = error "invalid path"
37− missingPath = error "missing path"
38− req <- askReq
39− p <- liftMaybe missingPath $ req.path !! 0
40− case p == "compile" of
41− true -> pure unit
42− false -> throwError invalidPath
43−
44−validateMethod :: ServerMock Unit
45−validateMethod = askReq >>= case _ of
46− { method: Post } -> pure unit
47− _ -> throwError $ error "invalid method"
48−
49−runServerMock :: Code -> Request -> Aff Unit
50−runServerMock res req = runReaderT (runReaderT (validatePath *> validateMethod) res) req
51−
52−launchServerMock :: Code -> Aff (Effect Unit)
53−launchServerMock res = do
54− close <- liftEffect $ serve settings.port (\req -> runServerMock res req *> ok res) $ pure unit
55− pure $ close $ pure unit
56−
57−setupSrv :: forall b. Code -> Aff b -> Aff b
58−setupSrv code act = bracket (launchServerMock code) liftEffect (const act)
3+import Prelude (Unit)
4+import Effect (Effect)
5+import Test.Compiler as Compiler
596
607main :: Effect Unit
61−main = runTest do
62− suite "compile" do
63− test "produces expected output" do
64− let expected = "compiled-code"
65− compile = runCompiler settings
66− actual <- setupSrv expected (compile "code")
67− expected `equal` actual
8+main = Compiler.runTests