/
issueTests.ts
381 lines (329 loc) · 11.3 KB
/
issueTests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
import { deepStrictEqual as equal, ok } from "assert";
import {
DeclarationReflection,
ProjectReflection,
QueryType,
ReflectionKind,
SignatureReflection,
ReflectionType,
Comment,
CommentTag,
UnionType,
} from "../lib/models";
import { getConverter2App } from "./programs";
import type { TestLogger } from "./TestLogger";
function query(project: ProjectReflection, name: string) {
const reflection = project.getChildByName(name);
ok(reflection instanceof DeclarationReflection, `Failed to find ${name}`);
return reflection;
}
export const issueTests: {
[issue: string]: (project: ProjectReflection, logger: TestLogger) => void;
} = {
gh869(project) {
const classFoo = project.children?.find(
(r) => r.name === "Foo" && r.kind === ReflectionKind.Class
);
ok(classFoo instanceof DeclarationReflection);
equal(
classFoo.children?.find((r) => r.name === "x"),
undefined
);
const nsFoo = project.children?.find(
(r) => r.name === "Foo" && r.kind === ReflectionKind.Namespace
);
ok(nsFoo instanceof DeclarationReflection);
ok(nsFoo.children?.find((r) => r.name === "x"));
},
gh1124(project) {
equal(
project.children?.length,
1,
"Namespace with type and value converted twice"
);
},
gh1150(project) {
const refl = query(project, "IntersectFirst");
equal(refl?.kind, ReflectionKind.TypeAlias);
equal(refl.type?.type, "indexedAccess");
},
gh1164(project) {
const refl = query(project, "gh1164");
equal(
refl.signatures?.[0]?.parameters?.[0]?.comment?.shortText,
"{@link CommentedClass} Test description."
);
equal(refl.signatures?.[0]?.comment?.returns, "Test description.\n");
},
gh1215(project) {
const foo = query(project, "Foo.bar");
ok(foo.setSignature instanceof SignatureReflection);
equal(foo.setSignature.type?.toString(), "void");
},
gh1255(project) {
const foo = query(project, "C.foo");
equal(foo.comment?.shortText, "Docs!");
},
gh1330(project) {
const example = query(project, "ExampleParam");
equal(example?.type?.type, "reference");
equal(example.type.toString(), "Example");
},
gh1366(project) {
const foo = query(project, "GH1366.Foo");
equal(foo.kind, ReflectionKind.Reference);
},
gh1408(project) {
const foo = query(project, "foo");
const type = foo?.signatures?.[0]?.typeParameters?.[0].type;
equal(type?.type, "array");
equal(type?.toString(), "unknown[]");
},
gh1436(project) {
equal(
project.children?.map((c) => c.name),
["gh1436"]
);
},
gh1449(project) {
const refl = query(project, "gh1449").signatures?.[0];
equal(
refl?.typeParameters?.[0].type?.toString(),
"[foo: any, bar?: any]"
);
},
gh1454(project) {
const foo = query(project, "foo");
const fooRet = foo?.signatures?.[0]?.type;
equal(fooRet?.type, "reference");
equal(fooRet?.toString(), "Foo");
const bar = query(project, "bar");
const barRet = bar?.signatures?.[0]?.type;
equal(barRet?.type, "reference");
equal(barRet?.toString(), "Bar");
},
gh1462(project) {
const prop = query(project, "PROP");
equal(prop.type?.toString(), "number");
// Would be nice to get this to work someday
equal(prop.comment?.shortText, void 0);
const method = query(project, "METHOD");
equal(method.signatures?.[0].comment?.shortText, "method docs");
},
gh1481(project) {
const signature = query(project, "GH1481.static").signatures?.[0];
equal(signature?.comment?.shortText, "static docs");
equal(signature?.type?.toString(), "void");
},
gh1483(project) {
equal(
query(project, "gh1483.namespaceExport").kind,
ReflectionKind.Function
);
equal(
query(project, "gh1483_2.staticMethod").kind,
ReflectionKind.Method
);
},
gh1490(project) {
const refl = query(project, "GH1490.optionalMethod");
equal(refl.signatures?.[0]?.comment?.shortText, "With comment");
},
gh1509(project) {
const pFoo = query(project, "PartialFoo.foo");
equal(pFoo.flags.isOptional, true);
const rFoo = query(project, "ReadonlyFoo.foo");
equal(rFoo.flags.isReadonly, true);
equal(rFoo.flags.isOptional, true);
},
gh1514(project) {
// Not ideal. Really we want to handle these names nicer...
query(project, "ComputedUniqueName.[UNIQUE_SYMBOL]");
},
gh1522(project) {
equal(
project.groups?.map((g) => g.categories?.map((c) => c.title)),
[["cat"]]
);
},
gh1524(project) {
const nullableParam = query(project, "nullable").signatures?.[0]
?.parameters?.[0];
equal(nullableParam?.type?.toString(), "null | string");
const nonNullableParam = query(project, "nonNullable").signatures?.[0]
?.parameters?.[0];
equal(nonNullableParam?.type?.toString(), "string");
},
gh1534(project) {
const func = query(project, "gh1534");
equal(
func.signatures?.[0]?.parameters?.[0]?.type?.toString(),
"readonly [number, string]"
);
},
gh1547(project) {
equal(
project.children?.map((c) => c.name),
["Test", "ThingA", "ThingB"]
);
},
gh1552(project) {
equal(query(project, "emptyArr").defaultValue, "[]");
equal(query(project, "nonEmptyArr").defaultValue, "...");
equal(query(project, "emptyObj").defaultValue, "{}");
equal(query(project, "nonEmptyObj").defaultValue, "...");
},
gh1578(project) {
ok(query(project, "notIgnored"));
ok(
!project.findReflectionByName("ignored"),
"Symbol re-exported from ignored file is ignored."
);
},
gh1580(project) {
ok(
query(project, "B.prop").hasComment(),
"Overwritten property with no comment should be inherited"
);
ok(
query(project, "B.run").signatures?.[0]?.hasComment(),
"Overwritten method with no comment should be inherited"
);
},
gh1624(project) {
ok(
query(project, "Foo.baz").signatures?.[0]?.hasComment(),
"Property methods declared in interface should still allow comment inheritance"
);
},
gh1626(project) {
const ctor = query(project, "Foo.constructor");
equal(ctor.sources?.[0]?.line, 2);
equal(ctor.sources?.[0]?.character, 4);
},
gh1660(project) {
const alias = query(project, "SomeType");
ok(alias.type instanceof QueryType);
equal(alias.type.queryType.name, "m.SomeClass.someProp");
},
gh1733(project) {
const alias = query(project, "Foo");
equal(alias.typeParameters?.[0].comment?.shortText.trim(), "T docs");
const cls = query(project, "Bar");
equal(cls.typeParameters?.[0].comment?.shortText.trim(), "T docs");
},
gh1734(project) {
const alias = query(project, "Foo");
const type = alias.type;
ok(type instanceof ReflectionType);
const expectedComment = new Comment();
expectedComment.returns = undefined;
expectedComment.tags = [
new CommentTag("asdf", void 0, "Some example text\n"),
];
equal(type.declaration.signatures?.[0].comment, expectedComment);
},
gh1745(project) {
const Foo = query(project, "Foo");
ok(Foo.type instanceof ReflectionType);
const group = project.groups?.find(
(g) => g.kind === ReflectionKind.TypeAlias
);
ok(group);
const cat = group.categories?.find(
(cat) => cat.title === "My category"
);
ok(cat);
ok(cat.children.includes(Foo));
ok(!Foo.comment?.hasTag("category"));
ok(!Foo.type.declaration.comment?.hasTag("category"));
ok(
!Foo.type.declaration.signatures?.some((s) =>
s.comment?.hasTag("category")
)
);
},
gh1795(project) {
equal(
project.children?.map((c) => c.name),
["default", "foo"]
);
ok(project.children![0].kind === ReflectionKind.Reference);
ok(project.children![1].kind !== ReflectionKind.Reference);
},
gh1875(project) {
const test = query(project, "test");
equal(
test.signatures?.[0].parameters?.map((p) => p.type?.toString()),
["typeof globalThis", "string"]
);
const test2 = query(project, "test2");
equal(
test2.signatures?.[0].parameters?.map((p) => p.type?.toString()),
["any", "string"]
);
},
gh1876(project) {
const foo = query(project, "foo");
const fooSig = foo.signatures?.[0].parameters?.[0];
ok(fooSig);
ok(fooSig.type instanceof UnionType);
ok(fooSig.type.types[1] instanceof ReflectionType);
equal(
fooSig.type.types[1].declaration.getChildByName("min")?.comment
?.shortText,
"Nested\n"
);
const bar = query(project, "bar");
const barSig = bar.signatures?.[0].parameters?.[0];
ok(barSig);
ok(barSig.type instanceof UnionType);
ok(barSig.type.types[0] instanceof ReflectionType);
ok(barSig.type.types[1] instanceof ReflectionType);
equal(
barSig.type.types[0].declaration.getChildByName("min")?.comment
?.shortText,
"Nested\n"
);
equal(
barSig.type.types[1].declaration.getChildByName("min")?.comment
?.shortText,
"Nested\n"
);
},
gh1880(project) {
const SomeEnum = query(project, "SomeEnum");
equal(SomeEnum.kind, ReflectionKind.Enum);
ok(SomeEnum.hasComment(), "Missing @enum variable comment");
const auto = query(project, "SomeEnum.AUTO");
ok(auto.hasComment(), "Missing @enum member comment");
},
gh1898(project, logger) {
const app = getConverter2App();
app.validate(project);
logger.discardDebugMessages();
logger.expectMessage(
"warn: UnDocFn.__type, defined at src/test/converter2/issues/gh1898.ts:4, does not have any documentation."
);
logger.expectNoOtherMessages();
},
gh1903(project) {
equal(
Object.values(project.reflections).map((r) => r.name),
["typedoc"]
);
},
gh1903b(project) {
equal(
Object.values(project.reflections).map((r) => r.name),
["typedoc"]
);
},
gh1907(_project, logger) {
logger.expectMessage(
'warn: The --name option was not specified, and package.json does not have a name field. Defaulting project name to "Documentation"'
);
logger.discardDebugMessages();
logger.expectNoOtherMessages();
},
};