-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrpc_test.ts
72 lines (70 loc) · 1.76 KB
/
rpc_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { assertNode, assertNodeThrows } from "./testutil.ts";
import { RPC } from "./rpc.ts";
import { Type } from "./type.ts";
Deno.test("RPC", async () => {
const tt: [string, RPC][] = [
[
`rpc Foo (Req) returns (Res) {}`,
new RPC(
"Foo",
{ name: new Type("Req", [1, 10], [1, 12]) },
{ name: new Type("Res", [1, 24], [1, 26]) },
[],
[1, 1],
[1, 30],
),
],
[
`rpc Foo (Req) returns (Res);`,
new RPC(
"Foo",
{ name: new Type("Req", [1, 10], [1, 12]) },
{ name: new Type("Res", [1, 24], [1, 26]) },
null,
[1, 1],
[1, 28],
),
],
[
`rpc Foo (stream Req) returns (Res);`,
new RPC(
"Foo",
{ name: new Type("Req", [1, 17], [1, 19]), streaming: true },
{ name: new Type("Res", [1, 31], [1, 33]) },
null,
[1, 1],
[1, 35],
),
],
[
`rpc Foo (Req) returns (stream Res);`,
new RPC(
"Foo",
{ name: new Type("Req", [1, 10], [1, 12]) },
{ name: new Type("Res", [1, 31], [1, 33]), streaming: true },
null,
[1, 1],
[1, 35],
),
],
];
for (const t of tt) await assertNode(RPC, ...t);
});
Deno.test("RPC errors", async () => {
const tt: [string, string][] = [
[`rpc Foo (Req) returns (Res) {`, "unexpected eof on line 1, column 29"],
[
`rpc _foo {}`,
"unexpected token (_) on line 1, column 5; expected identifier",
],
[
`rpc 1foo {}`,
"unexpected int (1) on line 1, column 5; expected identifier",
],
[
`rpc foo.bar {}`,
"unexpected token (.) on line 1, column 8; expected identifier",
],
];
for (const t of tt) await assertNodeThrows(RPC, ...t);
});