-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathparseRow.test.ts
More file actions
69 lines (65 loc) · 2.95 KB
/
parseRow.test.ts
File metadata and controls
69 lines (65 loc) · 2.95 KB
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
import * as assert from "https://deno.land/std@0.114.0/testing/asserts.ts";
import { parseRow } from "./parseRow.ts";
Deno.test("should return a valid result for vector", () => {
const a = parseRow("vector#1cb5c415 {t:Type} # [ t ] = Vector t;");
// asserts a should be {"name":"vector","id":481674261,"generic":{"genericDescriptor":[{"key":"t","type":"Type"}],"argsOrder":["t"]},"args":[]} key by key
assert.assertEquals(a.name, "vector");
assert.assertEquals(a.id, 481674261);
assert.assertEquals(a.generic.genericDescriptor[0].key, "t");
assert.assertEquals(
a.generic.genericDescriptor[0].type,
"Type",
);
assert.assertEquals(a.generic.argsOrder![0], "t");
assert.assertEquals(a.type, "Vector t");
assert.assertEquals(a.params.length, 0);
});
Deno.test("should return a valid result for other generics", () => {
const a = parseRow(
"initConnection#c1cd5ea9 {X:Type} flags:# api_id:int device_model:string system_version:string app_version:string system_lang_code:string lang_pack:string lang_code:string proxy:flags.0?InputClientProxy params:flags.1?JSONValue query:!X = X;",
);
assert.assertEquals(a, {
name: "initConnection",
id: -1043505495,
generic: { genericDescriptor: [{ key: "X", type: "Type" }] },
params: [
{ name: "flags", type: "#", index: 0, isOptional: false },
{ name: "api_id", type: "int", index: 1, isOptional: false },
{ name: "device_model", type: "string", index: 2, isOptional: false },
{ name: "system_version", type: "string", index: 3, isOptional: false },
{ name: "app_version", type: "string", index: 4, isOptional: false },
{ name: "system_lang_code", type: "string", index: 5, isOptional: false },
{ name: "lang_pack", type: "string", index: 6, isOptional: false },
{ name: "lang_code", type: "string", index: 7, isOptional: false },
{ name: "proxy", type: "InputClientProxy", index: 8, isOptional: true },
{ name: "params", type: "JSONValue", index: 9, isOptional: true },
{ name: "query", type: "X", index: 10, isOptional: false },
],
type: "X",
subclassOfId: 3081909835,
});
});
Deno.test("should return a valid result for non-generics", () => {
const a = parseRow(
"channels.getParticipants#77ced9d0 channel:InputChannel filter:ChannelParticipantsFilter offset:int limit:int hash:long = channels.ChannelParticipants;",
);
assert.assertEquals(a, {
name: "channels.getParticipants",
id: 2010044880,
generic: {},
params: [
{ name: "channel", type: "InputChannel", index: 0, isOptional: false },
{
name: "filter",
type: "ChannelParticipantsFilter",
index: 1,
isOptional: false,
},
{ name: "offset", type: "int", index: 2, isOptional: false },
{ name: "limit", type: "int", index: 3, isOptional: false },
{ name: "hash", type: "long", index: 4, isOptional: false },
],
type: "channels.ChannelParticipants",
subclassOfId: 3859443300,
});
});