Skip to content
Snippets Groups Projects
Commit 26d8c130 authored by Jens Nolte's avatar Jens Nolte
Browse files

Merge example api definition into test case

parent dd102eb9
No related branches found
No related tags found
No related merge requests found
......@@ -77,6 +77,5 @@ test-suite qrpc-test
main-is: Spec.hs
other-modules:
Network.RpcSpec
Network.RpcSpec.ExampleApi
hs-source-dirs:
test
......@@ -6,12 +6,31 @@ module Network.RpcSpec where
import Prelude
import Network.Rpc
import Test.Hspec
import Network.RpcSpec.ExampleApi
$(makeProtocol exampleApi)
$(makeClient exampleApi)
$(makeServer exampleApi)
$(do
let api = rpcApi "Example" [
rpcFunction "fixedHandler42" $ do
addArgument "arg" [t|Int|]
addResult "result" [t|Bool|]
setFixedHandler [| return . (== 42) |],
rpcFunction "fixedHandlerInc" $ do
addArgument "arg" [t|Int|]
addResult "result" [t|Int|]
setFixedHandler [| return . (+ 1) |],
rpcFunction "multiArgs" $ do
addArgument "one" [t|Int|]
addArgument "two" [t|Int|]
addArgument "three" [t|Bool|]
addResult "result" [t|Int|]
addResult "result2" [t|Bool|],
rpcFunction "noArgs" $ do
addResult "result" [t|Int|],
rpcFunction "noResponse" $ do
addArgument "arg" [t|Int|],
rpcFunction "noNothing" $ return ()
]
mconcat <$> sequence [makeProtocol api, makeClient api, makeServer api]
)
exampleProtocolImpl :: ExampleProtocolImpl
exampleProtocolImpl = ExampleProtocolImpl {
......
module Network.RpcSpec.ExampleApi where
import Prelude
import Network.Rpc
data Something = Something
exampleApi :: RpcApi
exampleApi = rpcApi "Example" [
rpcFunction "fixedHandler42" $ do
addArgument "arg" [t|Int|]
addResult "result" [t|Bool|]
setFixedHandler [| return . (== 42) |],
rpcFunction "fixedHandlerInc" $ do
addArgument "arg" [t|Int|]
addResult "result" [t|Int|]
setFixedHandler [| return . (+ 1) |],
rpcFunction "multiArgs" $ do
addArgument "one" [t|Int|]
addArgument "two" [t|Int|]
addArgument "three" [t|Bool|]
addResult "result" [t|Int|]
addResult "result2" [t|Bool|],
rpcFunction "noArgs" $ do
addResult "result" [t|Int|],
rpcFunction "noResponse" $ do
addArgument "arg" [t|Int|],
rpcFunction "noNothing" $ return ()
]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment