You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it('should create aliasses for global enumerations',()=>{
153
+
constwriter=newGluaApiWriter();
154
+
constapi=writer.writePage(<Enum>{
155
+
type: 'enum',
156
+
name: 'MATERIAL_FOG',
157
+
address: 'Enums/MATERIAL_FOG',
158
+
description: 'The fog mode.',
159
+
realm: 'Client',
160
+
items: [
161
+
{
162
+
key: 'MATERIAL_FOG_NONE',
163
+
value: '0',
164
+
description: 'No fog',
165
+
},
166
+
{
167
+
key: 'MATERIAL_FOG_LINEAR',
168
+
value: '1',
169
+
description: 'Linear fog',
170
+
},
171
+
{
172
+
key: 'MATERIAL_FOG_LINEAR_BELOW_FOG_Z',
173
+
value: '-2147483648',// test large negative number
174
+
},
175
+
{
176
+
// Should be skipped
177
+
key: 'MATERIAL_FOG_NEW_FAKE',
178
+
value: 'TODO',
179
+
}
180
+
],
181
+
});
182
+
183
+
expect(api).toEqual(`---@alias MATERIAL_FOG 0|1|-2147483648\n--- No fog\nMATERIAL_FOG_NONE = 0\n--- Linear fog\nMATERIAL_FOG_LINEAR = 1\nMATERIAL_FOG_LINEAR_BELOW_FOG_Z = -2147483648\n\n\n`);
184
+
});
185
+
186
+
it('should create enums for table enumerations',()=>{
187
+
constwriter=newGluaApiWriter();
188
+
constapi=writer.writePage(<Enum>{
189
+
type: 'enum',
190
+
name: 'SCREENFADE',
191
+
address: 'Enums/SCREENFADE',
192
+
description: 'The screen fade mode.',
193
+
realm: 'Client',
194
+
items: [
195
+
{
196
+
key: '',
197
+
value: '0',
198
+
description: 'Instant fade in',
199
+
},
200
+
{
201
+
key: 'SCREENFADE.IN',
202
+
value: '1',
203
+
description: 'Instant fade in',
204
+
},
205
+
{
206
+
key: 'SCREENFADE.OUT',
207
+
value: '2',
208
+
description: 'Slowly fade in',
209
+
},
210
+
{
211
+
key: 'SCREENFADE.MODULATE',
212
+
value: '4',
213
+
},
214
+
{
215
+
key: 'SCREENFADE.STAYOUT',
216
+
value: '8',
217
+
description: 'Never disappear',
218
+
},
219
+
{
220
+
key: 'SCREENFADE.PURGE',
221
+
value: '16',
222
+
description: 'Used to purge all currently active screen fade effects...\nMultiple\nLines',
223
+
},
224
+
],
225
+
});
226
+
227
+
expect(api).toEqual(`---@enum SCREENFADE\n--- The screen fade mode.\nSCREENFADE = {\n --- Instant fade in\n IN = 1,\n --- Slowly fade in\n OUT = 2,\n MODULATE = 4,\n --- Never disappear\n STAYOUT = 8,\n --- Used to purge all currently active screen fade effects...\n --- Multiple\n --- Lines\n PURGE = 16,\n}\n\n`);
228
+
});
229
+
230
+
it('should convert table<type> to type[]',()=>{
231
+
constwriter=newGluaApiWriter();
232
+
constapi=writer.writePage(<LibraryFunction>{
233
+
name: 'GetBots',
234
+
address: 'player.GetBots',
235
+
parent: 'player',
236
+
dontDefineParent: true,
237
+
description: 'Returns a table of all bots on the server.',
238
+
realm: 'Shared',
239
+
type: 'libraryfunc',
240
+
url: 'na',
241
+
returns: [
242
+
{
243
+
type: 'table<Player>',
244
+
description: 'A table only containing bots ( AI / non human players )',
245
+
},
246
+
],
247
+
});
248
+
249
+
expect(api).toEqual(`---[SHARED] Returns a table of all bots on the server.\n---\n---[(View on wiki)](na)\n---@return Player[] # A table only containing bots ( AI / non human players )\nfunction player.GetBots() end\n\n`);
250
+
});
251
+
252
+
it('should not convert table<type,otherType> to type,otherType[]',()=>{
253
+
constwriter=newGluaApiWriter();
254
+
constapi=writer.writePage(<LibraryFunction>{
255
+
name: 'GetBots',
256
+
address: 'player.GetBots',
257
+
parent: 'player',
258
+
dontDefineParent: true,
259
+
description: 'Returns a table of all bots on the server.',
260
+
realm: 'Shared',
261
+
type: 'libraryfunc',
262
+
url: 'na',
263
+
returns: [
264
+
{
265
+
type: 'table<number,Player>',
266
+
description: 'A table only containing bots ( AI / non human players )',
267
+
},
268
+
],
269
+
});
270
+
271
+
expect(api).toEqual(`---[SHARED] Returns a table of all bots on the server.\n---\n---[(View on wiki)](na)\n---@return table<number,Player> # A table only containing bots ( AI / non human players )\nfunction player.GetBots() end\n\n`);
272
+
});
273
+
274
+
consttestFuncPart={
275
+
name: 'Fake',
276
+
address: 'test.Fake',
277
+
parent: 'test',
278
+
dontDefineParent: true,
279
+
description: 'Just for testing.',
280
+
realm: 'Shared',
281
+
type: 'libraryfunc',
282
+
url: 'na',
283
+
};
284
+
285
+
it.each([
286
+
// Simple case with an altType (deprecated in wiki)
287
+
{
288
+
api: <LibraryFunction>{
289
+
...testFuncPart,
290
+
arguments: [
291
+
{
292
+
args: [{
293
+
name: 'value',
294
+
type: 'string',
295
+
description: 'The value to fake.',
296
+
altType: 'number',
297
+
}]
298
+
}
299
+
],
300
+
},
301
+
output: `---[SHARED] Just for testing.\n---\n---[(View on wiki)](na)\n---@param value string|number The value to fake.\nfunction test.Fake(value) end\n\n`,
302
+
},
303
+
// Case with pipes in the type (prefered in wiki)
304
+
{
305
+
api: <LibraryFunction>{
306
+
...testFuncPart,
307
+
arguments: [
308
+
{
309
+
args: [{
310
+
name: 'value',
311
+
type: 'string|number',
312
+
description: 'The value to fake.',
313
+
}]
314
+
}
315
+
],
316
+
},
317
+
output: `---[SHARED] Just for testing.\n---\n---[(View on wiki)](na)\n---@param value string|number The value to fake.\nfunction test.Fake(value) end\n\n`,
318
+
},
319
+
// Case with pipes and table<x> conversion
320
+
{
321
+
api: <LibraryFunction>{
322
+
...testFuncPart,
323
+
arguments: [
324
+
{
325
+
args: [{
326
+
name: 'value',
327
+
type: 'string|table<number,Player>',
328
+
description: 'The value to fake.',
329
+
}]
330
+
}
331
+
],
332
+
},
333
+
output: `---[SHARED] Just for testing.\n---\n---[(View on wiki)](na)\n---@param value string|table<number,Player> The value to fake.\nfunction test.Fake(value) end\n\n`,
334
+
},
335
+
// Case with table<x> conversion in both altType and type
336
+
{
337
+
api: <LibraryFunction>{
338
+
...testFuncPart,
339
+
arguments: [
340
+
{
341
+
args: [{
342
+
name: 'value',
343
+
type: 'table<number,Player>',
344
+
description: 'The value to fake.',
345
+
altType: 'table<Entity,number>',
346
+
}]
347
+
}
348
+
],
349
+
},
350
+
output: `---[SHARED] Just for testing.\n---\n---[(View on wiki)](na)\n---@param value table<number,Player>|table<Entity,number> The value to fake.\nfunction test.Fake(value) end\n\n`,
// TODO: Currently unsupported. Remove 'failing' (and change test name) when supporting this. (low priority imo)
360
+
it.failing('should currently fail in complicated cases like `table<string|number>|string`.',()=>{
361
+
constwriter=newGluaApiWriter();
362
+
constapi=writer.writePage(<LibraryFunction>{
363
+
...testFuncPart,
364
+
arguments: [
365
+
{
366
+
args: [{
367
+
name: 'value',
368
+
type: 'table<string|number>|string',
369
+
description: 'The value to fake.',
370
+
}]
371
+
}
372
+
],
373
+
});
374
+
375
+
expect(api).toEqual(`---[SHARED] Just for testing.\n---\n---[(View on wiki)](na)\n---@param value table<string|number>|string The value to fake.\nfunction test.Fake(value) end\n\n`);
376
+
});
377
+
378
+
it('should support structure table type',()=>{
379
+
constwriter=newGluaApiWriter();
380
+
constapi=writer.writePage(<LibraryFunction>{
381
+
name: 'ToScreen',
382
+
address: 'Vector.ToScreen',
383
+
parent: 'Vector',
384
+
dontDefineParent: true,
385
+
description: 'Returns where on the screen the specified position vector would appear.',
386
+
realm: 'Client',
387
+
type: 'libraryfunc',
388
+
url: 'na',
389
+
returns: [
390
+
{
391
+
type: 'table{ToScreenData}',
392
+
description: 'The created Structures/ToScreenData.',
393
+
},
394
+
],
395
+
});
396
+
397
+
expect(api).toEqual(`---[CLIENT] Returns where on the screen the specified position vector would appear.\n---\n---[(View on wiki)](na)\n---@return ToScreenData # The created Structures/ToScreenData.\nfunction Vector.ToScreen() end\n\n`);
398
+
});
399
+
400
+
// number{ENUM_NAME} -> ENUM_NAME
401
+
it('should support enum type',()=>{
402
+
constwriter=newGluaApiWriter();
403
+
constapi=writer.writePage(<LibraryFunction>{
404
+
name: 'FogMode',
405
+
address: 'render.FogMode',
406
+
parent: 'render',
407
+
dontDefineParent: true,
408
+
description: 'Sets the fog mode.',
409
+
realm: 'Client',
410
+
type: 'libraryfunc',
411
+
url: 'na',
412
+
arguments: [
413
+
{
414
+
args: [{
415
+
name: 'mode',
416
+
type: 'number{MATERIAL_FOG}',
417
+
description: 'The fog mode.',
418
+
}]
419
+
}
420
+
],
421
+
});
422
+
423
+
expect(api).toEqual(`---[CLIENT] Sets the fog mode.\n---\n---[(View on wiki)](na)\n---@param mode MATERIAL_FOG The fog mode.\nfunction render.FogMode(mode) end\n\n`);
424
+
});
152
425
153
426
// it('should be able to write Annotated API files directly from wiki pages', async () => {
0 commit comments