From 066b06862dacc7adb935fc39e70a35efa2c55694 Mon Sep 17 00:00:00 2001 From: coffeepots Date: Fri, 23 Nov 2018 16:11:12 +0000 Subject: [PATCH] Add test for Option[T] where T is not a builtin --- tests/testrpcmacro.nim | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/testrpcmacro.nim b/tests/testrpcmacro.nim index c5f6dbb..2219922 100644 --- a/tests/testrpcmacro.nim +++ b/tests/testrpcmacro.nim @@ -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()