Skip to content

Commit f11cfe0

Browse files
codebytereMarshallOfSound
authored andcommitted
fix: return type incorrectly checking periods (#26)
1 parent 110b288 commit f11cfe0

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

Diff for: src/__tests__/markdown-helpers.spec.ts

+74
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import MarkdownIt from 'markdown-it';
55
import {
66
safelyJoinTokens,
77
extractStringEnum,
8+
extractReturnType,
89
rawTypeToTypeInformation,
910
parseHeadingTags,
1011
findNextList,
@@ -366,6 +367,79 @@ foo`),
366367
});
367368
});
368369

370+
describe('extractReturnType()', () => {
371+
it('should handle simple return types with descriptions', () => {
372+
const intTokens = getTokens(`Returns \`Integer\` - The request id used for the request.`);
373+
const intRet = extractReturnType(intTokens);
374+
expect(intRet.parsedReturnType).toEqual({
375+
collection: false,
376+
type: 'Integer',
377+
});
378+
379+
const stringTokens = getTokens(`Returns \`String\` - Returns the WebRTC IP Handling Policy.`);
380+
const stringRet = extractReturnType(stringTokens);
381+
expect(stringRet.parsedReturnType).toEqual({
382+
collection: false,
383+
possibleValues: null,
384+
type: 'String',
385+
});
386+
});
387+
388+
it('should handle Promises with void inner types', () => {
389+
const promiseTokens = getTokens(
390+
`Returns \`Promise<void>\` - Indicates whether the snapshot has been created successfully.`,
391+
);
392+
const promiseRet = extractReturnType(promiseTokens);
393+
expect(promiseRet.parsedReturnType).toEqual({
394+
collection: false,
395+
innerTypes: [
396+
{
397+
collection: false,
398+
type: 'void',
399+
},
400+
],
401+
type: 'Promise',
402+
});
403+
});
404+
405+
it('should handle Promises with non-void inner types', () => {
406+
const promiseTokens = getTokens(
407+
`Returns \`Promise<Buffer>\` - Resolves with the generated PDF data.`,
408+
);
409+
const promiseRet = extractReturnType(promiseTokens);
410+
expect(promiseRet.parsedReturnType).toEqual({
411+
collection: false,
412+
innerTypes: [
413+
{
414+
collection: false,
415+
type: 'Buffer',
416+
},
417+
],
418+
type: 'Promise',
419+
});
420+
});
421+
422+
it('should handle custom return types', () => {
423+
const customTokens = getTokens(
424+
`Returns \`WebContents\` - A WebContents instance with the given ID.`,
425+
);
426+
const customRet = extractReturnType(customTokens);
427+
expect(customRet.parsedReturnType).toEqual({
428+
collection: false,
429+
type: 'WebContents',
430+
});
431+
});
432+
433+
it('should handle return types with no descriptions', () => {
434+
const printerTokens = getTokens(`Returns [\`PrinterInfo[]\`](structures/printer-info.md)`);
435+
const printerRet = extractReturnType(printerTokens);
436+
expect(printerRet.parsedReturnType).toEqual({
437+
collection: true,
438+
type: 'PrinterInfo',
439+
});
440+
});
441+
});
442+
369443
describe('getTopLevelGenericType()', () => {
370444
it('should return null if there is no generic in the type', () => {
371445
expect(getTopLevelGenericType('Foo')).toEqual(null);

Diff for: src/markdown-helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ export const extractReturnType = (
442442
}
443443

444444
const returnsWithNewLineMatch = description.match(
445-
new RegExp(`${prefix} \`([^\`]+?)\`:?(\. |\n|$)`),
445+
new RegExp(`${prefix} \`([^\`]+?)\`:?(\. |\.\n|\n|$)`),
446446
);
447447
const returnsWithHyphenMatch = description.match(new RegExp(`${prefix} \`([^\`]+?)\` - `));
448448
const returnsWithContinousSentence = description.match(new RegExp(`${prefix} \`([^\`]+?)\` `));

0 commit comments

Comments
 (0)