forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdlib.test.ts
61 lines (53 loc) · 1.75 KB
/
stdlib.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
import { beforeEach, describe, it } from "vitest";
import { CompilerOptions } from "../src/index.js";
import { expectDiagnosticEmpty } from "../src/testing/index.js";
import { createTestRunner } from "../src/testing/test-host.js";
import { BasicTestRunner } from "../src/testing/types.js";
let runner: BasicTestRunner;
beforeEach(async () => {
runner = await createTestRunner();
});
const intrinsicTypes = [
"string",
"int8",
"int16",
"int32",
"int64",
"uint64",
"decimal",
"Array<string>",
"Record<string>",
"string[]",
];
describe("with stdlib", () => {
const options: CompilerOptions = { nostdlib: false };
it("compiles", async () => {
const diagnostics = await runner.diagnose(`model Bar {}`, options);
expectDiagnosticEmpty(diagnostics);
});
describe("can use intrinsic types", () => {
it.each(intrinsicTypes)("%s", async (type) => {
const diagnostics = await runner.diagnose(`model Foo { name: ${type}; }`, options);
expectDiagnosticEmpty(diagnostics);
});
});
describe("can stdlib types", () => {
it.each(["url", "unixTimestamp32"])("%s", async (type) => {
const diagnostics = await runner.diagnose(`model Foo { name: ${type}; }`, options);
expectDiagnosticEmpty(diagnostics);
});
});
});
describe("without stdlib(--nostdlib)", () => {
const options: CompilerOptions = { nostdlib: true };
it("compiles", async () => {
const diagnostics = await runner.diagnose(`model Bar {}`, options);
expectDiagnosticEmpty(diagnostics);
});
describe("can use intrinsic types", () => {
it.each(intrinsicTypes)("%s", async (type) => {
const diagnostics = await runner.diagnose(`model Foo { name: ${type}; }`, options);
expectDiagnosticEmpty(diagnostics);
});
});
});