Skip to content

Commit b2d95bf

Browse files
fix: support complex and nested inner types (#2)
1 parent 5bcfc94 commit b2d95bf

File tree

3 files changed

+414
-13
lines changed

3 files changed

+414
-13
lines changed

src/__tests__/__snapshots__/markdown-helpers.spec.ts.snap

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,287 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`markdown-helpers rawTypeToTypeInformation() should map a Promise types correctly 1`] = `
4+
Object {
5+
"collection": false,
6+
"innerTypes": Array [
7+
Object {
8+
"collection": false,
9+
"type": "T",
10+
},
11+
],
12+
"type": "Promise",
13+
}
14+
`;
15+
16+
exports[`markdown-helpers rawTypeToTypeInformation() should map a complex Promise types correctly 1`] = `
17+
Object {
18+
"collection": false,
19+
"innerTypes": Array [
20+
Object {
21+
"collection": false,
22+
"type": Array [
23+
Object {
24+
"collection": false,
25+
"type": "T",
26+
},
27+
Object {
28+
"collection": false,
29+
"type": "A",
30+
},
31+
],
32+
},
33+
],
34+
"type": "Promise",
35+
}
36+
`;
37+
38+
exports[`markdown-helpers rawTypeToTypeInformation() should map a function return type + param types correctly 1`] = `
39+
Object {
40+
"collection": false,
41+
"parameters": Array [
42+
Object {
43+
"collection": false,
44+
"type": "P1",
45+
},
46+
Object {
47+
"collection": false,
48+
"type": "P2",
49+
},
50+
],
51+
"returns": Object {
52+
"collection": false,
53+
"type": "R",
54+
},
55+
"type": "Function",
56+
}
57+
`;
58+
59+
exports[`markdown-helpers rawTypeToTypeInformation() should map a function return type correctly 1`] = `
60+
Object {
61+
"collection": false,
62+
"parameters": Array [],
63+
"returns": Object {
64+
"collection": false,
65+
"type": "R",
66+
},
67+
"type": "Function",
68+
}
69+
`;
70+
71+
exports[`markdown-helpers rawTypeToTypeInformation() should map a function with complex return type + complex param types correctly 1`] = `
72+
Object {
73+
"collection": false,
74+
"parameters": Array [
75+
Object {
76+
"collection": false,
77+
"innerTypes": Array [
78+
Object {
79+
"collection": false,
80+
"type": "InnerP1",
81+
},
82+
Object {
83+
"collection": true,
84+
"type": "AnotherInnerP1",
85+
},
86+
],
87+
"type": "P1",
88+
},
89+
Object {
90+
"collection": false,
91+
"innerTypes": Array [
92+
Object {
93+
"collection": true,
94+
"type": Array [
95+
Object {
96+
"collection": false,
97+
"type": "InnerP2",
98+
},
99+
Object {
100+
"collection": false,
101+
"innerTypes": Array [
102+
Object {
103+
"collection": false,
104+
"type": "SuperDeepP2",
105+
},
106+
Object {
107+
"collection": false,
108+
"type": "EvenDeeperP2",
109+
},
110+
],
111+
"type": "AnotherInnerP2",
112+
},
113+
],
114+
},
115+
],
116+
"type": "P2",
117+
},
118+
],
119+
"returns": Object {
120+
"collection": false,
121+
"innerTypes": Array [
122+
Object {
123+
"collection": false,
124+
"type": "Foo",
125+
},
126+
],
127+
"type": "R",
128+
},
129+
"type": "Function",
130+
}
131+
`;
132+
133+
exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Function types correctly 1`] = `
134+
Object {
135+
"collection": false,
136+
"innerTypes": Array [
137+
Object {
138+
"collection": false,
139+
"type": Array [
140+
Object {
141+
"collection": false,
142+
"type": "T",
143+
},
144+
Object {
145+
"collection": true,
146+
"parameters": Array [],
147+
"returns": Object {
148+
"collection": true,
149+
"type": "A",
150+
},
151+
"type": "Function",
152+
},
153+
],
154+
},
155+
],
156+
"type": "Promise",
157+
}
158+
`;
159+
160+
exports[`markdown-helpers rawTypeToTypeInformation() should map a nested Promise types correctly 1`] = `
161+
Object {
162+
"collection": false,
163+
"innerTypes": Array [
164+
Object {
165+
"collection": false,
166+
"type": Array [
167+
Object {
168+
"collection": false,
169+
"type": "T",
170+
},
171+
Object {
172+
"collection": false,
173+
"innerTypes": Array [
174+
Object {
175+
"collection": false,
176+
"type": "A",
177+
},
178+
],
179+
"type": "Promise",
180+
},
181+
],
182+
},
183+
],
184+
"type": "Promise",
185+
}
186+
`;
187+
188+
exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex Promise types correctly 1`] = `
189+
Object {
190+
"collection": false,
191+
"innerTypes": Array [
192+
Object {
193+
"collection": false,
194+
"type": Array [
195+
Object {
196+
"collection": false,
197+
"type": "T",
198+
},
199+
Object {
200+
"collection": true,
201+
"innerTypes": Array [
202+
Object {
203+
"collection": true,
204+
"type": "A",
205+
},
206+
],
207+
"type": "Promise",
208+
},
209+
],
210+
},
211+
],
212+
"type": "Promise",
213+
}
214+
`;
215+
216+
exports[`markdown-helpers rawTypeToTypeInformation() should map a nested complex Promise types correctly 2`] = `
217+
Object {
218+
"collection": false,
219+
"innerTypes": Array [
220+
Object {
221+
"collection": false,
222+
"type": Array [
223+
Object {
224+
"collection": false,
225+
"type": "T",
226+
},
227+
Object {
228+
"collection": true,
229+
"innerTypes": Array [
230+
Object {
231+
"collection": true,
232+
"type": "A",
233+
},
234+
],
235+
"type": "Promise",
236+
},
237+
],
238+
},
239+
],
240+
"type": "Promise",
241+
}
242+
`;
243+
244+
exports[`markdown-helpers rawTypeToTypeInformation() should map a primitive types correctly 1`] = `
245+
Object {
246+
"collection": false,
247+
"type": "Boolean",
248+
}
249+
`;
250+
251+
exports[`markdown-helpers rawTypeToTypeInformation() should map a wrapped collection type correctly 1`] = `
252+
Object {
253+
"collection": false,
254+
"innerTypes": Array [
255+
Object {
256+
"collection": true,
257+
"type": Array [
258+
Object {
259+
"collection": false,
260+
"type": "T",
261+
},
262+
Object {
263+
"collection": false,
264+
"parameters": Array [],
265+
"returns": Object {
266+
"collection": true,
267+
"type": "A",
268+
},
269+
"type": "Function",
270+
},
271+
],
272+
},
273+
],
274+
"type": "Promise",
275+
}
276+
`;
277+
278+
exports[`markdown-helpers rawTypeToTypeInformation() should map an unknown types correctly 1`] = `
279+
Object {
280+
"collection": false,
281+
"type": "MyType",
282+
}
283+
`;
284+
3285
exports[`markdown-helpers safelyJoinTokens snapshots should be correct for basic-paragraph 1`] = `"This is just a basic paragraph. It has multiple sentences and natural soft breaks."`;
4286

5287
exports[`markdown-helpers safelyJoinTokens snapshots should be correct for blockquotes 1`] = `

src/__tests__/markdown-helpers.spec.ts

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as fs from 'fs';
22
import * as path from 'path';
33
import MarkdownIt from 'markdown-it';
44

5-
import { safelyJoinTokens, extractStringEnum } from '../markdown-helpers';
5+
import { safelyJoinTokens, extractStringEnum, rawTypeToTypeInformation } from '../markdown-helpers';
66

77
describe('markdown-helpers', () => {
88
describe('safelyJoinTokens', () => {
@@ -86,4 +86,62 @@ describe('markdown-helpers', () => {
8686
expect(values[2].value).toBe('c');
8787
});
8888
});
89+
90+
describe('rawTypeToTypeInformation()', () => {
91+
it('should map a primitive types correctly', () => {
92+
expect(rawTypeToTypeInformation('Boolean', '', null)).toMatchSnapshot();
93+
});
94+
95+
it('should map an unknown types correctly', () => {
96+
expect(rawTypeToTypeInformation('MyType', '', null)).toMatchSnapshot();
97+
});
98+
99+
it('should map a Promise types correctly', () => {
100+
expect(rawTypeToTypeInformation('Promise<T>', '', null)).toMatchSnapshot();
101+
});
102+
103+
it('should map a complex Promise types correctly', () => {
104+
expect(rawTypeToTypeInformation('Promise<T | A>', '', null)).toMatchSnapshot();
105+
});
106+
107+
it('should map a nested Promise types correctly', () => {
108+
expect(rawTypeToTypeInformation('Promise<T | Promise<A>>', '', null)).toMatchSnapshot();
109+
});
110+
111+
it('should map a nested complex Promise types correctly', () => {
112+
expect(rawTypeToTypeInformation('Promise<T | Promise<A[]>[]>', '', null)).toMatchSnapshot();
113+
});
114+
115+
it('should map a nested complex Promise types correctly', () => {
116+
expect(rawTypeToTypeInformation('Promise<T | Promise<A[]>[]>', '', null)).toMatchSnapshot();
117+
});
118+
119+
it('should map a nested Function types correctly', () => {
120+
expect(rawTypeToTypeInformation('Promise<T | Function<A[]>[]>', '', null)).toMatchSnapshot();
121+
});
122+
123+
it('should map a wrapped collection type correctly', () => {
124+
expect(
125+
rawTypeToTypeInformation('Promise<(T | Function<A[]>)[]>', '', null),
126+
).toMatchSnapshot();
127+
});
128+
129+
it('should map a function return type correctly', () => {
130+
expect(rawTypeToTypeInformation('Function<R>', '', null)).toMatchSnapshot();
131+
});
132+
133+
it('should map a function return type + param types correctly', () => {
134+
expect(rawTypeToTypeInformation('Function<P1, P2, R>', '', null)).toMatchSnapshot();
135+
});
136+
137+
it('should map a function with complex return type + complex param types correctly', () => {
138+
expect(
139+
rawTypeToTypeInformation(
140+
'Function<P1<InnerP1, AnotherInnerP1[]>, P2<(InnerP2 | AnotherInnerP2<SuperDeepP2, EvenDeeperP2>)[]>, R<Foo>>',
141+
'',
142+
null,
143+
),
144+
).toMatchSnapshot();
145+
});
146+
});
89147
});

0 commit comments

Comments
 (0)