Skip to content

Commit f5d5caa

Browse files
fix: support double quote string enum
1 parent 0a1bd84 commit f5d5caa

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

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

+59
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,65 @@ def fn():
260260
});
261261
});
262262

263+
describe('with double quotes', () => {
264+
it('should extract an enum of the format "can be x"', () => {
265+
const values = extractStringEnum(`Can be "x"`)!;
266+
expect(values).not.toBe(null);
267+
expect(values).toHaveLength(1);
268+
expect(values[0].value).toBe('x');
269+
});
270+
271+
it('should extract an enum of the format "can be x or y"', () => {
272+
const values = extractStringEnum(`Can be "x" or "y"`)!;
273+
expect(values).not.toBe(null);
274+
expect(values).toHaveLength(2);
275+
expect(values[0].value).toBe('x');
276+
expect(values[1].value).toBe('y');
277+
});
278+
279+
it('should extract an enum of the format "can be x, y or z"', () => {
280+
const values = extractStringEnum(`Can be "x", "y" or "z"`)!;
281+
expect(values).not.toBe(null);
282+
expect(values).toHaveLength(3);
283+
expect(values[0].value).toBe('x');
284+
expect(values[1].value).toBe('y');
285+
expect(values[2].value).toBe('z');
286+
});
287+
288+
it('should extract an enum of the format "can be x, y, or z"', () => {
289+
const values = extractStringEnum(`Can be "x", "y", or "z"`)!;
290+
expect(values).not.toBe(null);
291+
expect(values).toHaveLength(3);
292+
expect(values[0].value).toBe('x');
293+
expect(values[1].value).toBe('y');
294+
expect(values[2].value).toBe('z');
295+
});
296+
297+
it('should extract an enum of the format "values include a', () => {
298+
const values = extractStringEnum(`Values include "a"`)!;
299+
expect(values).not.toBe(null);
300+
expect(values).toHaveLength(1);
301+
expect(values[0].value).toBe('a');
302+
});
303+
304+
it('should extract an enum of the format "values include a and b', () => {
305+
const values = extractStringEnum(`Values include "a" and "b"`)!;
306+
expect(values).not.toBe(null);
307+
expect(values).toHaveLength(2);
308+
expect(values[0].value).toBe('a');
309+
expect(values[1].value).toBe('b');
310+
});
311+
312+
it('should extract an enum of the format "values include a, b and c', () => {
313+
const values = extractStringEnum(`Values include "a", "b" and "c"`)!;
314+
expect(values).not.toBe(null);
315+
expect(values).toHaveLength(3);
316+
expect(values[0].value).toBe('a');
317+
expect(values[1].value).toBe('b');
318+
expect(values[2].value).toBe('c');
319+
});
320+
});
321+
263322
describe('rawTypeToTypeInformation()', () => {
264323
it('should map a primitive types correctly', () => {
265324
expect(rawTypeToTypeInformation('Boolean', '', null)).toMatchSnapshot();

Diff for: src/markdown-helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,11 @@ export enum StripReturnTypeBehavior {
456456
export const extractStringEnum = (description: string): PossibleStringValue[] | null => {
457457
const possibleValues: PossibleStringValue[] = [];
458458

459-
const inlineValuesPattern = /(?:can be|values? includes?) ((?:(?:[`|'][a-zA-Z0-9-_\.:]+[`|'])(?:(, | )?))*(?:(?:or|and) [`|'][a-zA-Z0-9-_\.:]+[`|'])?)/i;
459+
const inlineValuesPattern = /(?:can be|values? includes?) ((?:(?:[`"'][a-zA-Z0-9-_\.:]+[`"'])(?:(, | )?))*(?:(?:or|and) [`"'][a-zA-Z0-9-_\.:]+[`"'])?)/i;
460460
const inlineMatch = inlineValuesPattern.exec(description);
461461
if (inlineMatch) {
462462
const valueString = inlineMatch[1];
463-
const valuePattern = /[`|']([a-zA-Z0-9-_\.:]+)[`|']/g;
463+
const valuePattern = /[`"']([a-zA-Z0-9-_\.:]+)[`"']/g;
464464
let value = valuePattern.exec(valueString);
465465

466466
while (value) {

0 commit comments

Comments
 (0)