@malloydata/malloy 0.0.80-dev230830211713 → 0.0.80-dev230903192621
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/dist/lang/test/expressions.spec.js +415 -0
- package/dist/lang/test/literals.spec.js +274 -0
- package/dist/lang/test/locations.spec.d.ts +1 -0
- package/dist/lang/test/locations.spec.js +722 -0
- package/dist/lang/test/parse.spec.js +93 -2417
- package/dist/lang/test/query.spec.d.ts +1 -0
- package/dist/lang/test/query.spec.js +998 -0
- package/dist/lang/test/source.spec.d.ts +1 -0
- package/dist/lang/test/source.spec.js +241 -0
- package/dist/lang/test/test-translator.d.ts +2 -1
- package/dist/lang/test/test-translator.js +24 -1
- package/package.json +1 -1
- package/dist/lang/test/refine.spec.js +0 -112
- package/dist/lang/test/strings.spec.js +0 -155
- /package/dist/lang/test/{refine.spec.d.ts → expressions.spec.d.ts} +0 -0
- /package/dist/lang/test/{strings.spec.d.ts → literals.spec.d.ts} +0 -0
|
@@ -0,0 +1,722 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2023 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files
|
|
7
|
+
* (the "Software"), to deal in the Software without restriction,
|
|
8
|
+
* including without limitation the rights to use, copy, modify, merge,
|
|
9
|
+
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
10
|
+
* and to permit persons to whom the Software is furnished to do so,
|
|
11
|
+
* subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be
|
|
14
|
+
* included in all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
21
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
22
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const test_translator_1 = require("./test-translator");
|
|
26
|
+
require("./parse-expects");
|
|
27
|
+
describe('source locations', () => {
|
|
28
|
+
test('renamed source location', () => {
|
|
29
|
+
const source = (0, test_translator_1.markSource) `source: ${'na is a'}`;
|
|
30
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
31
|
+
expect(m).toParse();
|
|
32
|
+
expect((0, test_translator_1.getExplore)(m.modelDef, 'na').location).toMatchObject(source.locations[0]);
|
|
33
|
+
});
|
|
34
|
+
test('refined source location', () => {
|
|
35
|
+
const source = (0, test_translator_1.markSource) `source: ${'na is a {}'}`;
|
|
36
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
37
|
+
expect(m).toParse();
|
|
38
|
+
expect((0, test_translator_1.getExplore)(m.modelDef, 'na').location).toMatchObject(source.locations[0]);
|
|
39
|
+
});
|
|
40
|
+
test('location of defined dimension', () => {
|
|
41
|
+
const source = (0, test_translator_1.markSource) `source: na is a { dimension: ${'x is 1'} }`;
|
|
42
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
43
|
+
expect(m).toTranslate();
|
|
44
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
45
|
+
const x = (0, test_translator_1.getFieldDef)(na, 'x');
|
|
46
|
+
expect(x.location).toMatchObject(source.locations[0]);
|
|
47
|
+
});
|
|
48
|
+
test('location of defined measure', () => {
|
|
49
|
+
const source = (0, test_translator_1.markSource) `source: na is a { measure: ${'x is count()'} }`;
|
|
50
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
51
|
+
expect(m).toTranslate();
|
|
52
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
53
|
+
const x = (0, test_translator_1.getFieldDef)(na, 'x');
|
|
54
|
+
expect(x.location).toMatchObject(source.locations[0]);
|
|
55
|
+
});
|
|
56
|
+
test('location of defined query', () => {
|
|
57
|
+
const source = (0, test_translator_1.markSource) `source: na is a { query: ${'x is { group_by: y is 1 }'} }`;
|
|
58
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
59
|
+
expect(m).toTranslate();
|
|
60
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
61
|
+
const x = (0, test_translator_1.getFieldDef)(na, 'x');
|
|
62
|
+
expect(x.location).toMatchObject(source.locations[0]);
|
|
63
|
+
});
|
|
64
|
+
test('location of defined field inside a query', () => {
|
|
65
|
+
const source = (0, test_translator_1.markSource) `
|
|
66
|
+
source: na is a {
|
|
67
|
+
query: x is {
|
|
68
|
+
group_by: ${'y is 1'}
|
|
69
|
+
}
|
|
70
|
+
}`;
|
|
71
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
72
|
+
expect(m).toTranslate();
|
|
73
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
74
|
+
const x = (0, test_translator_1.getQueryField)(na, 'x');
|
|
75
|
+
const y = (0, test_translator_1.getFieldDef)(x.pipeline[0], 'y');
|
|
76
|
+
expect(y.location).toMatchObject(source.locations[0]);
|
|
77
|
+
});
|
|
78
|
+
test('location of filtered field inside a query', () => {
|
|
79
|
+
const source = (0, test_translator_1.markSource) `
|
|
80
|
+
source: na is a {
|
|
81
|
+
measure: y is count()
|
|
82
|
+
query: x is {
|
|
83
|
+
aggregate: ${'z is y { where: true }'}
|
|
84
|
+
}
|
|
85
|
+
}`;
|
|
86
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
87
|
+
expect(m).toTranslate();
|
|
88
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
89
|
+
const x = (0, test_translator_1.getQueryField)(na, 'x');
|
|
90
|
+
const z = (0, test_translator_1.getFieldDef)(x.pipeline[0], 'z');
|
|
91
|
+
expect(z.location).toMatchObject(source.locations[0]);
|
|
92
|
+
});
|
|
93
|
+
test('location of field inherited from table', () => {
|
|
94
|
+
const source = (0, test_translator_1.markSource) `source: na is ${"table('aTable')"}`;
|
|
95
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
96
|
+
expect(m).toTranslate();
|
|
97
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
98
|
+
const abool = (0, test_translator_1.getFieldDef)(na, 'abool');
|
|
99
|
+
expect(abool.location).toMatchObject(source.locations[0]);
|
|
100
|
+
});
|
|
101
|
+
test('location of field inherited from sql block', () => {
|
|
102
|
+
const source = (0, test_translator_1.markSource) `--- comment
|
|
103
|
+
sql: s is { select: ${'"""SELECT 1 as one """'} }
|
|
104
|
+
source: na is from_sql(s)
|
|
105
|
+
`;
|
|
106
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
107
|
+
expect(m).toParse();
|
|
108
|
+
const compileSql = m.translate().compileSQL;
|
|
109
|
+
expect(compileSql).toBeDefined();
|
|
110
|
+
if (compileSql) {
|
|
111
|
+
m.update({
|
|
112
|
+
compileSQL: { [compileSql.name]: (0, test_translator_1.getSelectOneStruct)(compileSql) },
|
|
113
|
+
});
|
|
114
|
+
expect(m).toTranslate();
|
|
115
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
116
|
+
const one = (0, test_translator_1.getFieldDef)(na, 'one');
|
|
117
|
+
expect(one.location).isLocationIn(source.locations[0], source.code);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
test('location of fields inherited from a query', () => {
|
|
121
|
+
const source = (0, test_translator_1.markSource) `
|
|
122
|
+
source: na is from(
|
|
123
|
+
${"table('aTable')"} -> {
|
|
124
|
+
group_by:
|
|
125
|
+
abool
|
|
126
|
+
${'y is 1'}
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
`;
|
|
130
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
131
|
+
expect(m).toTranslate();
|
|
132
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
133
|
+
const abool = (0, test_translator_1.getFieldDef)(na, 'abool');
|
|
134
|
+
expect(abool.location).toMatchObject(source.locations[0]);
|
|
135
|
+
const y = (0, test_translator_1.getFieldDef)(na, 'y');
|
|
136
|
+
expect(y.location).toMatchObject(source.locations[1]);
|
|
137
|
+
});
|
|
138
|
+
test('location of named query', () => {
|
|
139
|
+
const source = (0, test_translator_1.markSource) `query: ${'q is a -> { project: * }'}`;
|
|
140
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
141
|
+
expect(m).toTranslate();
|
|
142
|
+
const q = (0, test_translator_1.getExplore)(m.modelDef, 'q');
|
|
143
|
+
expect(q.location).toMatchObject(source.locations[0]);
|
|
144
|
+
});
|
|
145
|
+
test('location of field in named query', () => {
|
|
146
|
+
const source = (0, test_translator_1.markSource) `query: q is a -> { group_by: ${'b is 1'} }`;
|
|
147
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
148
|
+
expect(m).toTranslate();
|
|
149
|
+
const q = (0, test_translator_1.getModelQuery)(m.modelDef, 'q');
|
|
150
|
+
const a = (0, test_translator_1.getFieldDef)(q.pipeline[0], 'b');
|
|
151
|
+
expect(a.location).toMatchObject(source.locations[0]);
|
|
152
|
+
});
|
|
153
|
+
test('location of named SQL block', () => {
|
|
154
|
+
const source = (0, test_translator_1.markSource) `${'sql: s is { select: """SELECT 1 as one""" }'}`;
|
|
155
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
156
|
+
expect(m).toParse();
|
|
157
|
+
const compileSql = m.translate().compileSQL;
|
|
158
|
+
expect(compileSql).toBeDefined();
|
|
159
|
+
if (compileSql) {
|
|
160
|
+
m.update({
|
|
161
|
+
compileSQL: { [compileSql.name]: (0, test_translator_1.getSelectOneStruct)(compileSql) },
|
|
162
|
+
});
|
|
163
|
+
expect(m).toTranslate();
|
|
164
|
+
const s = m.sqlBlocks[0];
|
|
165
|
+
expect(s.location).isLocationIn(source.locations[0], source.code);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
test('location of renamed field', () => {
|
|
169
|
+
const source = (0, test_translator_1.markSource) `
|
|
170
|
+
source: na is a {
|
|
171
|
+
rename: ${'bbool is abool'}
|
|
172
|
+
}
|
|
173
|
+
`;
|
|
174
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
175
|
+
expect(m).toTranslate();
|
|
176
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
177
|
+
const bbool = (0, test_translator_1.getFieldDef)(na, 'bbool');
|
|
178
|
+
expect(bbool.location).toMatchObject(source.locations[0]);
|
|
179
|
+
});
|
|
180
|
+
test('location of join on', () => {
|
|
181
|
+
const source = (0, test_translator_1.markSource) `
|
|
182
|
+
source: na is a {
|
|
183
|
+
join_one: ${'x is a { primary_key: abool } on abool'}
|
|
184
|
+
}
|
|
185
|
+
`;
|
|
186
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
187
|
+
expect(m).toTranslate();
|
|
188
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
189
|
+
const x = (0, test_translator_1.getFieldDef)(na, 'x');
|
|
190
|
+
expect(x.location).toMatchObject(source.locations[0]);
|
|
191
|
+
});
|
|
192
|
+
test('location of join with', () => {
|
|
193
|
+
const source = (0, test_translator_1.markSource) `
|
|
194
|
+
source: na is a {
|
|
195
|
+
join_one: ${'x is a { primary_key: astr } with astr'}
|
|
196
|
+
}
|
|
197
|
+
`;
|
|
198
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
199
|
+
expect(m).toTranslate();
|
|
200
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
201
|
+
const x = (0, test_translator_1.getFieldDef)(na, 'x');
|
|
202
|
+
expect(x.location).toMatchObject(source.locations[0]);
|
|
203
|
+
});
|
|
204
|
+
test('location of field in join', () => {
|
|
205
|
+
const source = (0, test_translator_1.markSource) `
|
|
206
|
+
source: na is a {
|
|
207
|
+
join_one: x is a {
|
|
208
|
+
primary_key: abool
|
|
209
|
+
dimension: ${'y is 1'}
|
|
210
|
+
} on abool
|
|
211
|
+
}
|
|
212
|
+
`;
|
|
213
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
214
|
+
expect(m).toTranslate();
|
|
215
|
+
const na = (0, test_translator_1.getExplore)(m.modelDef, 'na');
|
|
216
|
+
const x = (0, test_translator_1.getJoinField)(na, 'x');
|
|
217
|
+
const y = (0, test_translator_1.getFieldDef)(x, 'y');
|
|
218
|
+
expect(y.location).toMatchObject(source.locations[0]);
|
|
219
|
+
});
|
|
220
|
+
// Since """ strings are not single tokens, I don't know how to do this.
|
|
221
|
+
// test("multi line sql block token span is correct", () => {
|
|
222
|
+
// const sqlSource = `sql: { select: """// line 0\n//line 1\n// line 2""" }`;
|
|
223
|
+
// const m = new TestTranslator(sqlSource);
|
|
224
|
+
// expect(m).not.toParse();
|
|
225
|
+
// const errList = m.errors().errors;
|
|
226
|
+
// expect(errList[0].at?.range.end).toEqual({ line: 2, character: 11 });
|
|
227
|
+
// });
|
|
228
|
+
test('undefined query location', () => {
|
|
229
|
+
expect((0, test_translator_1.model) `query: ${'-> xyz'}`).translationToFailWith("Reference to undefined query 'xyz'");
|
|
230
|
+
});
|
|
231
|
+
test('undefined field reference', () => {
|
|
232
|
+
expect((0, test_translator_1.model) `query: a -> { group_by: ${'xyz'} }`).translationToFailWith("'xyz' is not defined");
|
|
233
|
+
});
|
|
234
|
+
test('bad query', () => {
|
|
235
|
+
expect((0, test_translator_1.model) `query: a -> { group_by: astr; ${'project: *'} }`).translationToFailWith(/Not legal in grouping query/);
|
|
236
|
+
});
|
|
237
|
+
test.skip('undefined field reference in top', () => {
|
|
238
|
+
expect((0, test_translator_1.model) `query: a -> { group_by: one is 1; top: 1 by ${'xyz'} }`).translationToFailWith("'xyz' is not defined");
|
|
239
|
+
});
|
|
240
|
+
test.skip('undefined field reference in order_by', () => {
|
|
241
|
+
expect((0, test_translator_1.model) `query: a -> { group_by: one is 1; order_by: ${'xyz'} }`).translationToFailWith("'xyz' is not defined");
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
describe('source references', () => {
|
|
245
|
+
test('reference to explore', () => {
|
|
246
|
+
const source = (0, test_translator_1.markSource) `
|
|
247
|
+
source: ${'na is a'}
|
|
248
|
+
query: ${'na'} -> { project: * }
|
|
249
|
+
`;
|
|
250
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
251
|
+
expect(m).toTranslate();
|
|
252
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
253
|
+
location: source.locations[1],
|
|
254
|
+
type: 'exploreReference',
|
|
255
|
+
text: 'na',
|
|
256
|
+
definition: {
|
|
257
|
+
location: source.locations[0],
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
test('reference to query in query', () => {
|
|
262
|
+
const source = (0, test_translator_1.markSource) `
|
|
263
|
+
source: t is a {
|
|
264
|
+
query: ${'q is { project: * }'}
|
|
265
|
+
}
|
|
266
|
+
query: t -> ${'q'}
|
|
267
|
+
`;
|
|
268
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
269
|
+
expect(m).toTranslate();
|
|
270
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
271
|
+
location: source.locations[1],
|
|
272
|
+
type: 'fieldReference',
|
|
273
|
+
text: 'q',
|
|
274
|
+
definition: {
|
|
275
|
+
location: source.locations[0],
|
|
276
|
+
},
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
test('reference to query in query (version 2)', () => {
|
|
280
|
+
const source = (0, test_translator_1.markSource) `
|
|
281
|
+
source: na is a { query: ${'x is { group_by: y is 1 }'} }
|
|
282
|
+
query: na -> ${'x'}
|
|
283
|
+
`;
|
|
284
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
285
|
+
expect(m).toTranslate();
|
|
286
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
287
|
+
location: source.locations[1],
|
|
288
|
+
type: 'fieldReference',
|
|
289
|
+
text: 'x',
|
|
290
|
+
definition: {
|
|
291
|
+
location: source.locations[0],
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
test('reference to sql block', () => {
|
|
296
|
+
const source = (0, test_translator_1.markSource) `
|
|
297
|
+
${'sql: s is {select:"""SELECT 1 as one"""}'}
|
|
298
|
+
source: na is from_sql(${'s'})
|
|
299
|
+
`;
|
|
300
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
301
|
+
expect(m).toParse();
|
|
302
|
+
const compileSql = m.translate().compileSQL;
|
|
303
|
+
expect(compileSql).toBeDefined();
|
|
304
|
+
if (compileSql) {
|
|
305
|
+
m.update({
|
|
306
|
+
compileSQL: { [compileSql.name]: (0, test_translator_1.getSelectOneStruct)(compileSql) },
|
|
307
|
+
});
|
|
308
|
+
expect(m).toTranslate();
|
|
309
|
+
const ref = m.referenceAt(pos(source.locations[1]));
|
|
310
|
+
expect(ref).toMatchObject({
|
|
311
|
+
location: source.locations[1],
|
|
312
|
+
type: 'sqlBlockReference',
|
|
313
|
+
text: 's',
|
|
314
|
+
definition: {
|
|
315
|
+
...(0, test_translator_1.getSelectOneStruct)(compileSql),
|
|
316
|
+
location: source.locations[0],
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
test('reference to query in from', () => {
|
|
322
|
+
const source = (0, test_translator_1.markSource) `
|
|
323
|
+
query: ${'q is a -> { project: * }'}
|
|
324
|
+
source: na is from(-> ${'q'})
|
|
325
|
+
`;
|
|
326
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
327
|
+
expect(m).toTranslate();
|
|
328
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
329
|
+
location: source.locations[1],
|
|
330
|
+
type: 'queryReference',
|
|
331
|
+
text: 'q',
|
|
332
|
+
definition: {
|
|
333
|
+
location: source.locations[0],
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
test('reference to query in query head', () => {
|
|
338
|
+
const source = (0, test_translator_1.markSource) `
|
|
339
|
+
query: ${'q is a -> { project: * }'}
|
|
340
|
+
query: q2 is -> ${'q'} -> { project: * }
|
|
341
|
+
`;
|
|
342
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
343
|
+
expect(m).toTranslate();
|
|
344
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
345
|
+
location: source.locations[1],
|
|
346
|
+
type: 'queryReference',
|
|
347
|
+
text: 'q',
|
|
348
|
+
definition: {
|
|
349
|
+
location: source.locations[0],
|
|
350
|
+
},
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
test('reference to query in refined query', () => {
|
|
354
|
+
const source = (0, test_translator_1.markSource) `
|
|
355
|
+
query: ${'q is a -> { project: * }'}
|
|
356
|
+
query: q2 is -> ${'q'} { limit: 10 }
|
|
357
|
+
`;
|
|
358
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
359
|
+
expect(m).toTranslate();
|
|
360
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
361
|
+
location: source.locations[1],
|
|
362
|
+
type: 'queryReference',
|
|
363
|
+
text: 'q',
|
|
364
|
+
definition: {
|
|
365
|
+
location: source.locations[0],
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
test('reference to field in expression', () => {
|
|
370
|
+
const source = (0, test_translator_1.markSource) `
|
|
371
|
+
source: na is ${"table('aTable')"}
|
|
372
|
+
query: na -> { project: bbool is not ${'abool'} }
|
|
373
|
+
`;
|
|
374
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
375
|
+
expect(m).toTranslate();
|
|
376
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
377
|
+
location: source.locations[1],
|
|
378
|
+
type: 'fieldReference',
|
|
379
|
+
text: 'abool',
|
|
380
|
+
definition: {
|
|
381
|
+
location: source.locations[0],
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
test('reference to quoted field in expression', () => {
|
|
386
|
+
const source = (0, test_translator_1.markSource) `
|
|
387
|
+
source: na is a {
|
|
388
|
+
dimension: ${"`name` is 'name'"}
|
|
389
|
+
}
|
|
390
|
+
query: na -> { project: ${'`name`'} }
|
|
391
|
+
`;
|
|
392
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
393
|
+
expect(m).toTranslate();
|
|
394
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
395
|
+
location: source.locations[1],
|
|
396
|
+
type: 'fieldReference',
|
|
397
|
+
text: 'name',
|
|
398
|
+
definition: {
|
|
399
|
+
location: source.locations[0],
|
|
400
|
+
},
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
test('reference to joined field in expression', () => {
|
|
404
|
+
const source = (0, test_translator_1.markSource) `
|
|
405
|
+
source: na is a {
|
|
406
|
+
join_one: self is ${"table('aTable')"}
|
|
407
|
+
on astr = self.astr
|
|
408
|
+
}
|
|
409
|
+
query: na -> { project: bstr is self.${'astr'} }
|
|
410
|
+
`;
|
|
411
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
412
|
+
expect(m).toTranslate();
|
|
413
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
414
|
+
location: source.locations[1],
|
|
415
|
+
type: 'fieldReference',
|
|
416
|
+
text: 'astr',
|
|
417
|
+
definition: {
|
|
418
|
+
location: source.locations[0],
|
|
419
|
+
},
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
test('reference to joined join in expression', () => {
|
|
423
|
+
const source = (0, test_translator_1.markSource) `
|
|
424
|
+
source: na is a {
|
|
425
|
+
join_one: ${'self is a on astr = self.astr'}
|
|
426
|
+
}
|
|
427
|
+
query: na -> { project: bstr is ${'self'}.astr }
|
|
428
|
+
`;
|
|
429
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
430
|
+
expect(m).toTranslate();
|
|
431
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
432
|
+
location: source.locations[1],
|
|
433
|
+
type: 'joinReference',
|
|
434
|
+
text: 'self',
|
|
435
|
+
definition: {
|
|
436
|
+
location: source.locations[0],
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
test('reference to field not in expression (group by)', () => {
|
|
441
|
+
const source = (0, test_translator_1.markSource) `
|
|
442
|
+
query: ${"table('aTable')"} -> { group_by: ${'abool'} }
|
|
443
|
+
`;
|
|
444
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
445
|
+
expect(m).toTranslate();
|
|
446
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
447
|
+
location: source.locations[1],
|
|
448
|
+
type: 'fieldReference',
|
|
449
|
+
text: 'abool',
|
|
450
|
+
definition: {
|
|
451
|
+
location: source.locations[0],
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
test('reference to field not in expression (project)', () => {
|
|
456
|
+
const source = (0, test_translator_1.markSource) `
|
|
457
|
+
source: na is ${"table('aTable')"}
|
|
458
|
+
query: na -> { project: ${'abool'} }
|
|
459
|
+
`;
|
|
460
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
461
|
+
expect(m).toTranslate();
|
|
462
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
463
|
+
location: source.locations[1],
|
|
464
|
+
type: 'fieldReference',
|
|
465
|
+
text: 'abool',
|
|
466
|
+
definition: {
|
|
467
|
+
location: source.locations[0],
|
|
468
|
+
},
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
test.skip('reference to field in order by', () => {
|
|
472
|
+
const source = (0, test_translator_1.markSource) `
|
|
473
|
+
query: ${"table('aTable')"} -> {
|
|
474
|
+
group_by: abool
|
|
475
|
+
order_by: ${'abool'}
|
|
476
|
+
}
|
|
477
|
+
`;
|
|
478
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
479
|
+
expect(m).toTranslate();
|
|
480
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
481
|
+
location: source.locations[1],
|
|
482
|
+
type: 'fieldReference',
|
|
483
|
+
text: 'abool',
|
|
484
|
+
definition: {
|
|
485
|
+
location: source.locations[0],
|
|
486
|
+
},
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
test.skip('reference to field in order by (output space)', () => {
|
|
490
|
+
const source = (0, test_translator_1.markSource) `
|
|
491
|
+
query: a -> {
|
|
492
|
+
group_by: ${'one is 1'}
|
|
493
|
+
order_by: ${'one'}
|
|
494
|
+
}
|
|
495
|
+
`;
|
|
496
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
497
|
+
expect(m).toTranslate();
|
|
498
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
499
|
+
location: source.locations[1],
|
|
500
|
+
type: 'fieldReference',
|
|
501
|
+
text: 'abool',
|
|
502
|
+
definition: {
|
|
503
|
+
location: source.locations[0],
|
|
504
|
+
},
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
test('reference to field in aggregate', () => {
|
|
508
|
+
const source = (0, test_translator_1.markSource) `
|
|
509
|
+
query: a { measure: ${'c is count()'} } -> {
|
|
510
|
+
group_by: abool
|
|
511
|
+
aggregate: ${'c'}
|
|
512
|
+
}
|
|
513
|
+
`;
|
|
514
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
515
|
+
expect(m).toTranslate();
|
|
516
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
517
|
+
location: source.locations[1],
|
|
518
|
+
type: 'fieldReference',
|
|
519
|
+
text: 'c',
|
|
520
|
+
definition: {
|
|
521
|
+
location: source.locations[0],
|
|
522
|
+
},
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
test('reference to field in measure', () => {
|
|
526
|
+
const source = (0, test_translator_1.markSource) `
|
|
527
|
+
source: e is a {
|
|
528
|
+
measure: ${'c is count()'}
|
|
529
|
+
measure: c2 is ${'c'}
|
|
530
|
+
}
|
|
531
|
+
`;
|
|
532
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
533
|
+
expect(m).toTranslate();
|
|
534
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
535
|
+
location: source.locations[1],
|
|
536
|
+
type: 'fieldReference',
|
|
537
|
+
text: 'c',
|
|
538
|
+
definition: {
|
|
539
|
+
location: source.locations[0],
|
|
540
|
+
},
|
|
541
|
+
});
|
|
542
|
+
});
|
|
543
|
+
test.skip('reference to field in top', () => {
|
|
544
|
+
const source = (0, test_translator_1.markSource) `
|
|
545
|
+
query: ${"table('aTable')"} -> {
|
|
546
|
+
group_by: abool
|
|
547
|
+
top: 10 by ${'abool'}
|
|
548
|
+
}
|
|
549
|
+
`;
|
|
550
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
551
|
+
expect(m).toTranslate();
|
|
552
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
553
|
+
location: source.locations[1],
|
|
554
|
+
type: 'fieldReference',
|
|
555
|
+
text: 'abool',
|
|
556
|
+
definition: {
|
|
557
|
+
location: source.locations[0],
|
|
558
|
+
},
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
test.skip('reference to field in top (output space)', () => {
|
|
562
|
+
const source = (0, test_translator_1.markSource) `
|
|
563
|
+
query: a -> {
|
|
564
|
+
group_by: ${'one is 1'}
|
|
565
|
+
top: 10 by ${'one'}
|
|
566
|
+
}
|
|
567
|
+
`;
|
|
568
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
569
|
+
expect(m).toTranslate();
|
|
570
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
571
|
+
location: source.locations[1],
|
|
572
|
+
type: 'fieldReference',
|
|
573
|
+
text: 'abool',
|
|
574
|
+
definition: {
|
|
575
|
+
location: source.locations[0],
|
|
576
|
+
},
|
|
577
|
+
});
|
|
578
|
+
});
|
|
579
|
+
test('reference to field in filter', () => {
|
|
580
|
+
const source = (0, test_translator_1.markSource) `
|
|
581
|
+
query: ${"table('aTable')"} -> {
|
|
582
|
+
group_by: abool
|
|
583
|
+
where: ${'abool'}
|
|
584
|
+
}
|
|
585
|
+
`;
|
|
586
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
587
|
+
expect(m).toTranslate();
|
|
588
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
589
|
+
location: source.locations[1],
|
|
590
|
+
type: 'fieldReference',
|
|
591
|
+
text: 'abool',
|
|
592
|
+
definition: {
|
|
593
|
+
location: source.locations[0],
|
|
594
|
+
},
|
|
595
|
+
});
|
|
596
|
+
});
|
|
597
|
+
test('reference to field in aggregate source', () => {
|
|
598
|
+
const source = (0, test_translator_1.markSource) `
|
|
599
|
+
source: na is ${"table('aTable')"}
|
|
600
|
+
query: na -> { aggregate: ai_sum is ${'ai'}.sum() }
|
|
601
|
+
`;
|
|
602
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
603
|
+
expect(m).toTranslate();
|
|
604
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
605
|
+
location: source.locations[1],
|
|
606
|
+
type: 'fieldReference',
|
|
607
|
+
text: 'ai',
|
|
608
|
+
definition: {
|
|
609
|
+
location: source.locations[0],
|
|
610
|
+
},
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
function pos(location) {
|
|
614
|
+
return location.range.start;
|
|
615
|
+
}
|
|
616
|
+
test('reference to join in aggregate source', () => {
|
|
617
|
+
const source = (0, test_translator_1.markSource) `
|
|
618
|
+
source: na is a {
|
|
619
|
+
join_one: ${'self is a on astr = self.astr'}
|
|
620
|
+
}
|
|
621
|
+
query: na -> { aggregate: ai_sum is ${'self'}.sum(self.ai) }
|
|
622
|
+
`;
|
|
623
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
624
|
+
expect(m).toTranslate();
|
|
625
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
626
|
+
location: source.locations[1],
|
|
627
|
+
type: 'joinReference',
|
|
628
|
+
text: 'self',
|
|
629
|
+
definition: {
|
|
630
|
+
location: source.locations[0],
|
|
631
|
+
},
|
|
632
|
+
});
|
|
633
|
+
});
|
|
634
|
+
test('reference to join in aggregate in expr', () => {
|
|
635
|
+
const source = (0, test_translator_1.markSource) `
|
|
636
|
+
source: na is a {
|
|
637
|
+
join_one: ${'self is a on astr = self.astr'}
|
|
638
|
+
}
|
|
639
|
+
query: na -> { aggregate: ai_sum is self.sum(${'self'}.ai) }
|
|
640
|
+
`;
|
|
641
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
642
|
+
expect(m).toTranslate();
|
|
643
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
644
|
+
location: source.locations[1],
|
|
645
|
+
type: 'joinReference',
|
|
646
|
+
text: 'self',
|
|
647
|
+
definition: {
|
|
648
|
+
location: source.locations[0],
|
|
649
|
+
},
|
|
650
|
+
});
|
|
651
|
+
});
|
|
652
|
+
test('reference to sourcein join', () => {
|
|
653
|
+
const source = (0, test_translator_1.markSource) `
|
|
654
|
+
source: ${'exp1 is a'}
|
|
655
|
+
source: exp2 is a {
|
|
656
|
+
join_one: ${'exp1'} on astr = exp1.astr
|
|
657
|
+
}
|
|
658
|
+
`;
|
|
659
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
660
|
+
expect(m).toTranslate();
|
|
661
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
662
|
+
location: source.locations[1],
|
|
663
|
+
type: 'exploreReference',
|
|
664
|
+
text: 'exp1',
|
|
665
|
+
definition: {
|
|
666
|
+
location: source.locations[0],
|
|
667
|
+
},
|
|
668
|
+
});
|
|
669
|
+
});
|
|
670
|
+
test('reference to field in aggregate (in expr)', () => {
|
|
671
|
+
const source = (0, test_translator_1.markSource) `
|
|
672
|
+
source: na is ${"table('aTable')"}
|
|
673
|
+
query: na -> { aggregate: ai_sum is sum(${'ai'}) }
|
|
674
|
+
`;
|
|
675
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
676
|
+
expect(m).toTranslate();
|
|
677
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
678
|
+
location: source.locations[1],
|
|
679
|
+
type: 'fieldReference',
|
|
680
|
+
text: 'ai',
|
|
681
|
+
definition: {
|
|
682
|
+
location: source.locations[0],
|
|
683
|
+
},
|
|
684
|
+
});
|
|
685
|
+
});
|
|
686
|
+
test('reference to field in rename', () => {
|
|
687
|
+
const source = (0, test_translator_1.markSource) `
|
|
688
|
+
source: na is ${"table('aTable')"} {
|
|
689
|
+
rename: bbool is ${'abool'}
|
|
690
|
+
}
|
|
691
|
+
`;
|
|
692
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
693
|
+
expect(m).toTranslate();
|
|
694
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
695
|
+
location: source.locations[1],
|
|
696
|
+
type: 'fieldReference',
|
|
697
|
+
text: 'abool',
|
|
698
|
+
definition: {
|
|
699
|
+
location: source.locations[0],
|
|
700
|
+
},
|
|
701
|
+
});
|
|
702
|
+
});
|
|
703
|
+
test('reference to field in join with', () => {
|
|
704
|
+
const source = (0, test_translator_1.markSource) `
|
|
705
|
+
source: exp1 is a { primary_key: astr }
|
|
706
|
+
source: exp2 is ${"table('aTable')"} {
|
|
707
|
+
join_one: exp1 with ${'astr'}
|
|
708
|
+
}
|
|
709
|
+
`;
|
|
710
|
+
const m = new test_translator_1.TestTranslator(source.code);
|
|
711
|
+
expect(m).toTranslate();
|
|
712
|
+
expect(m.referenceAt(pos(source.locations[1]))).toMatchObject({
|
|
713
|
+
location: source.locations[1],
|
|
714
|
+
type: 'fieldReference',
|
|
715
|
+
text: 'astr',
|
|
716
|
+
definition: {
|
|
717
|
+
location: source.locations[0],
|
|
718
|
+
},
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
});
|
|
722
|
+
//# sourceMappingURL=locations.spec.js.map
|