-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
145 lines (116 loc) · 3.59 KB
/
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
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
import "npm:@total-typescript/ts-reset";
import { describe, it } from "https://deno.land/[email protected]/testing/bdd.ts";
import { assertSnapshot } from "https://deno.land/[email protected]/testing/snapshot.ts";
import { collapseTypes } from "./lib/collapse-types.ts";
import { parseJson } from "./lib/parse.ts";
import { Json, Type } from "./lib/types.ts";
describe("parseJson", () => {
async function run(
ctx: Deno.TestContext,
filename: string,
) {
const json = await Deno.readTextFile(`./fixtures/${filename}`);
const obj = JSON.parse(json) as Json;
const type = parseJson(obj);
await assertSnapshot(ctx, type);
}
it("parses array-0.json", async (ctx) => {
await run(ctx, "array-0.json");
});
it("parses array-1.json", async (ctx) => {
await run(ctx, "array-1.json");
});
it("parses array-2.json", async (ctx) => {
await run(ctx, "array-2.json");
});
it("parses array-3.json", async (ctx) => {
await run(ctx, "array-3.json");
});
it("parses array-4.json", async (ctx) => {
await run(ctx, "array-4.json");
});
it("parses boolean-false.json", async (ctx) => {
await run(ctx, "boolean-false.json");
});
it("parses boolean-true.json", async (ctx) => {
await run(ctx, "boolean-true.json");
});
it("parses map-0.json", async (ctx) => {
await run(ctx, "map-0.json");
});
it("parses map-1.json", async (ctx) => {
await run(ctx, "map-1.json");
});
it("parses map-2.json", async (ctx) => {
await run(ctx, "map-2.json");
});
it("parses null.json", async (ctx) => {
await run(ctx, "null.json");
});
it("parses number-negative.json", async (ctx) => {
await run(ctx, "number-negative.json");
});
it("parses number-positive.json", async (ctx) => {
await run(ctx, "number-positive.json");
});
it("parses number-zero.json", async (ctx) => {
await run(ctx, "number-zero.json");
});
it("parses object-0.json", async (ctx) => {
await run(ctx, "object-0.json");
});
it("parses object-1.json", async (ctx) => {
await run(ctx, "object-1.json");
});
it("parses object-2.json", async (ctx) => {
await run(ctx, "object-2.json");
});
it("parses object-3.json", async (ctx) => {
await run(ctx, "object-3.json");
});
it("parses object-4.json", async (ctx) => {
await run(ctx, "object-4.json");
});
it("parses object-5.json", async (ctx) => {
await run(ctx, "object-5.json");
});
it("parses object-6.json", async (ctx) => {
await run(ctx, "object-6.json");
});
it("parses object-7.json", async (ctx) => {
await run(ctx, "object-7.json");
});
it("parses object-8.json", async (ctx) => {
await run(ctx, "object-8.json");
});
it("parses regression-0-option-option.json", async (ctx) => {
await run(ctx, "regression-0-option-option.json");
});
});
describe("Parse Multiple Files", () => {
async function run(
ctx: Deno.TestContext,
directory: string,
) {
const files = Deno.readDir(`./fixtures/${directory}`);
const types = new Array<Type>();
for await (const file of files) {
const json = await Deno.readTextFile(
`./fixtures/${directory}/${file.name}`,
);
const obj = JSON.parse(json) as Json;
types.push(parseJson(obj));
}
const type = collapseTypes(types);
await assertSnapshot(ctx, type);
}
it("datapack/blockstates", async (ctx) => {
await run(ctx, "datapack/blockstates");
});
it("datapack/models/block", async (ctx) => {
await run(ctx, "datapack/models/block");
});
it("datapack/models/item", async (ctx) => {
await run(ctx, "datapack/models/item");
});
});