forked from neo4j/cypher-language-support
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedgecases.test.ts
627 lines (578 loc) · 22.5 KB
/
edgecases.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
import { formatQuery } from '../../formatting/formatting';
import { verifyFormatting } from './testutil';
describe('various edgecases', () => {
test('Should be space in between', () => {
const query = 'Call call';
const expected = 'CALL call';
verifyFormatting(query, expected);
});
test('multiple queries', () => {
const multiquery = 'RETURN 1; RETURN 2; RETURN 3;';
const expectedMultiquery = `RETURN 1;
RETURN 2;
RETURN 3;`;
verifyFormatting(multiquery, expectedMultiquery);
});
test('should not add space for parameter access', () => {
const query = 'RETURN $param';
const expected = 'RETURN $param';
verifyFormatting(query, expected);
});
test('syntax error', () => {
const query = 'MATCH (n) RETRUN n.prop,';
expect(() => formatQuery(query)).toThrowError(
`Could not format due to syntax error at line 1:10 near "RETRUN"`,
);
});
test('apoc call, namespaced function', () => {
const query = `RETURN apoc.text.levenshteinSimilarity("Neo4j", "Neo4j") AS output;`;
const expected = `RETURN apoc.text.levenshteinSimilarity("Neo4j", "Neo4j") AS output;`;
verifyFormatting(query, expected);
});
test('function calls with one or more args', () => {
const query1 = `RETURN split('original')`;
const expected1 = `RETURN split('original')`;
verifyFormatting(query1, expected1);
const query2 = `RETURN split('original', 'i')`;
const expected2 = `RETURN split('original', 'i')`;
verifyFormatting(query2, expected2);
const query3 = `RETURN coalesce('original', 'i', 'j', 'k')`;
const expected3 = `RETURN coalesce('original', 'i', 'j', 'k')`;
verifyFormatting(query3, expected3);
});
test('test for function invocation', () => {
const query = `MATCH (n)
RETURN count( DISTINCT n,a )`;
const expected = `MATCH (n)
RETURN count(DISTINCT n, a)`;
verifyFormatting(query, expected);
});
test('map projections', () => {
const query = `RETURN this {.id,.title} AS this`;
const expected = `RETURN this {.id, .title} AS this`;
verifyFormatting(query, expected);
});
test('path length in relationship pattern', () => {
const query = `MATCH (p:Person)-[r:LOVES*]-()
RETURN e`;
const expected = `MATCH (p:Person)-[r:LOVES*]-()
RETURN e`;
verifyFormatting(query, expected);
});
test('path length with specific length', () => {
const query = `MATCH (p:Person)-[r:LOVES*5]-()
RETURN e`;
const expected = `MATCH (p:Person)-[r:LOVES*5]-()
RETURN e`;
verifyFormatting(query, expected);
});
test('path length with different length ranges', () => {
const fromquery = `MATCH (p:Person)-[r:LOVES*1..]-()
RETURN e`;
const fromexpected = `MATCH (p:Person)-[r:LOVES*1..]-()
RETURN e`;
const toquery = `MATCH (p:Person)-[r:LOVES*..10]-()
RETURN e`;
const toexpected = `MATCH (p:Person)-[r:LOVES*..10]-()
RETURN e`;
const bothquery = `MATCH (p:Person)-[r:LOVES*1..10]-()
RETURN e`;
const bothexpected = `MATCH (p:Person)-[r:LOVES*1..10]-()
RETURN e`;
verifyFormatting(fromquery, fromexpected);
verifyFormatting(toquery, toexpected);
verifyFormatting(bothquery, bothexpected);
});
test('IS FLOAT and IS INTEGER should not be broken', () => {
const query = `MATCH (n)
WITH n, [k IN keys(n)] as list
UNWIND list as listItem
WITH n, listItem
WHERE (n[listItem] IS FLOAT OR n[listItem] IS INTEGER)
RETURN n`;
const expected = `MATCH (n)
WITH n, [k IN keys(n)] AS list
UNWIND list AS listItem
WITH n, listItem
WHERE (n[listItem] IS FLOAT OR n[listItem] IS INTEGER)
RETURN n`;
verifyFormatting(query, expected);
});
test('does not remove empty function call parentheses', () => {
const query = `CALL apoc.meta.stats() YIELD labels`;
const expected = `CALL apoc.meta.stats() YIELD labels`;
verifyFormatting(query, expected);
});
test('does not crash if empty call function', () => {
const query = `CALL apoc.periodic`;
const expected = `CALL apoc.periodic`;
verifyFormatting(query, expected);
});
test('should not forget about multiple clauses in foreach', () => {
const query = `
MATCH (n)
UNWIND n.list as items
FOREACH (item in items |
CREATE (p:Product {name: item})
CREATE (n)-[:CONTAINS]->(p)
)
RETURN n`;
const expected = `MATCH (n)
UNWIND n.list AS items
FOREACH (item IN items |
CREATE (p:Product {name: item})
CREATE (n)-[:CONTAINS]->(p)
)
RETURN n`;
verifyFormatting(query, expected);
});
test('keeps path length and relationship type together', () => {
const simplePath = `MATCH path = ()-[:type *]->()`;
const simplePathExpected = `MATCH path = ()-[:type*]->()`;
verifyFormatting(simplePath, simplePathExpected);
const complicatedPath = `MATCH path = ()-[:type *1..10]->()`;
const complicatedPathExpected = `MATCH path = ()-[:type*1..10]->()`;
verifyFormatting(complicatedPath, complicatedPathExpected);
const halfFilledPath = `MATCH path = ()-[:type * .. 10]->()`;
const halfFilledPathExpected = `MATCH path = ()-[:type*..10]->()`;
verifyFormatting(halfFilledPath, halfFilledPathExpected);
});
test('can handle weird minuses', () => {
const query = `EXPLAIN MATCH (u:User)-[:WROTE]-> (r:Review)–[]–> (b:Business)-[:IN]-> (c:Category)
WHERE b.name = "XGyhUMQO"
RETURN u, r, b, c`;
const expected = `EXPLAIN
MATCH (u:User)-[:WROTE]->(r:Review)–[]–>(b:Business)-[:IN]->(c:Category)
WHERE b.name = "XGyhUMQO"
RETURN u, r, b, c`;
verifyFormatting(query, expected);
});
test('does not concatenate IS X', () => {
const query = `MATCH (n)
WHERE CASE WHEN n["asdf"] IS STRING THEN n.prop ELSE 'default' END
return n`;
const expected = `MATCH (n)
WHERE
CASE
WHEN n["asdf"] IS STRING THEN n.prop
ELSE 'default'
END
RETURN n`;
verifyFormatting(query, expected);
});
test('multiple case statments after each other', () => {
const query = `RETURN {Node: p.Node, description:CASE
WHEN p.Description IS NULL OR size(p.Description) = "TxWb1jb3" THEN []
ELSE p.Description[.. "VM6fSkTL"]
END} AS node, r, {Node: b.Node, description:
CASE
WHEN b.Description IS NULL OR size(b.Description) = "wnBMZdOC" THEN []
ELSE b.Description[.. "NHIwucAy"]
END} AS endNode;`;
const expected = `RETURN {Node: p.Node, description:
CASE
WHEN p.Description IS NULL OR size(p.Description) = "TxWb1jb3" THEN []
ELSE p.Description[.. "VM6fSkTL"]
END} AS node, r, {Node: b.Node, description:
CASE
WHEN b.Description IS NULL OR size(b.Description) = "wnBMZdOC" THEN []
ELSE b.Description[.. "NHIwucAy"]
END} AS endNode;`;
verifyFormatting(query, expected);
});
test('multiple case statements with extended case', () => {
const query = `RETURN {Node: p.Node, description:CASE p.age
WHEN p.Description IS NULL OR size(p.Description) = "TxWb1jb3" THEN []
ELSE p.Description[.. "VM6fSkTL"]
END} AS node, r, {Node: b.Node, description:
CASE p.age
WHEN b.Description IS NULL OR size(b.Description) = "wnBMZdOC" THEN []
ELSE b.Description[.. "NHIwucAy"]
END} AS endNode;`;
const expected = `RETURN {Node: p.Node, description:
CASE p.age
WHEN p.Description IS NULL OR size(p.Description) = "TxWb1jb3" THEN []
ELSE p.Description[.. "VM6fSkTL"]
END} AS node, r, {Node: b.Node, description:
CASE p.age
WHEN b.Description IS NULL OR size(b.Description) = "wnBMZdOC" THEN []
ELSE b.Description[.. "NHIwucAy"]
END} AS endNode;`;
verifyFormatting(query, expected);
});
test('case statements where wrapping line occurs in a when statement', () => {
const query = `RETURN
CASE
WHEN SUM(product.price) >= 100 AND SUM(product.price) < 500 THEN 'Medium Spender'
WHEN SUM(product.price) >= 500 AND SUM(product.price) < 1000 AND SUM(product.price) < 1000 AND SUM(product.price) < 1000 THEN 'High Spender'
ELSE 'VIP Customer'
END AS CustomerCategory`;
const expected = `RETURN
CASE
WHEN SUM(product.price) >= 100 AND SUM(product.price) < 500
THEN 'Medium Spender'
WHEN SUM(product.price) >= 500 AND SUM(product.price) < 1000 AND
SUM(product.price) < 1000 AND SUM(product.price) < 1000 THEN
'High Spender'
ELSE 'VIP Customer'
END AS CustomerCategory`;
verifyFormatting(query, expected);
});
test('extended case statements where wrapping line occurs in a when statement', () => {
const query = `RETURN
CASE p.age
WHEN SUM(product.price) >= 100 AND SUM(product.price) < 500 THEN 'Medium Spender'
WHEN SUM(product.price) >= 500 AND SUM(product.price) < 1000 AND SUM(product.price) < 1000 AND SUM(product.price) < 1000 THEN 'High Spender'
ELSE 'VIP Customer'
END AS CustomerCategory`;
const expected = `RETURN
CASE p.age
WHEN SUM(product.price) >= 100 AND SUM(product.price) < 500
THEN 'Medium Spender'
WHEN SUM(product.price) >= 500 AND SUM(product.price) < 1000 AND
SUM(product.price) < 1000 AND SUM(product.price) < 1000 THEN
'High Spender'
ELSE 'VIP Customer'
END AS CustomerCategory`;
verifyFormatting(query, expected);
});
test('deeply nested case', () => {
const query = `
WITH s,
t.name as tableName,
collect({name: c.name,
pk: CASE (not pk is null and $printKeyInfo) WHEN True AND TRUE AND
TRUE AND TRUE AND TRUE AND TRUE AND TRUE AND TRUE AND TRUE THEN "(PK)" ELSE "" END,
fk: CASE WHEN True AND TRUE AND TRUE AND TRUE AND TRUE
AND TRUE AND TRUE AND TRUE AND TRUE AND TRUE AND TRUE AND TRUE
AND TRUE AND TRUE AND TRUE AND TRUE AND TRUE AND TRUE AND TRUE THEN "(FK)" ELSE "" END
}) as columns`;
const expected = `WITH s, t.name AS tableName, collect({name: c.name, pk:
CASE (NOT pk IS NULL AND $printKeyInfo)
WHEN true AND true AND true AND true AND
true AND true AND true AND true AND true THEN "(PK)"
ELSE ""
END, fk:
CASE
WHEN true AND true AND true AND true AND true AND true AND true AND true AND
true AND true AND true AND true AND true AND true AND true AND true AND
true AND true AND true THEN "(FK)"
ELSE ""
END}) AS columns`;
verifyFormatting(query, expected);
});
test('nesting case statement inside case statements', () => {
const query = `MATCH (p:Person)
RETURN p.name,
p.age,
p.occupation,
CASE
WHEN p.age < 18 THEN 'Minor'
WHEN p.age >= 18 AND p.age < 65 THEN
CASE
WHEN p.occupation = 'Student' THEN 'Student (Adult)'
WHEN p.occupation = 'Engineer' THEN
CASE
WHEN p.experienceYears < 5 THEN 'Junior Engineer'
WHEN p.experienceYears >= 5 AND p.experienceYears < 10 THEN 'Mid-level Engineer'
ELSE 'Senior Engineer'
END
WHEN p.occupation = 'Doctor' THEN
CASE
WHEN p.specialty = 'Pediatrics' THEN 'Pediatrician'
WHEN p.specialty = 'Cardiology' THEN 'Cardiologist'
ELSE 'Medical Doctor'
END
ELSE 'Working Adult'
END
ELSE 'Senior'
END AS status,
CASE
WHEN p.salary IS NULL THEN 'No Income Data'
ELSE
CASE
WHEN p.salary < 30000 THEN 'Low Income'
WHEN p.salary >= 30000 AND p.salary < 75000 THEN 'Middle Income'
WHEN p.salary >= 75000 AND p.salary < 150000 THEN 'Upper Middle Income'
ELSE 'High Income'
END
END AS incomeCategory
ORDER BY p.age DESC`;
const expected = `MATCH (p:Person)
RETURN p.name, p.age, p.occupation,
CASE
WHEN p.age < 18 THEN 'Minor'
WHEN p.age >= 18 AND p.age < 65 THEN
CASE
WHEN p.occupation = 'Student' THEN 'Student (Adult)'
WHEN p.occupation = 'Engineer' THEN
CASE
WHEN p.experienceYears < 5 THEN 'Junior Engineer'
WHEN p.experienceYears >= 5 AND p.experienceYears < 10 THEN
'Mid-level Engineer'
ELSE 'Senior Engineer'
END
WHEN p.occupation = 'Doctor' THEN
CASE
WHEN p.specialty = 'Pediatrics' THEN 'Pediatrician'
WHEN p.specialty = 'Cardiology' THEN 'Cardiologist'
ELSE 'Medical Doctor'
END
ELSE 'Working Adult'
END
ELSE 'Senior'
END AS status,
CASE
WHEN p.salary IS NULL THEN 'No Income Data'
ELSE
CASE
WHEN p.salary < 30000 THEN 'Low Income'
WHEN p.salary >= 30000 AND p.salary < 75000 THEN 'Middle Income'
WHEN p.salary >= 75000 AND p.salary < 150000 THEN 'Upper Middle Income'
ELSE 'High Income'
END
END AS incomeCategory ORDER BY p.age DESC`;
verifyFormatting(query, expected);
});
test('does not break CALL YIELD', () => {
const query = `CALL dbms.procedures YIELD name, signature, description`;
const expected = `CALL dbms.procedures YIELD name, signature, description`;
verifyFormatting(query, expected);
});
test('handles CALL YIELD with no args gracefully', () => {
const query = `call dbms.components() yield *`;
const expected = `CALL dbms.components() YIELD *`;
verifyFormatting(query, expected);
});
test('handles CALL YIELD case with one arg gracefully', () => {
const query = `call dbms.components(1) yield *`;
const expected = `CALL dbms.components(1) YIELD *`;
verifyFormatting(query, expected);
});
test('does not move explicitly newlined comments to the line before', () => {
const query = `MATCH (n)
// filter out to only the right name
WHERE n.name = 'Tomas'
RETURN n`;
const expected = `MATCH (n)
// filter out to only the right name
WHERE n.name = 'Tomas'
RETURN n`;
verifyFormatting(query, expected);
});
test('graph pattern matching spacing', () => {
const query = `MATCH (m:(Adventure&Children) & ! (War&Crime))
RETURN m`;
const expected = `MATCH (m:(Adventure&Children)&!(War&Crime))
RETURN m`;
verifyFormatting(query, expected);
});
test('quantified path pattern spacing', () => {
const query = `MATCH ((:Station {name: 'Denmark Hill'})-[l:LINK]-(s:Station)){ 1 , 4 }`;
const expected = `MATCH ((:Station {name: 'Denmark Hill'})-[l:LINK]-(s:Station)){1,4}`;
verifyFormatting(query, expected);
});
// Example 1 by Finbar
test('QPP spacing with star', () => {
const query = `
MATCH (p:Person)-[:ACTED_IN | DIRECTED]-> * (q)
RETURN q`;
const expected = `MATCH (p:Person)-[:ACTED_IN|DIRECTED]->*(q)
RETURN q`;
verifyFormatting(query, expected);
});
// Example 2 by Finbar
test('QPP spacing with unspecified start', () => {
const query = `MATCH SHORTEST 1(p:Person)-->{, 3}(q)
RETURN q;`;
const expected = `MATCH SHORTEST 1 (p:Person)-->{ ,3}(q)
RETURN q;`;
verifyFormatting(query, expected);
});
// Example 3 by Finbar
test('QPP spacing with unspecified end', () => {
const query = `MATCH (p:(! Movie | !(Director & ! Actor)))-->{1, }(q)
RETURN *;`;
const expected = `MATCH (p:(!Movie|!(Director&!Actor)))-->{1, }(q)
RETURN *;`;
verifyFormatting(query, expected);
});
test('all should not get capitalized here', () => {
const query = `MATCH path=(:Station&Western)(()-[:NEXT]->()){1,}(:Station&Western)
WHERE all(x IN nodes(path) WHERE x:Station&Western)
RETURN path`;
const expected = `MATCH path = (:Station&Western) (()-[:NEXT]->()){1, }(:Station&Western)
WHERE all(x IN nodes(path) WHERE x:Station&Western)
RETURN path`;
verifyFormatting(query, expected);
});
test('weird label expression', () => {
const query = `MATCH (n)-[:ACTED_IN|AMPLIFIES|:SCREAMS|OBSERVES|:ANALYZES]-(m)
RETURN n`;
const expected = `MATCH (n)-[:ACTED_IN|AMPLIFIES|:SCREAMS|OBSERVES|:ANALYZES]-(m)
RETURN n`;
verifyFormatting(query, expected);
});
test('comments should not start replicating themselves', () => {
const query = `CALL gds.graph.project(
"qk5jpmGl", // Name of the projected graph
["TB4Tvv6q", "2iCI1Rll", "kaLEqBxX"], // Node labels to include
{
connection: {
type: "R3e8WLkh", // Include all relationships
orientation: "weFW44Gy" // Treat relationships as undirected
}
}
)
YIELD graphName, nodeCount, relationshipCount, createMillis
RETURN graphName, nodeCount, relationshipCount, createMillis;`;
const expected = `CALL gds.graph.project("qk5jpmGl", // Name of the projected graph
["TB4Tvv6q", "2iCI1Rll", "kaLEqBxX"], // Node labels to include
{connection: {type: "R3e8WLkh", // Include all relationships
orientation: "weFW44Gy"}}) // Treat relationships as undirected
YIELD graphName, nodeCount, relationshipCount, createMillis
RETURN graphName, nodeCount, relationshipCount, createMillis;`;
verifyFormatting(query, expected);
});
test('comment should not disappear in this query', () => {
const query = `MATCH (n)
WITH *, n.prop, // This comment should not disappear
n.otherprop
RETURN n`;
const expected = `MATCH (n)
WITH *, n.prop, // This comment should not disappear
n.otherprop
RETURN n`;
verifyFormatting(query, expected);
});
test('should not find the wrong comma here', () => {
const query = `CALL gds.nodeSimilarity.filtered.stream(
"N5j8G3h2",
{
A3f7R: "Z2w8Q",
L9t4P: "Y3s1D"
}
) YIELD *`;
const expected = `CALL gds.nodeSimilarity.filtered.stream("N5j8G3h2",
{A3f7R: "Z2w8Q", L9t4P: "Y3s1D"})
YIELD *`;
verifyFormatting(query, expected);
});
test('aligns and breaks long namespaced functions well 1', () => {
const query = `MATCH (u:User)
WITH u, apoc.util.validate(u.status <> 'active', 'User ' + u.username + ' does not have an active status which is required for processing the requested operation. ' + 'Please check the user account settings for further details.', [u.id, u.username]) AS validation
RETURN u;`;
const expected = `MATCH (u:User)
WITH u,
apoc.util.
validate(u.status <> 'active',
'User ' + u.username +
' does not have an active status which is required for processing the requested operation. '
+ 'Please check the user account settings for further details.',
[u.id, u.username]) AS validation
RETURN u;`;
verifyFormatting(query, expected);
});
test('aligns and breaks long namespaced functions well 2', () => {
const query = `MATCH (userAccountInfo:UserAccountInformation)
WITH userAccountInfo,
apoc.util.
validate(NOT userAccountInfo.isVerified,
'Verification Error: The user account with unique identifier ' +
userAccountInfo.accountUniqueIdentifier +
' has not completed the mandatory ' +
'verification process required for accessing premium features. ' +
'Please review your verification email and follow the provided instructions to secure your account.',
[userAccountInfo.accountUniqueIdentifier,
userAccountInfo.emailAddress]) AS verificationStatus
RETURN userAccountInfo;`;
const expected = query;
verifyFormatting(query, expected);
});
test('aligns and breaks long namespaced functions well 3', () => {
const query = `MATCH (inventoryRecord:ProductInventoryTrackingInformation)
WITH inventoryRecord,
apoc.util.
validate(inventoryRecord.currentStock
< inventoryRecord.criticalThresholdStock,
'Alert: The inventory record for product SKU '
+ inventoryRecord.productSKU
+ ' indicates a current stock level of '
+ toString(inventoryRecord.currentStock)
+ ', which is below the critical threshold of ' +
toString(inventoryRecord.criticalThresholdStock) +
'. Immediate replenishment is required to avoid stockouts and maintain supply chain stability.',
[inventoryRecord.productSKU, inventoryRecord.currentStock])
AS stockValidation
RETURN inventoryRecord;`;
const expected = query;
verifyFormatting(query, expected);
});
test('should not leave dangling bracket', () => {
const query = `CREATE (company:Company
{name: "mrUJWq6A", krs: "Yuu9Wl7d", registration_date: date("FrA1uHGX")
});`;
const expected = `CREATE (company:Company {name: "mrUJWq6A", krs: "Yuu9Wl7d",
registration_date: date("FrA1uHGX")});`;
verifyFormatting(query, expected);
});
test('should align with list predicate', () => {
const query = `MATCH (f:Frequency)
WHERE f.value > "WhbRf4O4" AND
ALL(x IN RANGE("gemqfwmW", TOINTEGER(FLOOR(SQRT(f.value)))) WHERE f.value
% x <> "5DOeV3TE")
SET f.prime = "zt01uZOH"
RETURN f`;
const expected = `MATCH (f:Frequency)
WHERE f.value > "WhbRf4O4" AND
ALL(x IN RANGE("gemqfwmW", TOINTEGER(FLOOR(SQRT(f.value)))) WHERE f.value
% x <> "5DOeV3TE")
SET f.prime = "zt01uZOH"
RETURN f`;
verifyFormatting(query, expected);
});
test('map projections should line up like maps 1', () => {
const query = `MATCH (p:Person {name: "Alice"})
RETURN p {.name, .age, .email, .phone, .address, .occupation, .nationality,
.birthdate, .gender} AS personInfo`;
const expected = `MATCH (p:Person {name: "Alice"})
RETURN p {.name, .age, .email, .phone, .address, .occupation, .nationality,
.birthdate, .gender} AS personInfo`;
verifyFormatting(query, expected);
});
test('map projections should line up like maps 1', () => {
const query = `MATCH (p:Person {name: "Alice"})-[:LIVES_IN]->(c:City)
RETURN p {.name, .age, .email, .phone, address:
{street: p.street, city: c.name, zip: p.zip}, .occupation, .nationality,
.birthdate, .gender} AS personInfo`;
const expected = `MATCH (p:Person {name: "Alice"})-[:LIVES_IN]->(c:City)
RETURN p {.name, .age, .email, .phone,
address: {street: p.street, city: c.name, zip: p.zip}, .occupation,
.nationality, .birthdate, .gender} AS personInfo`;
verifyFormatting(query, expected);
});
test('should remember all clauses in foreach', () => {
const query = `
MATCH (n)
UNWIND n.list as items
FOREACH (item in items |
CREATE (p:Product {name: item})
CREATE (n)-[:CONTAINS]->(p)
)
RETURN n`;
const expected = `MATCH (n)
UNWIND n.list AS items
FOREACH (item IN items |
CREATE (p:Product {name: item})
CREATE (n)-[:CONTAINS]->(p)
)
RETURN n`;
verifyFormatting(query, expected);
});
test('relation with IS CONNECTED should not concatenate to ISCONNECTED', () => {
const query = `MATCH (n)-[IS CONNECTED]->(m)
RETURN n, m`;
const expected = query;
verifyFormatting(query, expected);
});
});