@@ -508,4 +508,110 @@ describe('MySQL Syntax Suggestion', () => {
508
508
expect ( suggestion ) . not . toBeUndefined ( ) ;
509
509
expect ( suggestion ?. wordRanges . map ( ( token ) => token . text ) ) . toEqual ( [ 'test' , '.' , 'v' ] ) ;
510
510
} ) ;
511
+
512
+ test ( 'Select expression column' , ( ) => {
513
+ const pos : CaretPosition = {
514
+ lineNumber : 59 ,
515
+ column : 24 ,
516
+ } ;
517
+ const syntaxes = mysql . getSuggestionAtCaretPosition (
518
+ commentOtherLine ( syntaxSql , pos . lineNumber ) ,
519
+ pos
520
+ ) ?. syntax ;
521
+ const suggestion = syntaxes ?. find (
522
+ ( syn ) => syn . syntaxContextType === EntityContextType . COLUMN
523
+ ) ;
524
+
525
+ expect ( suggestion ) . not . toBeUndefined ( ) ;
526
+ expect ( suggestion ?. wordRanges . map ( ( token ) => token . text ) ) . toEqual ( [ 'salary' ] ) ;
527
+ } ) ;
528
+
529
+ test ( 'Group by expression column' , ( ) => {
530
+ const pos : CaretPosition = {
531
+ lineNumber : 59 ,
532
+ column : 72 ,
533
+ } ;
534
+ const syntaxes = mysql . getSuggestionAtCaretPosition (
535
+ commentOtherLine ( syntaxSql , pos . lineNumber ) ,
536
+ pos
537
+ ) ?. syntax ;
538
+ const suggestion = syntaxes ?. find (
539
+ ( syn ) => syn . syntaxContextType === EntityContextType . COLUMN
540
+ ) ;
541
+
542
+ expect ( suggestion ) . not . toBeUndefined ( ) ;
543
+ expect ( suggestion ?. wordRanges . map ( ( token ) => token . text ) ) . toEqual ( [ 'user' ] ) ;
544
+ } ) ;
545
+
546
+ test ( 'Having expression column' , ( ) => {
547
+ const pos : CaretPosition = {
548
+ lineNumber : 59 ,
549
+ column : 91 ,
550
+ } ;
551
+ const syntaxes = mysql . getSuggestionAtCaretPosition (
552
+ commentOtherLine ( syntaxSql , pos . lineNumber ) ,
553
+ pos
554
+ ) ?. syntax ;
555
+ const suggestion = syntaxes ?. find (
556
+ ( syn ) => syn . syntaxContextType === EntityContextType . COLUMN
557
+ ) ;
558
+
559
+ expect ( suggestion ) . not . toBeUndefined ( ) ;
560
+ expect ( suggestion ?. wordRanges . map ( ( token ) => token . text ) ) . toEqual ( [ 'salary' ] ) ;
561
+ } ) ;
562
+
563
+ test ( 'Select expression column' , ( ) => {
564
+ const pos : CaretPosition = {
565
+ lineNumber : 59 ,
566
+ column : 46 ,
567
+ } ;
568
+ const syntaxes = mysql . getSuggestionAtCaretPosition (
569
+ commentOtherLine ( syntaxSql , pos . lineNumber ) ,
570
+ pos
571
+ ) ?. syntax ;
572
+ const suggestion = syntaxes ?. find (
573
+ ( syn ) => syn . syntaxContextType === EntityContextType . COLUMN
574
+ ) ;
575
+
576
+ expect ( suggestion ) . not . toBeUndefined ( ) ;
577
+ expect ( suggestion ?. wordRanges . map ( ( token ) => token . text ) ) . toEqual ( [ 'age' ] ) ;
578
+ } ) ;
579
+
580
+ test ( 'Join expression column' , ( ) => {
581
+ const pos : CaretPosition = {
582
+ lineNumber : 61 ,
583
+ column : 85 ,
584
+ } ;
585
+ const syntaxes = mysql . getSuggestionAtCaretPosition (
586
+ commentOtherLine ( syntaxSql , pos . lineNumber ) ,
587
+ pos
588
+ ) ?. syntax ;
589
+ const suggestion = syntaxes ?. find (
590
+ ( syn ) => syn . syntaxContextType === EntityContextType . COLUMN
591
+ ) ;
592
+
593
+ expect ( suggestion ) . not . toBeUndefined ( ) ;
594
+ expect ( suggestion ?. wordRanges . map ( ( token ) => token . text ) ) . toEqual ( [
595
+ 'p' ,
596
+ '.' ,
597
+ 'category_id' ,
598
+ ] ) ;
599
+ } ) ;
600
+
601
+ test ( 'Case expression column' , ( ) => {
602
+ const pos : CaretPosition = {
603
+ lineNumber : 63 ,
604
+ column : 30 ,
605
+ } ;
606
+ const syntaxes = mysql . getSuggestionAtCaretPosition (
607
+ commentOtherLine ( syntaxSql , pos . lineNumber ) ,
608
+ pos
609
+ ) ?. syntax ;
610
+ const suggestion = syntaxes ?. find (
611
+ ( syn ) => syn . syntaxContextType === EntityContextType . COLUMN
612
+ ) ;
613
+
614
+ expect ( suggestion ) . not . toBeUndefined ( ) ;
615
+ expect ( suggestion ?. wordRanges . map ( ( token ) => token . text ) ) . toEqual ( [ 'score' ] ) ;
616
+ } ) ;
511
617
} ) ;
0 commit comments