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
Copy file name to clipboardExpand all lines: __tests__/api-writer/glua-api-writer.spec.ts
+70Lines changed: 70 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -423,6 +423,76 @@ describe('GLua API Writer', () => {
423
423
expect(api).toEqual(`--- Sets the fog mode.\n---\n---[View wiki](na)\n---@param mode MATERIAL_FOG The fog mode.\nfunction render.FogMode(mode) end\n\n`);
424
424
});
425
425
426
+
it('should parse functions with callbacks correctly',()=>{
427
+
constwriter=newGluaApiWriter();
428
+
constapi=writer.writePage(<LibraryFunction>{
429
+
name: 'Generate',
430
+
address: 'sound.Generate',
431
+
parent: 'sound',
432
+
dontDefineParent: true,
433
+
description: 'Creates a sound from a function.',
434
+
realm: 'client',
435
+
type: 'libraryfunc',
436
+
url: 'na',
437
+
arguments: [
438
+
{
439
+
args: [
440
+
{
441
+
name: 'indentifier',
442
+
type: 'string',
443
+
description: 'An unique identified for the sound.'
444
+
},
445
+
{
446
+
name: 'samplerate',
447
+
type: 'number',
448
+
description: 'The sample rate of the sound. Must be `11025`, `22050` or `44100`.'
449
+
},
450
+
{
451
+
name: 'length',
452
+
type: 'number',
453
+
description: 'The length in seconds of the sound to generate.'
454
+
},
455
+
{
456
+
name: 'callbackOrData',
457
+
type: 'function',
458
+
altType: 'table',
459
+
description: "A function which will be called to generate every sample on the sound.",
460
+
callback: {
461
+
arguments: [
462
+
{
463
+
name: 'sampleIndex',
464
+
type: 'number',
465
+
description: 'The current sample number.'
466
+
}
467
+
],
468
+
returns: [
469
+
{
470
+
name: 'sampleValue',
471
+
type: 'number',
472
+
description: 'The return value must be between `-1.0` and `1.0`.'
473
+
},
474
+
{
475
+
name: 'fake',
476
+
type: 'string',
477
+
},
478
+
],
479
+
},
480
+
},
481
+
{
482
+
name: 'loopStart',
483
+
type: 'number',
484
+
description: 'Sample ID of the loop start. If given, the sound will be looping and will restart playing at given position after reaching its end.',
485
+
default: 'nil'
486
+
},
487
+
],
488
+
},
489
+
],
490
+
returns: [],
491
+
});
492
+
493
+
expect(api).toEqual(`--- Creates a sound from a function.\n---\n---[View wiki](na)\n---@param indentifier string An unique identified for the sound.\n---@param samplerate number The sample rate of the sound. Must be \`11025\`, \`22050\` or \`44100\`.\n---@param length number The length in seconds of the sound to generate.\n---@param callbackOrData fun(sampleIndex: number):(sampleValue: number, fake: string)|table A function which will be called to generate every sample on the sound.\n---@param loopStart? number Sample ID of the loop start. If given, the sound will be looping and will restart playing at given position after reaching its end.\nfunction sound.Generate(indentifier, samplerate, length, callbackOrData, loopStart) end\n\n`);
494
+
});
495
+
426
496
// it('should be able to write Annotated API files directly from wiki pages', async () => {
<description>Returns the function to create an vgui element for a specified content type, previously defined by <page>spawnmenu.AddContentType</page>.</description>
description: 'Returns the function to create an vgui element for a specified content type, previously defined by [spawnmenu.AddContentType](https://wiki.facepunch.com/gmod/spawnmenu.AddContentType).',
29
+
realm: 'client',
30
+
arguments: [
31
+
{
32
+
args: [{
33
+
altType: undefined,
34
+
callback: undefined,
35
+
name: 'contentType',
36
+
type: 'string',
37
+
description: 'The content type name.',
38
+
}]},
39
+
],
40
+
returns: [
41
+
{
42
+
callback: {
43
+
arguments: [
44
+
{
45
+
default: undefined,
46
+
description: 'The container panel to parent the created icon to.',
47
+
name: 'container',
48
+
type: 'Panel',
49
+
},
50
+
{
51
+
default: undefined,
52
+
description: 'Data for the content type passed from spawnmenu.CreateContentIcon.',
53
+
name: 'data',
54
+
type: 'table',
55
+
},
56
+
],
57
+
returns: [
58
+
{
59
+
default: undefined,
60
+
description: 'The created panel',
61
+
name: 'pnl',
62
+
type: 'Panel',
63
+
},
64
+
],
65
+
},
66
+
description: 'The panel creation function.\n\n\n\nFunction argument(s):\n* Panel `container` - The container panel to parent the created icon to.\n* table `data` - Data for the content type passed from spawnmenu.CreateContentIcon.\n\nFunction return value(s):\n* Panel `pnl` - The created panel\n\n',
0 commit comments