mirror of
https://github.com/bsima/haskell-urbit-api.git
synced 2024-09-11 18:27:08 +03:00
better testing and formatting with ormolu
This commit is contained in:
parent
5c723787a7
commit
384d249041
69
test.hs
69
test.hs
@ -1,17 +1,66 @@
|
|||||||
|
{-# LANGUAGE LambdaCase #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
|
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
|
import Control.Exception (SomeException (..), try)
|
||||||
|
import Data.Aeson (KeyValue ((.=)))
|
||||||
|
import qualified Data.Aeson as Aeson
|
||||||
|
import Data.Text (Text)
|
||||||
|
import qualified Data.Text as Text
|
||||||
|
import qualified Data.Text.IO as Text.IO
|
||||||
import Urbit.Airlock
|
import Urbit.Airlock
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
let ship = Ship {
|
let ship =
|
||||||
session = Nothing,
|
Ship
|
||||||
lastEventId = 0,
|
{ session = Nothing,
|
||||||
url = "http://localhost:8081",
|
lastEventId = 0,
|
||||||
code = "lidlut-tabwed-pillex-ridrup",
|
url = "http://localhost:8081",
|
||||||
sseClient = False,
|
code = "lidlut-tabwed-pillex-ridrup",
|
||||||
name = "zod"
|
sseClient = False
|
||||||
}
|
}
|
||||||
connect ship
|
|
||||||
putStrLn "success"
|
testing "ship connection" $ connect ship
|
||||||
|
|
||||||
|
testing "poke ship" $
|
||||||
|
poke ship "zod" "chat-hook" "json" $
|
||||||
|
Aeson.object
|
||||||
|
[ "message"
|
||||||
|
.= Aeson.object
|
||||||
|
[ "path" .= Text.pack "/~/~zod/mc",
|
||||||
|
"envelope"
|
||||||
|
.= Aeson.object
|
||||||
|
[ "uid" .= Text.pack "FIXME",
|
||||||
|
"number" .= lastEventId ship,
|
||||||
|
"author" .= Text.pack "~zod",
|
||||||
|
"when" .= Text.pack "FIXME", -- int(time.time() * 1000)
|
||||||
|
"letter" .= Aeson.object ["text" .= Text.pack "hello world!"]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
-- | Poor man's testing framework
|
||||||
|
testing :: Show a => Text -> IO a -> IO ()
|
||||||
|
testing description f =
|
||||||
|
(putStrLn $ replicate 80 '-') >> try f >>= \case
|
||||||
|
Left (err :: SomeException) -> do
|
||||||
|
Text.IO.putStrLn $ "FAIL: " <> description
|
||||||
|
putStrLn $ show err
|
||||||
|
Right _ ->
|
||||||
|
Text.IO.putStrLn $ "PASS: " <> description
|
||||||
|
|
||||||
|
{-
|
||||||
|
s = baseconvert.base(random.getrandbits(128), 10, 32, string=True).lower()
|
||||||
|
uid = '0v' + '.'.join(s[i:i+5] for i in range(0, len(s), 5))[::-1]
|
||||||
|
|
||||||
|
"path": "/~/~zod/mc",
|
||||||
|
"envelope": {"uid": uid,
|
||||||
|
"number": 1,
|
||||||
|
"author": "~zod",
|
||||||
|
"when": ,
|
||||||
|
"letter": {"text": "hello world!"}}
|
||||||
|
|
||||||
|
-}
|
||||||
|
Loading…
Reference in New Issue
Block a user