@@ -2,12 +2,12 @@ module Test.Main where
3import Prelude (Unit, ($), (==), (>>=), unit, pure, bind, const)
3import Prelude (Unit, ($), (==), (>>=), unit, pure, bind, const)
4import Control.Apply ((*>))
4import Control.Apply ((*>))
5−import Control.Monad.Error.Class (class MonadThrow, throwError, liftMaybe)
5+import Control.Monad.Error.Class (throwError, liftMaybe)
6import Control.Monad.Reader.Trans (ReaderT, ask, runReaderT)
6import Control.Monad.Reader.Trans (ReaderT, ask, runReaderT)
7import Effect
7import Effect
8import Effect.Aff (Aff, bracket)
8import Effect.Aff (Aff, bracket)
9import Effect.Class (liftEffect)
9import Effect.Class (liftEffect)
10−import Effect.Exception (Error, error)
10+import Effect.Exception (error)
11import HTTPure.Request (Request)
11import HTTPure.Request (Request)
12import HTTPure.Response (ok)
12import HTTPure.Response (ok)
13import HTTPure.Server (serve)
13import HTTPure.Server (serve)
@@ -17,10 +17,13 @@ import HTTPure.Method (Method(Post))
17import Test.Unit (suite, test)
17import Test.Unit (suite, test)
18import Test.Unit.Main (runTest)
18import Test.Unit.Main (runTest)
19import Test.Unit.Assert (equal)
19import Test.Unit.Assert (equal)
20−import Main (compile)
20+import Main (Settings, runCompiler)
22type RequestValidator = ReaderT Request Aff Unit
22type RequestValidator = ReaderT Request Aff Unit
25+settings = { protocol: "http", hostname: "localhost", port: 3000 }
24validatePath :: RequestValidator
27validatePath :: RequestValidator
25validatePath = do
28validatePath = do
26 let invalidPath = error "invalid path"
29 let invalidPath = error "invalid path"
@@ -41,7 +44,7 @@ runReqValidator req = runReaderT (validatePath *> validateMethod) req
42mockSrv :: forall a. Body a => a -> Aff (Effect Unit)
45mockSrv :: forall a. Body a => a -> Aff (Effect Unit)
43mockSrv res = do
46mockSrv res = do
44− close <- liftEffect $ serve 3000 (\req -> runReqValidator req *> ok res) $ pure unit
47+ close <- liftEffect $ serve settings.port (\req -> runReqValidator req *> ok res) $ pure unit
45 pure $ close $ pure unit
48 pure $ close $ pure unit
47setupSrv :: forall a b. Body a => a -> Aff b -> Aff b
50setupSrv :: forall a b. Body a => a -> Aff b -> Aff b
@@ -52,5 +55,6 @@ main = runTest do
52 suite "compile" do
55 suite "compile" do
53 test "produces expected output" do
56 test "produces expected output" do
54 let expected = "2"
57 let expected = "2"
58+ compile = runCompiler settings
55 actual <- setupSrv expected (compile "1+1")
59 actual <- setupSrv expected (compile "1+1")
56 expected `equal` actual
60 expected `equal` actual