@malloy-publisher/sdk 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/{DocumentStorageProvider-CyOJ0hqf.es.js → DocumentStorage-B04sZ5Ie.es.js} +2307 -2334
- package/dist/{DocumentStorageProvider-DGPQEd_l.cjs.js → DocumentStorage-B_MMJ0Ot.cjs.js} +20 -20
- package/dist/{RenderedResult-BnPzJ9Jf.es.js → RenderedResult-BB7eokcf.es.js} +100 -80
- package/dist/RenderedResult-DVuGhatg.cjs.js +135 -0
- package/dist/ServerProvider-D-jjzfE5.cjs.js +1 -0
- package/dist/{ServerProvider-BWOEKg0O.es.js → ServerProvider-Do-GBvpn.es.js} +492 -481
- package/dist/builder/index.cjs.js +57 -52
- package/dist/builder/index.es.js +4421 -3738
- package/dist/client/api.d.ts +14 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/TileCard.d.ts +7 -3
- package/dist/components/Dashboard/telemetry.d.ts +20 -8
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +16 -4
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +31 -8
- package/dist/components/DashboardBuilder/controls.d.ts +8 -6
- package/dist/components/DashboardBuilder/document.d.ts +19 -5
- package/dist/components/DashboardBuilder/malloyText.d.ts +0 -30
- package/dist/components/DashboardBuilder/malloyTree.d.ts +232 -0
- package/dist/components/DashboardBuilder/preview.d.ts +17 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +23 -28
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +12 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +69 -5
- package/dist/components/DocumentStorage/index.d.ts +1 -0
- package/dist/index.cjs.js +9 -9
- package/dist/index.es.js +508 -506
- package/dist/theme/resolveTheme.d.ts +1 -1
- package/dist/theme/types.d.ts +12 -2
- package/package.json +1 -1
- package/src/components/Dashboard/TileCard.tsx +8 -4
- package/src/components/Dashboard/telemetry.ts +20 -8
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +4 -5
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +21 -3
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +706 -0
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +356 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +468 -103
- package/src/components/DashboardBuilder/FilterDialog.tsx +19 -6
- package/src/components/DashboardBuilder/TileFrame.tsx +11 -2
- package/src/components/DashboardBuilder/TileMenu.tsx +6 -0
- package/src/components/DashboardBuilder/__test__/inventory.ts +367 -0
- package/src/components/DashboardBuilder/controls.spec.ts +53 -3
- package/src/components/DashboardBuilder/controls.ts +9 -7
- package/src/components/DashboardBuilder/document.ts +17 -5
- package/src/components/DashboardBuilder/invariants.spec.ts +297 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +27 -66
- package/src/components/DashboardBuilder/malloyText.ts +4 -109
- package/src/components/DashboardBuilder/malloyTree.spec.ts +362 -0
- package/src/components/DashboardBuilder/malloyTree.ts +954 -0
- package/src/components/DashboardBuilder/preview.spec.ts +18 -0
- package/src/components/DashboardBuilder/preview.ts +24 -6
- package/src/components/DashboardBuilder/readDocument.spec.ts +312 -21
- package/src/components/DashboardBuilder/readDocument.ts +144 -165
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +550 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +955 -21
- package/src/components/DashboardBuilder/spliceDocument.ts +509 -119
- package/src/components/DashboardBuilder/statementExtent.spec.ts +606 -0
- package/src/components/DocumentStorage/BrowserDocumentStorage.ts +7 -6
- package/src/components/DocumentStorage/DocumentStorage.ts +78 -5
- package/src/components/DocumentStorage/index.ts +1 -0
- package/src/components/Package/Package.tsx +12 -7
- package/src/components/RenderedResult/RenderedResult.tsx +21 -1
- package/src/components/given/GivensPanel.tsx +15 -3
- package/src/theme/buildTableCssVars.spec.ts +3 -0
- package/src/theme/buildTableCssVars.ts +6 -0
- package/src/theme/defaults.ts +16 -12
- package/src/theme/resolveTheme.spec.ts +14 -7
- package/src/theme/resolveTheme.ts +14 -8
- package/src/theme/types.ts +12 -2
- package/tsconfig.spec.json +5 -1
- package/dist/RenderedResult-Dp22kZsQ.cjs.js +0 -115
- package/dist/ServerProvider-Cc489A3f.cjs.js +0 -1
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import {
|
|
6
|
+
parseMalloy,
|
|
7
|
+
parseRefused,
|
|
8
|
+
type ParsedMalloy,
|
|
9
|
+
type TreeStage,
|
|
10
|
+
} from "./malloyTree";
|
|
11
|
+
|
|
12
|
+
async function parsed(source: string): Promise<ParsedMalloy> {
|
|
13
|
+
const result = await parseMalloy(source);
|
|
14
|
+
if (parseRefused(result))
|
|
15
|
+
throw new Error(`expected a parse: ${result.reason}`);
|
|
16
|
+
return result.parsed;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function refusal(source: string): Promise<string> {
|
|
20
|
+
const result = await parseMalloy(source);
|
|
21
|
+
if (!parseRefused(result)) throw new Error("expected a refusal");
|
|
22
|
+
return result.reason;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const text = (p: ParsedMalloy, span: { start: number; end: number }) =>
|
|
26
|
+
p.text.slice(span.start, span.end);
|
|
27
|
+
|
|
28
|
+
const view = async (body: string, source = "a") => {
|
|
29
|
+
const src = `source: s is ${source} extend {\n view: v is ${body}\n}\n`;
|
|
30
|
+
const p = await parsed(src);
|
|
31
|
+
return { p, v: p.sources[0].views[0] };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
describe("locating a view's body", () => {
|
|
35
|
+
it("reads an inline body as its own stage", async () => {
|
|
36
|
+
const { p, v } = await view("{\n aggregate: n is count()\n }");
|
|
37
|
+
expect(v.body.kind).toBe("inline");
|
|
38
|
+
if (v.body.kind !== "inline") throw new Error("kind");
|
|
39
|
+
expect(text(p, v.body.stage.span)).toBe(
|
|
40
|
+
"{\n aggregate: n is count()\n }",
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("reads a bare reference", async () => {
|
|
45
|
+
const { v } = await view("by_brand");
|
|
46
|
+
expect(v.body).toMatchObject({ kind: "reference", from: "by_brand" });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// The shape that DELETES the refinement at head: `vx + vy + { … }` nests
|
|
50
|
+
// left, so the base is everything left of the RIGHTMOST operand.
|
|
51
|
+
it("keeps the whole base of a chained refinement", async () => {
|
|
52
|
+
const { p, v } = await view("vx + vy + { where: a ~ $A }");
|
|
53
|
+
expect(v.body.kind).toBe("reference");
|
|
54
|
+
if (v.body.kind !== "reference") throw new Error("kind");
|
|
55
|
+
expect(v.body.from).toBe("vx + vy");
|
|
56
|
+
expect(text(p, v.body.refinement!.span)).toBe("{ where: a ~ $A }");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("refuses to treat a `->` pipeline as editable", async () => {
|
|
60
|
+
const { v } = await view("x -> { aggregate: n is count() }");
|
|
61
|
+
expect(v.body).toMatchObject({ kind: "unsupported" });
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("locating filters", () => {
|
|
66
|
+
const wheresOf = (stage: TreeStage) => stage.wheres;
|
|
67
|
+
|
|
68
|
+
it("reads field, operator and given off the tree", async () => {
|
|
69
|
+
const { v } = await view("{\n where: products.cat = $CAT\n }");
|
|
70
|
+
if (v.body.kind !== "inline") throw new Error("kind");
|
|
71
|
+
expect(wheresOf(v.body.stage)[0].clauses[0].binding).toEqual({
|
|
72
|
+
field: "products.cat",
|
|
73
|
+
op: "=",
|
|
74
|
+
given: "CAT",
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// A live corrupting bug at head: the `::` defeated the boundary scan, so a
|
|
79
|
+
// second `where:` was written and the tile filtered twice.
|
|
80
|
+
it("reads a cast on the left of a binding", async () => {
|
|
81
|
+
const { v } = await view("{\n where: created_at::date >= $SINCE\n }");
|
|
82
|
+
if (v.body.kind !== "inline") throw new Error("kind");
|
|
83
|
+
expect(wheresOf(v.body.stage)[0].clauses[0].binding).toEqual({
|
|
84
|
+
field: "created_at::date",
|
|
85
|
+
op: ">=",
|
|
86
|
+
given: "SINCE",
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("reads a backtick field name, apostrophe and all", async () => {
|
|
91
|
+
const { v } = await view("{\n where: `it's odd` = $ODD\n }");
|
|
92
|
+
if (v.body.kind !== "inline") throw new Error("kind");
|
|
93
|
+
expect(wheresOf(v.body.stage)[0].clauses[0].binding?.field).toBe(
|
|
94
|
+
"`it's odd`",
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Structure, not an isolation heuristic: an `and` is simply not a
|
|
99
|
+
// comparison, so it can never be read as a binding to remove.
|
|
100
|
+
it("does not read a compound predicate as a binding", async () => {
|
|
101
|
+
const { v } = await view("{\n where: a ~ $A and c = 1\n }");
|
|
102
|
+
if (v.body.kind !== "inline") throw new Error("kind");
|
|
103
|
+
const clauses = wheresOf(v.body.stage)[0].clauses;
|
|
104
|
+
expect(clauses).toHaveLength(1);
|
|
105
|
+
expect(clauses[0].binding).toBeUndefined();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("locates each clause of a list separately", async () => {
|
|
109
|
+
const { p, v } = await view("{\n where: x ~ $X, y ~ $Y\n }");
|
|
110
|
+
if (v.body.kind !== "inline") throw new Error("kind");
|
|
111
|
+
const clauses = wheresOf(v.body.stage)[0].clauses;
|
|
112
|
+
expect(clauses.map((c) => text(p, c.span))).toEqual(["x ~ $X", "y ~ $Y"]);
|
|
113
|
+
expect(clauses.map((c) => c.binding?.given)).toEqual(["X", "Y"]);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
// Depth is structure. A nested `nest:`'s filter is that block's, so it
|
|
117
|
+
// cannot be lifted to tile level however the braces happen to be written.
|
|
118
|
+
it("does not surface a nested nest's where as the body's own", async () => {
|
|
119
|
+
const { v } = await view(
|
|
120
|
+
"{\n where: mine ~ $M\n nest: sub is { where: theirs ~ $T }\n }",
|
|
121
|
+
);
|
|
122
|
+
if (v.body.kind !== "inline") throw new Error("kind");
|
|
123
|
+
expect(
|
|
124
|
+
wheresOf(v.body.stage).map((w) => w.clauses[0].binding?.given),
|
|
125
|
+
).toEqual(["M"]);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// A filtered measure's `where:` is the measure's, not the source's.
|
|
129
|
+
it("keeps a filtered measure's where out of the source's own", async () => {
|
|
130
|
+
const p = await parsed(
|
|
131
|
+
"source: s is a extend {\n where: src ~ $S\n measure: m is count() { where: fm ~ $F }\n}\n",
|
|
132
|
+
);
|
|
133
|
+
expect(
|
|
134
|
+
p.sources[0].wheres.map((w) => w.clauses[0].binding?.given),
|
|
135
|
+
).toEqual(["S"]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("does not read a where: out of a multi-line string literal", async () => {
|
|
139
|
+
const p = await parsed(
|
|
140
|
+
'source: s is a extend {\n view: v is {\n select: q is """\n where: fake ~ $FAKE\n """\n }\n}\n',
|
|
141
|
+
);
|
|
142
|
+
const body = p.sources[0].views[0].body;
|
|
143
|
+
if (body.kind !== "inline") throw new Error("kind");
|
|
144
|
+
expect(body.stage.wheres).toHaveLength(0);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("locating declarations", () => {
|
|
149
|
+
it("reads a source's base through backticks", async () => {
|
|
150
|
+
const p = await parsed(
|
|
151
|
+
"source: s is `odd name` extend {\n where: a = 1\n}\n",
|
|
152
|
+
);
|
|
153
|
+
expect(p.sources[0]).toMatchObject({ name: "s", base: "`odd name`" });
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("carries a view's own tag block, and not the model's", async () => {
|
|
157
|
+
const p = await parsed(
|
|
158
|
+
'##! experimental.givens\nsource: s is a extend {\n # colspan=6\n # label="Orders"\n view: v is x\n}\n',
|
|
159
|
+
);
|
|
160
|
+
expect(p.sources[0].views[0].tags.map((t) => t.text)).toEqual([
|
|
161
|
+
"# colspan=6",
|
|
162
|
+
'# label="Orders"',
|
|
163
|
+
]);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("counts the siblings of a comma-separated view list", async () => {
|
|
167
|
+
const p = await parsed(
|
|
168
|
+
"source: s is a extend {\n view: x is p, y is q\n}\n",
|
|
169
|
+
);
|
|
170
|
+
expect(p.sources[0].views.map((v) => [v.name, v.siblings])).toEqual([
|
|
171
|
+
["x", 2],
|
|
172
|
+
["y", 2],
|
|
173
|
+
]);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("reads givens in both spellings", async () => {
|
|
177
|
+
const p = await parsed(
|
|
178
|
+
"##! experimental.givens\ngiven: A :: filter<string> is f''\ngiven:\n B :: date is @2023-01-01\n",
|
|
179
|
+
);
|
|
180
|
+
expect(p.givens.map((g) => g.name)).toEqual(["A", "B"]);
|
|
181
|
+
expect(p.givens[1].declaration).toBe("B :: date is @2023-01-01");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("reads both import spellings", async () => {
|
|
185
|
+
const p = await parsed(
|
|
186
|
+
"import { a, b } from '../m.malloy'\nimport \"../all.malloy\"\n",
|
|
187
|
+
);
|
|
188
|
+
expect(p.imports).toMatchObject([
|
|
189
|
+
{ from: "../m.malloy", names: ["a", "b"] },
|
|
190
|
+
{ from: "../all.malloy" },
|
|
191
|
+
]);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe("comments", () => {
|
|
196
|
+
it("finds a trailing comment but not a // inside a literal", async () => {
|
|
197
|
+
const p = await parsed(
|
|
198
|
+
"source: s is a extend {\n view: v is x // note\n view: w is y + { where: u ~ 'http://z' }\n}\n",
|
|
199
|
+
);
|
|
200
|
+
expect(text(p, p.trailingComment(1)!)).toBe("// note");
|
|
201
|
+
expect(p.trailingComment(2)).toBeUndefined();
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("takes the comment block above a declaration up to a blank line", async () => {
|
|
205
|
+
const source =
|
|
206
|
+
"source: s is a extend {\n\n // why this tile leads\n # colspan=6\n view: v is x\n}\n";
|
|
207
|
+
const p = await parsed(source);
|
|
208
|
+
expect(p.blockStart(4)).toBe(2);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Malloy's lexer spells a comment three ways under two token names. A guard
|
|
212
|
+
// that knew only `COMMENT_TO_EOL` never saw a `/* … */` at all, so the
|
|
213
|
+
// writer could delete one and report success.
|
|
214
|
+
it("indexes every comment the lexer recognizes, both token kinds", async () => {
|
|
215
|
+
const p = await parsed(
|
|
216
|
+
"source: s is a extend {\n // slash\n -- dash\n /* block */\n view: v is x\n}\n",
|
|
217
|
+
);
|
|
218
|
+
expect(p.comments.map((at) => text(p, at))).toEqual([
|
|
219
|
+
"// slash",
|
|
220
|
+
"-- dash",
|
|
221
|
+
"/* block */",
|
|
222
|
+
]);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it("sees a block comment inside a span a writer is about to delete", async () => {
|
|
226
|
+
const p = await parsed(
|
|
227
|
+
"source: s is a extend {\n view: v is x + { where: a ~ $A, /* keep */ b ~ $B }\n}\n",
|
|
228
|
+
);
|
|
229
|
+
const where = p.sources[0].views[0].body;
|
|
230
|
+
if (where.kind !== "reference" || !where.refinement)
|
|
231
|
+
throw new Error("expected a refinement");
|
|
232
|
+
const clauses = where.refinement.wheres[0].clauses;
|
|
233
|
+
const gap = { start: clauses[0].span.end, end: clauses[1].span.start };
|
|
234
|
+
expect(text(p, p.commentIn(gap)!)).toBe("/* keep */");
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// What precedes a comment is not enough to call the LINE a comment: code can
|
|
238
|
+
// follow one. Deciding otherwise made the walk above a declaration step over
|
|
239
|
+
// a line that declares something, and collect the `#` tag belonging to it.
|
|
240
|
+
it("does not call a line a comment when code follows the comment", async () => {
|
|
241
|
+
const p = await parsed(
|
|
242
|
+
"source: s is a extend {\n /* keep tidy */ dimension: helper is 1\n view: v is x\n}\n",
|
|
243
|
+
);
|
|
244
|
+
expect(p.commentLine(1)).toBe(false);
|
|
245
|
+
// ...so the block above `view:` stops at that line rather than walking on.
|
|
246
|
+
expect(p.blockStart(2)).toBe(2);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("does not call the closing line of a block comment a comment when code follows", async () => {
|
|
250
|
+
const p = await parsed(
|
|
251
|
+
"source: s is a extend {\n /* keep\n tidy */ dimension: helper is 1\n view: v is x\n}\n",
|
|
252
|
+
);
|
|
253
|
+
expect(p.commentLine(1)).toBe(true);
|
|
254
|
+
expect(p.commentLine(2)).toBe(false);
|
|
255
|
+
expect(p.blockStart(3)).toBe(3);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("still calls a line a comment when only whitespace surrounds the comment", async () => {
|
|
259
|
+
const p = await parsed(
|
|
260
|
+
"source: s is a extend {\n /* just a note */\n # colspan=6\n view: v is x\n}\n",
|
|
261
|
+
);
|
|
262
|
+
expect(p.commentLine(1)).toBe(true);
|
|
263
|
+
expect(p.blockStart(3)).toBe(1);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
// A comment with code on BOTH sides is not trailing: anything appended at the
|
|
267
|
+
// statement's end would be pushed past code that follows it.
|
|
268
|
+
it("does not treat a comment with code after it as a trailing comment", async () => {
|
|
269
|
+
const p = await parsed(
|
|
270
|
+
"source: s is a extend {\n view: v is x + { where: a ~ $A, /* c */ b ~ $B }\n}\n",
|
|
271
|
+
);
|
|
272
|
+
expect(p.trailingComment(1)).toBeUndefined();
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// A block comment's own text is not code, so a line inside one that happens
|
|
276
|
+
// to start with `#` is prose, not an annotation. Reading it as a tag makes
|
|
277
|
+
// the writer rewrite a line inside a comment.
|
|
278
|
+
it("does not read a `#` line inside a block comment as a tag", async () => {
|
|
279
|
+
const p = await parsed(
|
|
280
|
+
"source: s is a extend {\n # big_value\n /* Notes:\n # colspan is chosen below\n */\n # colspan=6\n view: v is x\n}\n",
|
|
281
|
+
);
|
|
282
|
+
expect(p.sources[0].views[0].tags.map((t) => t.text)).toEqual([
|
|
283
|
+
"# big_value",
|
|
284
|
+
"# colspan=6",
|
|
285
|
+
]);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
// `--` starts a comment in Malloy exactly as `//` does.
|
|
289
|
+
it("reads a dash comment as the block above a declaration", async () => {
|
|
290
|
+
const p = await parsed(
|
|
291
|
+
"source: s is a extend {\n\n -- why this tile leads\n # colspan=6\n view: v is x\n}\n",
|
|
292
|
+
);
|
|
293
|
+
expect(p.blockStart(4)).toBe(2);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
describe("locating dimensions", () => {
|
|
298
|
+
// The name and the expression are both nodes the tree hands over. Splitting
|
|
299
|
+
// the declaration's text on the word `is` instead made a backtick-quoted
|
|
300
|
+
// name containing that word cut the declaration in half -- the last place in
|
|
301
|
+
// this module that re-derived Malloy's grammar from text.
|
|
302
|
+
it("reads a dimension's name and expression off the tree", async () => {
|
|
303
|
+
const p = await parsed(
|
|
304
|
+
"source: s is a extend {\n dimension: total is price * qty\n}\n",
|
|
305
|
+
);
|
|
306
|
+
expect(
|
|
307
|
+
p.sources[0].dimensions.map((d) => [d.name, d.expression]),
|
|
308
|
+
).toEqual([["total", "price * qty"]]);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("reads a backtick name that contains the word `is`", async () => {
|
|
312
|
+
const p = await parsed(
|
|
313
|
+
"source: s is a extend {\n dimension: `is` is 1\n}\n",
|
|
314
|
+
);
|
|
315
|
+
expect(
|
|
316
|
+
p.sources[0].dimensions.map((d) => [d.name, d.expression]),
|
|
317
|
+
).toEqual([["`is`", "1"]]);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it("reads each dimension of a comma-separated list", async () => {
|
|
321
|
+
const p = await parsed(
|
|
322
|
+
"source: s is a extend {\n dimension: one is 1, two is 2\n}\n",
|
|
323
|
+
);
|
|
324
|
+
expect(
|
|
325
|
+
p.sources[0].dimensions.map((d) => [d.name, d.expression]),
|
|
326
|
+
).toEqual([
|
|
327
|
+
["one", "1"],
|
|
328
|
+
["two", "2"],
|
|
329
|
+
]);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
describe("refusing rather than guessing", () => {
|
|
334
|
+
// ANTLR recovers from a syntax error by inventing structure — a phantom
|
|
335
|
+
// view, a backwards range, every later declaration dropped — and reports
|
|
336
|
+
// none of it. An edit located in that tree deletes real code.
|
|
337
|
+
it("refuses a file with a syntax error", async () => {
|
|
338
|
+
const reason = await refusal("source: s is a extend {\n view: v is {\n");
|
|
339
|
+
expect(reason).toContain("syntax error");
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
it("names the version when the tree is not what it expects", async () => {
|
|
343
|
+
// The assertion's own message, which is the only protection a host that
|
|
344
|
+
// resolved a different peer version ever gets.
|
|
345
|
+
const reason = await refusal("source: s is a extend {\n view: v is }\n");
|
|
346
|
+
expect(reason.length).toBeGreaterThan(0);
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
describe("offsets are UTF-16, not code points", () => {
|
|
351
|
+
// The parser counts code points. Slicing a JS string by its numbers puts a
|
|
352
|
+
// clause two units early and cuts an emoji into a lone surrogate.
|
|
353
|
+
it("locates a clause after an astral character exactly", async () => {
|
|
354
|
+
const { p, v } = await view(
|
|
355
|
+
"{\n where: label = '\u{1F600}\u{1F600}', b ~ $B\n }",
|
|
356
|
+
);
|
|
357
|
+
if (v.body.kind !== "inline") throw new Error("kind");
|
|
358
|
+
const clauses = v.body.stage.wheres[0].clauses;
|
|
359
|
+
expect(text(p, clauses[1].span)).toBe("b ~ $B");
|
|
360
|
+
expect(text(p, clauses[0].span)).toBe("label = '\u{1F600}\u{1F600}'");
|
|
361
|
+
});
|
|
362
|
+
});
|