@@ -7,6 +7,7 @@ const dbSchema = {
77 'Pokemon' ,
88 'Trainer' ,
99 'Gym' ,
10+ 'Region' ,
1011 'Type' ,
1112 'Move' ,
1213 'UnrelatedLabel' ,
@@ -16,16 +17,24 @@ const dbSchema = {
1617 'CATCHES' ,
1718 'TRAINS' ,
1819 'BATTLES' ,
20+ 'CHALLENGES' ,
1921 'KNOWS' ,
2022 'WEAK_TO' ,
23+ 'STRONG_AGAINST' ,
24+ 'IS_IN' ,
2125 'UNRELATED_RELTYPE' ,
2226 ] ,
2327 graphSchema : [
2428 { from : 'Trainer' , relType : 'CATCHES' , to : 'Pokemon' } ,
2529 { from : 'Trainer' , relType : 'TRAINS' , to : 'Pokemon' } ,
2630 { from : 'Trainer' , relType : 'BATTLES' , to : 'Trainer' } ,
31+ { from : 'Trainer' , relType : 'IS_IN' , to : 'Region' } ,
32+ { from : 'Gym' , relType : 'IS_IN' , to : 'Region' } ,
33+ { from : 'Trainer' , relType : 'CHALLENGES' , to : 'Gym' } ,
34+ { from : 'Pokemon' , relType : 'CHALLENGES' , to : 'Gym' } ,
2735 { from : 'Pokemon' , relType : 'KNOWS' , to : 'Move' } ,
2836 { from : 'Pokemon' , relType : 'WEAK_TO' , to : 'Type' } ,
37+ { from : 'Type' , relType : 'STRONG_AGAINST' , to : 'Type' } ,
2938 {
3039 from : 'UnrelatedLabel' ,
3140 relType : 'UNRELATED_RELTYPE' ,
@@ -236,14 +245,39 @@ RETURN [(p)-[:`;
236245 } ) ;
237246 } ) ;
238247
239- test ( 'Handles nodes with multiple labels properly' , ( ) => {
248+ test ( 'Handles nodes with multiple labels properly (AND logic) ' , ( ) => {
240249 const query = 'MATCH (n:Trainer) WHERE n:Pokemon MATCH (n)-[:' ;
241250
242251 testCompletions ( {
243252 query,
244253 dbSchema,
245254 computeSymbolsInfo : true ,
246255 expected : [
256+ { label : 'CHALLENGES' , kind : CompletionItemKind . TypeParameter } ,
257+ // Limitation: These should actually be excluded, but since we dont track direction yet, they are not
258+ // Note that even though we don't know the direction in the query, we can see in the graph schema that we don't
259+ // have ex. 'CATCHES' going to/from both Trainer and Pokemon, meaning it cant be going to/from a Pokemon&Trainer node
260+ { label : 'CATCHES' , kind : CompletionItemKind . TypeParameter } ,
261+ { label : 'TRAINS' , kind : CompletionItemKind . TypeParameter } ,
262+ ] ,
263+ excluded : [
264+ { label : 'UNRELATED_RELTYPE' , kind : CompletionItemKind . TypeParameter } ,
265+ { label : 'BATTLES' , kind : CompletionItemKind . TypeParameter } ,
266+ { label : 'KNOWS' , kind : CompletionItemKind . TypeParameter } ,
267+ { label : 'WEAK_TO' , kind : CompletionItemKind . TypeParameter } ,
268+ ] ,
269+ } ) ;
270+ } ) ;
271+
272+ test ( 'Handles nodes that have one of multiple labels (OR logic)' , ( ) => {
273+ const query = 'MATCH (x) WHERE x:Trainer OR x:Pokemon MATCH (x)-[:' ;
274+
275+ testCompletions ( {
276+ query,
277+ dbSchema,
278+ computeSymbolsInfo : true ,
279+ expected : [
280+ { label : 'CHALLENGES' , kind : CompletionItemKind . TypeParameter } ,
247281 { label : 'CATCHES' , kind : CompletionItemKind . TypeParameter } ,
248282 { label : 'TRAINS' , kind : CompletionItemKind . TypeParameter } ,
249283 { label : 'BATTLES' , kind : CompletionItemKind . TypeParameter } ,
@@ -256,6 +290,50 @@ RETURN [(p)-[:`;
256290 } ) ;
257291 } ) ;
258292
293+ test ( 'Handles deeper label trees, and mixing AND/OR logic' , ( ) => {
294+ const query = 'MATCH (x:Trainer) WHERE x:Gym OR x:Pokemon MATCH (x)-[:' ;
295+ // -> AND(Trainer, OR(Gym, Pokemon))
296+ testCompletions ( {
297+ query,
298+ dbSchema,
299+ computeSymbolsInfo : true ,
300+ expected : [
301+ { label : 'CHALLENGES' , kind : CompletionItemKind . TypeParameter } ,
302+ { label : 'IS_IN' , kind : CompletionItemKind . TypeParameter } ,
303+ // Limitation: These should actually be excluded, but since we dont track direction yet, they are not
304+ // Note that even though we don't know the direction in the query, we can see in the graph schema that we don't
305+ // have ex. 'CATCHES' going to/from both Trainer and Pokemon, meaning it cant be going to/from a Pokemon&Trainer node
306+ { label : 'CATCHES' , kind : CompletionItemKind . TypeParameter } ,
307+ { label : 'TRAINS' , kind : CompletionItemKind . TypeParameter } ,
308+ ] ,
309+ excluded : [
310+ { label : 'UNRELATED_RELTYPE' , kind : CompletionItemKind . TypeParameter } ,
311+ { label : 'BATTLES' , kind : CompletionItemKind . TypeParameter } ,
312+ { label : 'KNOWS' , kind : CompletionItemKind . TypeParameter } ,
313+ { label : 'WEAK_TO' , kind : CompletionItemKind . TypeParameter } ,
314+ ] ,
315+ } ) ;
316+ } ) ;
317+
318+ test ( 'Handles AND logic with self-referencing ' , ( ) => {
319+ const query = 'MATCH (x) WHERE x:Pokemon OR x:Type MATCH (x)-[:' ;
320+ testCompletions ( {
321+ query,
322+ dbSchema,
323+ computeSymbolsInfo : true ,
324+ expected : [
325+ { label : 'CHALLENGES' , kind : CompletionItemKind . TypeParameter } ,
326+ { label : 'KNOWS' , kind : CompletionItemKind . TypeParameter } ,
327+ { label : 'WEAK_TO' , kind : CompletionItemKind . TypeParameter } ,
328+ { label : 'STRONG_AGAINST' , kind : CompletionItemKind . TypeParameter } ,
329+ ] ,
330+ excluded : [
331+ { label : 'UNRELATED_RELTYPE' , kind : CompletionItemKind . TypeParameter } ,
332+ { label : 'BATTLES' , kind : CompletionItemKind . TypeParameter } ,
333+ ] ,
334+ } ) ;
335+ } ) ;
336+
259337 test ( 'Limitation: Does not handle union types, as they are not yet supported in symbol table ' , ( ) => {
260338 const query = 'MATCH (x:Pokemon|Trainer)-[r:' ;
261339
@@ -264,38 +342,56 @@ RETURN [(p)-[:`;
264342 dbSchema,
265343 computeSymbolsInfo : true ,
266344 expected : [
267- /* These should be included
268- { label: 'CATCHES', kind: CompletionItemKind.TypeParameter },
345+ /* Only these should be included
346+ { label: 'CHALLENGES', kind: CompletionItemKind.TypeParameter },
347+ { label: 'CATCHES', kind: CompletionItemKind.TypeParameter },
269348 { label: 'TRAINS', kind: CompletionItemKind.TypeParameter },
270349 { label: 'BATTLES', kind: CompletionItemKind.TypeParameter },
271350 { label: 'KNOWS', kind: CompletionItemKind.TypeParameter },
272351 { label: 'WEAK_TO', kind: CompletionItemKind.TypeParameter },
273352 */
353+ // For now, test bail working
354+ { label : 'CHALLENGES' , kind : CompletionItemKind . TypeParameter } ,
355+ { label : 'CATCHES' , kind : CompletionItemKind . TypeParameter } ,
356+ { label : 'TRAINS' , kind : CompletionItemKind . TypeParameter } ,
357+ { label : 'BATTLES' , kind : CompletionItemKind . TypeParameter } ,
358+ { label : 'KNOWS' , kind : CompletionItemKind . TypeParameter } ,
359+ { label : 'WEAK_TO' , kind : CompletionItemKind . TypeParameter } ,
360+ { label : 'UNRELATED_RELTYPE' , kind : CompletionItemKind . TypeParameter } ,
274361 ] ,
275362 excluded : [
276- { label : 'UNRELATED_RELTYPE' , kind : CompletionItemKind . TypeParameter } ,
363+ // { label: 'UNRELATED_RELTYPE', kind: CompletionItemKind.TypeParameter },
277364 ] ,
278365 } ) ;
279366 } ) ;
280367
281- test ( 'Limitation: Does not handle AND, OR, NOT, etc. ' , ( ) => {
282- const query = 'MATCH (x:Pokemon) WHERE x:Trainer MATCH (x)-[:' ;
283-
368+ test ( 'Limitation: Does not handle NOT' , ( ) => {
369+ const query = 'MATCH (x) WHERE NOT x:Trainer MATCH (x)-[:' ;
284370 testCompletions ( {
285371 query,
286372 dbSchema,
287373 computeSymbolsInfo : true ,
288- expected : [ ] ,
289- excluded : [
374+ expected : [
375+ // For now, test bail working
376+ { label : 'CHALLENGES' , kind : CompletionItemKind . TypeParameter } ,
377+ { label : 'KNOWS' , kind : CompletionItemKind . TypeParameter } ,
378+ { label : 'WEAK_TO' , kind : CompletionItemKind . TypeParameter } ,
290379 { label : 'UNRELATED_RELTYPE' , kind : CompletionItemKind . TypeParameter } ,
291- // no valid outgoing types something that's both a pokemon and a trainer
292- /*
293380 { label : 'CATCHES' , kind : CompletionItemKind . TypeParameter } ,
294381 { label : 'TRAINS' , kind : CompletionItemKind . TypeParameter } ,
295382 { label : 'BATTLES' , kind : CompletionItemKind . TypeParameter } ,
383+ /* These should be included
384+ { label: 'CHALLENGES', kind: CompletionItemKind.TypeParameter },
296385 { label: 'KNOWS', kind: CompletionItemKind.TypeParameter },
297386 { label: 'WEAK_TO', kind: CompletionItemKind.TypeParameter },
387+ */
388+ ] ,
389+ excluded : [
390+ /* These should be excluded
298391 { label: 'UNRELATED_RELTYPE', kind: CompletionItemKind.TypeParameter },
392+ { label: 'CATCHES', kind: CompletionItemKind.TypeParameter },
393+ { label: 'TRAINS', kind: CompletionItemKind.TypeParameter },
394+ { label: 'BATTLES', kind: CompletionItemKind.TypeParameter },
299395 */
300396 ] ,
301397 } ) ;
0 commit comments