forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuppression.test.ts
95 lines (82 loc) · 2.3 KB
/
suppression.test.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
import { beforeEach, describe, it } from "vitest";
import { navigateProgram } from "../src/core/semantic-walker.js";
import {
TestHost,
createTestHost,
expectDiagnosticEmpty,
expectDiagnostics,
} from "../src/testing/index.js";
describe("compiler: suppress", () => {
let host: TestHost;
beforeEach(async () => {
host = await createTestHost();
});
async function run(typespec: string) {
host.addTypeSpecFile("main.tsp", typespec);
await host.compile("main.tsp", { nostdlib: true });
navigateProgram(host.program, {
model: (model) => {
if (model.name === "") {
host.program.reportDiagnostic({
severity: "warning",
code: "no-inline-model",
message: "Inline models are not recommended",
target: model,
});
}
},
modelProperty: (prop) => {
if (prop.name === "id") {
host.program.reportDiagnostic({
severity: "error",
code: "no-id-property",
message: "Id properties on models are forbidden",
target: prop,
});
}
},
});
return host.program.diagnostics;
}
it("emit warning diagnostics when there is no suppression", async () => {
const diagnostics = await run(`
model Foo {
inline: {
name: 123;
};
}
`);
expectDiagnostics(diagnostics, { code: "no-inline-model" });
});
it("suppress warning diagnostic on item itself", async () => {
const diagnostics = await run(`
model Foo {
#suppress "no-inline-model" "This is needed"
inline: {
name: 123;
};
}
`);
expectDiagnosticEmpty(diagnostics);
});
it("suppress warning diagnostic on parent node", async () => {
const diagnostics = await run(`
#suppress "no-inline-model" "This is needed"
model Foo {
inline: {
name: 123;
};
}
`);
expectDiagnosticEmpty(diagnostics);
});
it("error diagnostics cannot be suppressed and emit another error", async () => {
const diagnostics = await run(`
model Foo {
#suppress "no-id-property" "This is needed"
id: 123;
}
`);
expectDiagnostics(diagnostics, [{ code: "suppress-error" }, { code: "no-id-property" }]);
});
});