mirror of
https://github.com/logos-storage/nim-json-rpc.git
synced 2026-01-08 08:33:14 +00:00
Add test for Option[T] where T is not a builtin
This commit is contained in:
parent
51ed6f3000
commit
066b06862d
@ -19,6 +19,9 @@ type
|
||||
MyOptional = object
|
||||
maybeInt: Option[int]
|
||||
|
||||
MyOptionalNotBuiltin = object
|
||||
val: Option[Test2]
|
||||
|
||||
let
|
||||
testObj = %*{
|
||||
"a": %1,
|
||||
@ -94,6 +97,9 @@ s.rpc("rpc.mixedOptionalArg") do(a: int, b: Option[int], c: string,
|
||||
result.d = d
|
||||
result.e = e
|
||||
|
||||
s.rpc("rpc.optionalArgNotBuiltin") do(obj: Option[MyOptionalNotBuiltin]) -> string:
|
||||
result = obj.get.val.get.y
|
||||
|
||||
# Tests
|
||||
suite "Server types":
|
||||
test "On macro registration":
|
||||
@ -187,12 +193,23 @@ suite "Server types":
|
||||
check r1 == %int1
|
||||
check r2 == %int2
|
||||
|
||||
test "mixed optional arg":
|
||||
test "Mixed optional arg":
|
||||
var ax = waitFor rpcMixedOptionalArg(%[%10, %11, %"hello", %12, %"world"])
|
||||
check ax == %OptionalFields(a: 10, b: some(11), c: "hello", d: some(12), e: some("world"))
|
||||
var bx = waitFor rpcMixedOptionalArg(%[%10, newJNull(), %"hello"])
|
||||
check bx == %OptionalFields(a: 10, c: "hello")
|
||||
|
||||
test "Non-built-in optional types":
|
||||
let
|
||||
testOptionalNonBuiltin = %*{
|
||||
"val": %*{
|
||||
"x": %[1, 2],
|
||||
"y": %"Hello"
|
||||
}
|
||||
}
|
||||
var r = waitFor rpcOptionalArgNotBuiltin(%[testOptionalNonBuiltin])
|
||||
check r == %"Hello"
|
||||
|
||||
s.stop()
|
||||
waitFor s.closeWait()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user