forked from microsoft/typespec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscalars.test.ts
53 lines (46 loc) · 1.32 KB
/
scalars.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
import assert from "assert";
import { describe, it } from "vitest";
import { emitSchema } from "./utils.js";
describe("emitting scalars", () => {
it("works with scalars extending built-in scalars", async () => {
const schemas = await emitSchema(`
scalar Test extends uint8;
`);
assert.deepStrictEqual(schemas["Test.json"], {
$id: "Test.json",
$schema: "https://json-schema.org/draft/2020-12/schema",
type: "integer",
minimum: 0,
maximum: 255,
});
});
it("throws errors for scalars not extending built-in scalars", async () => {
await assert.rejects(async () => {
await emitSchema(`
scalar Test;
`);
});
});
it("handles extensions", async () => {
const schemas = await emitSchema(`
@extension("x-scalar", Json<true>)
scalar Test extends uint8;
`);
assert.strictEqual(schemas["Test.json"]["x-scalar"], true);
});
it("can use a scalar template", async () => {
const schemas = await emitSchema(`
scalar Test<T> extends uint8;
model TestModel {
test: Test<string>;
}
`);
assert.deepStrictEqual(schemas["TestString.json"], {
$id: "TestString.json",
$schema: "https://json-schema.org/draft/2020-12/schema",
type: "integer",
maximum: 255,
minimum: 0,
});
});
});