git.iko.soy/rowtype-yoga/purs-eval
on main help sign in
feat: add compile
commitbcf123b4367614a2d7630c9fcb6c7a583ee0cf7b authorWalker <walker@praiseweb.com.br> dateFri 28 Oct 2022, 21:13 (4 years ago) parenta63b2b1
3 files changed+47−5
flake.nix+9−2 src/Main.purs+14−1 test/Main.purs+24−2
flake.nix+9−2
@@ -21,15 +21,22 @@
2121 ps =
2222 purs-nix.purs
2323 {
24+ dir = ./.;
25+
2426 dependencies =
2527 with purs-nix.ps-pkgs;
2628 [
27− effect
2829 prelude
30+ aff
31+ effect
2932 node-process
33+ test-unit
34+ httpure
35+ affjax-node
3036 ];
3137
32− dir = ./.;
38+ #foreign.xhr2.node_modules = ./xhr2.nix;
39+
3340 };
3441 in
3542 rec {
src/Main.purs+14−1
@@ -1,10 +1,23 @@
11module Main where
22
3−import Prelude (Unit, void, ($))
3+import Prelude (Unit, ($), (<<<), void, pure, bind)
44
5+import Control.Monad.Error.Class (liftEither)
6+import Data.Bifunctor (lmap)
7+import Data.Maybe (Maybe(Just))
58import Effect (Effect)
9+import Effect.Aff (Aff, error)
610import Node.Process (stdin, stdout)
711import Node.Stream (pipe)
12+import Affjax.ResponseFormat (string)
13+import Affjax.Node (post, printError)
14+import Affjax.RequestBody (RequestBody (String))
15+
16+compile :: String -> Aff String
17+compile s = do
18+ mRes <- post string "http://localhost:3000/compiler" $ Just $ String s
19+ res <- liftEither $ (error <<< printError) `lmap` mRes
20+ pure res.body
821
922main :: Effect Unit
1023main = void $ stdin `pipe` stdout
test/Main.purs+24−2
@@ -1,7 +1,29 @@
11module Test.Main where
22
3−import Prelude (Unit, pure, unit)
3+import Prelude (Unit, ($), unit, pure, bind, const)
44import Effect
5+import Effect.Aff (Aff, bracket)
6+import Effect.Class (liftEffect)
7+import HTTPure.Response (ok)
8+import HTTPure.Server (serve)
9+import HTTPure.Body (class Body)
10+import Test.Unit (suite, test)
11+import Test.Unit.Main (runTest)
12+import Test.Unit.Assert (equal)
13+import Main (compile)
14+
15+mockSrv :: forall a. Body a => a -> Aff (Effect Unit)
16+mockSrv res = do
17+ close <- liftEffect $ serve 3000 (const $ ok res) $ pure unit
18+ pure $ close $ pure unit
19+
20+setupSrv :: forall a b. Body a => a -> Aff b -> Aff b
21+setupSrv res act = bracket (mockSrv res) liftEffect (const act)
522
623main :: Effect Unit
7−main = pure unit
24+main = runTest do
25+ suite "compile" do
26+ test "produces expected output" do
27+ let expected = "2"
28+ actual <- setupSrv expected (compile "1+1")
29+ actual `equal` expected