Skip to content

Commit be86710

Browse files
authored
Merge pull request #83 from luttje/bugfix/backlog
Fixing issues in backlog
2 parents 55a6152 + 62e932d commit be86710

File tree

9 files changed

+332
-136
lines changed

9 files changed

+332
-136
lines changed

__tests__/api-writer/glua-api-writer.spec.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { apiDefinition as structApiDefinition, markup as structMarkup, json as s
66
import { markup as panelMarkup, apiDefinition as panelApiDefinition } from '../test-data/offline-sites/gmod-wiki/panel-slider';
77
import { markup as multiReturnFuncMarkup, apiDefinition as multiReturnFuncApiDefinition } from '../test-data/offline-sites/gmod-wiki/library-function-concommand-gettable';
88
import { markup as varargsFuncMarkup, apiDefinition as varargsFuncApiDefinition } from '../test-data/offline-sites/gmod-wiki/library-function-coroutine-resume';
9-
import { Enum, LibraryFunction, WikiPage, WikiPageMarkupScraper } from '../../src/scrapers/wiki-page-markup-scraper';
9+
import { Enum, LibraryFunction, PanelFunction, WikiPage, WikiPageMarkupScraper } from '../../src/scrapers/wiki-page-markup-scraper';
1010
import { GluaApiWriter } from '../../src/api-writer/glua-api-writer';
1111
import fetchMock from "jest-fetch-mock";
1212

@@ -107,12 +107,12 @@ describe('GLua API Writer', () => {
107107
url: 'na',
108108
arguments: [
109109
{
110-
args: [ {
110+
args: [{
111111
name: 'intensity',
112112
type: 'number',
113113
description: 'The intensity of the explosion.',
114114
default: '1000',
115-
} ]
115+
}]
116116
}
117117
],
118118
returns: [
@@ -397,6 +397,28 @@ describe('GLua API Writer', () => {
397397
expect(api).toEqual(`---![(Client)](https://github.com/user-attachments/assets/a5f6ba64-374d-42f0-b2f4-50e5c964e808) Returns where on the screen the specified position vector would appear.\n---\n---[View wiki](na)\n---@return ToScreenData # The created Structures/ToScreenData.\nfunction Vector.ToScreen() end\n\n`);
398398
});
399399

400+
it('should support Panel type', () => {
401+
const writer = new GluaApiWriter();
402+
const api = writer.writePage(<PanelFunction>{
403+
name: 'GetVBar',
404+
address: 'DScrollPanel.GetVBar',
405+
parent: 'DScrollPanel',
406+
isPanelFunction: 'yes',
407+
description: 'Returns the vertical scroll bar of the panel.',
408+
realm: 'client',
409+
type: 'panelfunc',
410+
url: 'na',
411+
returns: [
412+
{
413+
type: 'Panel{DVScrollBar}',
414+
description: 'The DVScrollBar.',
415+
},
416+
],
417+
});
418+
419+
expect(api).toEqual(`---![(Client)](https://github.com/user-attachments/assets/a5f6ba64-374d-42f0-b2f4-50e5c964e808) Returns the vertical scroll bar of the panel.\n---\n---[View wiki](na)\n---@return DVScrollBar # The DVScrollBar.\nfunction DScrollPanel:GetVBar() end\n\n`);
420+
});
421+
400422
// number{ENUM_NAME} -> ENUM_NAME
401423
it('should support enum type', () => {
402424
const writer = new GluaApiWriter();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { markdownifyDescription } from '../../src/scrapers/wiki-page-markup-scraper';
2+
import * as cheerio from 'cheerio';
3+
4+
describe('markdownifyDescription', () => {
5+
it('should handle spaces in links', async () => {
6+
const textWithUrl = '<test>This is a <page>link with spaces</page>.</test>';
7+
const $ = cheerio.load(textWithUrl, { xmlMode: true });
8+
const result = markdownifyDescription($, $('test'));
9+
10+
expect(result).toBe(
11+
'This is a [link with spaces](https://wiki.facepunch.com/gmod/link_with_spaces).'
12+
);
13+
});
14+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { GluaApiWriter } from '../../src/api-writer/glua-api-writer';
2+
3+
describe('writeType', () => {
4+
describe('callback functions', () => {
5+
it('should write parameter names', async () => {
6+
const result = GluaApiWriter.transformType('function', {
7+
arguments: [
8+
{ type: 'number', name: 'count' },
9+
{ type: 'string', name: 'total' },
10+
],
11+
returns: [
12+
{ type: 'number', name: 'sum' },
13+
{ type: 'string', name: 'limit' },
14+
],
15+
});
16+
17+
expect(result).toEqual('fun(count: number, total: string):(sum: number, limit: string)');
18+
});
19+
20+
it('should write ret1, ret2, etc when parameter names are missing', async () => {
21+
const result = GluaApiWriter.transformType('function', {
22+
arguments: [
23+
{ type: 'number', name: 'count' },
24+
{ type: 'string', name: '' },
25+
],
26+
returns: [
27+
{ type: 'number', name: '' },
28+
{ type: 'string', name: '' },
29+
],
30+
});
31+
32+
expect(result).toEqual('fun(count: number, arg1: string):(ret0: number, ret1: string)');
33+
});
34+
});
35+
});

__tests__/test-data/offline-sites/gmod-wiki/panel-slider.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ end
3737
</example>`;
3838

3939
export const apiDefinition =
40-
`---
41-
---
42-
---
43-
--- A simple slider featuring an numeric display.
44-
---
40+
`--- A simple slider featuring an numeric display.
4541
---@deprecated Panel:SetActionFunction and Panel:PostMessage. Use DNumSlider instead.
4642
---@class Slider : Panel
4743
local Slider = {}\n\n`;

__tests__/test-data/offline-sites/gmod-wiki/struct-custom-entity-fields.ts

Lines changed: 91 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,10 @@ This can also be set from map, see <page>Sandbox Specific Mapping</page></item>
4747
</structure>`;
4848

4949
export const apiDefinition =
50-
`---
51-
--- Information about custom fields **all** entities can have.
50+
`--- Information about custom fields **all** entities can have.
5251
---
5352
--- See also [Structures/ENT](https://wiki.facepunch.com/gmod/Structures/ENT)
5453
---
55-
---
5654
---[View wiki](https://wiki.facepunch.com/gmod/Custom_Entity_Fields)
5755
---@class Custom_Entity_Fields
5856
local Custom_Entity_Fields = {}
@@ -136,94 +134,94 @@ Custom_Entity_Fields.m_RenderOrigin = nil
136134
Custom_Entity_Fields.m_RenderAngles = nil\n\n`;
137135

138136
export const json = {
139-
name: 'Custom_Entity_Fields',
140-
address: 'Custom_Entity_Fields',
141-
type: 'struct',
142-
fields: [
143-
{
144-
name: 'GetEntityDriveMode',
145-
type: 'function',
146-
description: '`Serverside`, Sandbox and Sandbox derived only.\n\nCalled by the Drive property to override the default drive type, which is `drive_sandbox`.',
147-
},
148-
{
149-
name: 'OnEntityCopyTableFinish',
150-
type: 'function',
151-
description: 'Documented at ENTITY:OnEntityCopyTableFinish.',
152-
},
153-
{
154-
name: 'PostEntityCopy',
155-
type: 'function',
156-
description: 'Documented at ENTITY:PostEntityCopy.',
157-
},
158-
{
159-
name: 'PostEntityPaste',
160-
type: 'function',
161-
description: 'Documented at ENTITY:PostEntityPaste.',
162-
},
163-
{
164-
name: 'PreEntityCopy',
165-
type: 'function',
166-
description: 'Documented at ENTITY:PreEntityCopy.',
167-
},
168-
{
169-
name: 'OnDuplicated',
170-
type: 'function',
171-
description: 'Documented at ENTITY:OnDuplicated.',
172-
},
173-
{
174-
name: 'PhysgunDisabled',
175-
type: 'boolean',
176-
description: '`Shared`, Sandbox or Sandbox derived only.\n\nIf set to `true`, physgun will not be able to pick this entity up. This can also be set from map, see Sandbox Specific Mapping',
177-
},
178-
{
179-
name: 'PhysgunPickup',
180-
type: 'function',
181-
description: '`Shared`, Sandbox or Sandbox derived only.\n\nCalled from GM:PhysgunPickup, overrides `PhysgunDisabled`',
182-
},
183-
{
184-
name: 'm_tblToolsAllowed',
185-
type: 'table',
186-
description: '`Shared`, Sandbox or Sandbox derived only.\n\nControls which tools **and** properties can be used on this entity. Format is a list of strings where each string is the tool or property classname.\n\nThis can also be set from map, see Sandbox Specific Mapping',
187-
},
188-
{
189-
name: 'GravGunPickupAllowed',
190-
type: 'function',
191-
description: 'Documented at ENTITY:GravGunPickupAllowed.',
192-
},
193-
{
194-
name: 'GravGunPunt',
195-
type: 'function',
196-
description: 'Documented at ENTITY:GravGunPunt.',
197-
},
198-
{
199-
name: 'CanProperty',
200-
type: 'function',
201-
description: 'Documented at ENTITY:CanProperty.',
202-
},
203-
{
204-
name: 'CanTool',
205-
type: 'function',
206-
description: 'Documented at ENTITY:CanTool.',
207-
},
208-
{
209-
name: 'CalcAbsolutePosition',
210-
type: 'function',
211-
description: 'Documented at ENTITY:CalcAbsolutePosition.',
212-
},
213-
{
214-
name: 'RenderOverride',
215-
type: 'function',
216-
description: 'Documented at ENTITY:RenderOverride.',
217-
},
218-
{
219-
name: 'm_RenderOrigin',
220-
type: 'Vector',
221-
description: '(Clientside) Do not use.',
222-
},
223-
{
224-
name: 'm_RenderAngles',
225-
type: 'Angle',
226-
description: '(Clientside) Do not use.',
227-
},
228-
],
137+
name: 'Custom_Entity_Fields',
138+
address: 'Custom_Entity_Fields',
139+
type: 'struct',
140+
fields: [
141+
{
142+
name: 'GetEntityDriveMode',
143+
type: 'function',
144+
description: '`Serverside`, Sandbox and Sandbox derived only.\n\nCalled by the Drive property to override the default drive type, which is `drive_sandbox`.',
145+
},
146+
{
147+
name: 'OnEntityCopyTableFinish',
148+
type: 'function',
149+
description: 'Documented at ENTITY:OnEntityCopyTableFinish.',
150+
},
151+
{
152+
name: 'PostEntityCopy',
153+
type: 'function',
154+
description: 'Documented at ENTITY:PostEntityCopy.',
155+
},
156+
{
157+
name: 'PostEntityPaste',
158+
type: 'function',
159+
description: 'Documented at ENTITY:PostEntityPaste.',
160+
},
161+
{
162+
name: 'PreEntityCopy',
163+
type: 'function',
164+
description: 'Documented at ENTITY:PreEntityCopy.',
165+
},
166+
{
167+
name: 'OnDuplicated',
168+
type: 'function',
169+
description: 'Documented at ENTITY:OnDuplicated.',
170+
},
171+
{
172+
name: 'PhysgunDisabled',
173+
type: 'boolean',
174+
description: '`Shared`, Sandbox or Sandbox derived only.\n\nIf set to `true`, physgun will not be able to pick this entity up. This can also be set from map, see Sandbox Specific Mapping',
175+
},
176+
{
177+
name: 'PhysgunPickup',
178+
type: 'function',
179+
description: '`Shared`, Sandbox or Sandbox derived only.\n\nCalled from GM:PhysgunPickup, overrides `PhysgunDisabled`',
180+
},
181+
{
182+
name: 'm_tblToolsAllowed',
183+
type: 'table',
184+
description: '`Shared`, Sandbox or Sandbox derived only.\n\nControls which tools **and** properties can be used on this entity. Format is a list of strings where each string is the tool or property classname.\n\nThis can also be set from map, see Sandbox Specific Mapping',
185+
},
186+
{
187+
name: 'GravGunPickupAllowed',
188+
type: 'function',
189+
description: 'Documented at ENTITY:GravGunPickupAllowed.',
190+
},
191+
{
192+
name: 'GravGunPunt',
193+
type: 'function',
194+
description: 'Documented at ENTITY:GravGunPunt.',
195+
},
196+
{
197+
name: 'CanProperty',
198+
type: 'function',
199+
description: 'Documented at ENTITY:CanProperty.',
200+
},
201+
{
202+
name: 'CanTool',
203+
type: 'function',
204+
description: 'Documented at ENTITY:CanTool.',
205+
},
206+
{
207+
name: 'CalcAbsolutePosition',
208+
type: 'function',
209+
description: 'Documented at ENTITY:CalcAbsolutePosition.',
210+
},
211+
{
212+
name: 'RenderOverride',
213+
type: 'function',
214+
description: 'Documented at ENTITY:RenderOverride.',
215+
},
216+
{
217+
name: 'm_RenderOrigin',
218+
type: 'Vector',
219+
description: '(Clientside) Do not use.',
220+
},
221+
{
222+
name: 'm_RenderAngles',
223+
type: 'Angle',
224+
description: '(Clientside) Do not use.',
225+
},
226+
],
229227
};

__tests__/utils/string.spec.ts

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { removeNewlines, toLowerCamelCase, putCommentBeforeEachLine, safeFileName } from '../../src/utils/string';
1+
import { removeNewlines, toLowerCamelCase, wrapInComment, safeFileName, unindentText } from '../../src/utils/string';
22

33
describe('toLowerCamelCase', () => {
44
it('should convert a string to lowerCamelCase', () => {
@@ -35,21 +35,74 @@ describe('putCommentBeforeEachLine', () => {
3535
['hello\n\n\n\nworld', '--- hello\n---\n--- world'],
3636
['hello\r\n\r\n\r\n\r\nworld', '--- hello\n---\n--- world'],
3737
])('should put a comment before each line', (input, expected, skipFirstLine = false) => {
38-
expect(putCommentBeforeEachLine(input, skipFirstLine)).toBe(expected);
38+
expect(wrapInComment(input, skipFirstLine)).toBe(expected);
39+
});
40+
});
41+
42+
describe('wrapInComment', () => {
43+
it.each([
44+
[
45+
`The following specifiers are exclusive to LuaJIT:
46+
47+
| Format | Description | Example of the output |
48+
|:------:|:-----------:|:---------------------:|
49+
| %p | Returns pointer to supplied structure (table/function) | \`0xf20a8968\` |
50+
| %q | Formats a string between double quotes, using escape sequences when necessary to ensure that it can safely be read back by the Lua interpreter | \`"test\\1\\2test"\` |`,
51+
`The following specifiers are exclusive to LuaJIT:
52+
--[[
53+
54+
| Format | Description | Example of the output |
55+
|:------:|:-----------:|:---------------------:|
56+
| %p | Returns pointer to supplied structure (table/function) | \`0xf20a8968\` |
57+
| %q | Formats a string between double quotes, using escape sequences when necessary to ensure that it can safely be read back by the Lua interpreter | \`"test\\1\\2test"\` |
58+
--]]`,
59+
true,
60+
],
61+
[
62+
`The following specifiers are exclusive to LuaJIT:
63+
64+
| Format | Description | Example of the output |
65+
| ------ | ----------- | --------------------- |
66+
| %p | Returns pointer to supplied structure (table/function) | \`0xf20a8968\` |
67+
| %q | Formats a string between double quotes, using escape sequences when necessary to ensure that it can safely be read back by the Lua interpreter | \`"test\\1\\2test"\` |`,
68+
`--[[
69+
The following specifiers are exclusive to LuaJIT:
70+
71+
| Format | Description | Example of the output |
72+
| ------ | ----------- | --------------------- |
73+
| %p | Returns pointer to supplied structure (table/function) | \`0xf20a8968\` |
74+
| %q | Formats a string between double quotes, using escape sequences when necessary to ensure that it can safely be read back by the Lua interpreter | \`"test\\1\\2test"\` |
75+
--]]`,
76+
],
77+
])('should put a comment before each line', (input, expected, skipFirstLine = false) => {
78+
expect(wrapInComment(input, skipFirstLine)).toBe(expected);
3979
});
4080
});
4181

4282
describe('safeFileName', () => {
4383
it.each([
44-
['hello world','hello world'],
84+
['hello world', 'hello world'],
4585
['hello:World', 'hello_World'],
4686
['hello:World', 'hello-World', '-'],
4787
['hello:World', 'helloWorld', ''],
4888
['hello:World', 'hello World', ' '],
49-
])('should make a string "%s" safe ("%s") for use as a file name', (input: string, expected: string, replacement: string|undefined = undefined) => {
89+
])('should make a string "%s" safe ("%s") for use as a file name', (input: string, expected: string, replacement: string | undefined = undefined) => {
5090
if (replacement !== undefined)
5191
expect(safeFileName(input, replacement)).toBe(expected);
5292
else
5393
expect(safeFileName(input)).toBe(expected);
5494
});
5595
});
96+
97+
describe('unindentText', () => {
98+
it.each([
99+
['hello\nworld', 'hello\nworld'],
100+
[' hello\n world', 'hello\nworld'],
101+
[' hello\n world', 'hello\nworld'],
102+
['\thello\n\tworld', 'hello\nworld'],
103+
['\thello\n\t world', 'hello\n world'],
104+
['\t\thello\n\t\tworld', 'hello\nworld'],
105+
])('should unindent text by the given amount', (input, expected) => {
106+
expect(unindentText(input)).toBe(expected);
107+
});
108+
});

0 commit comments

Comments
 (0)