@@ -4,14 +4,16 @@ import { signatures as shellSignatures, Topologies } from '@mongosh/shell-api';
4
4
import { expect } from 'chai' ;
5
5
6
6
let collections : string [ ] ;
7
+ let databases : string [ ] ;
7
8
const standalone440 = {
8
9
topology : ( ) => Topologies . Standalone ,
9
10
connectionInfo : ( ) => ( {
10
11
is_atlas : false ,
11
12
is_data_lake : false ,
12
13
server_version : '4.4.0'
13
14
} ) ,
14
- getCollectionCompletionsForCurrentDb : ( ) => collections
15
+ getCollectionCompletionsForCurrentDb : ( ) => collections ,
16
+ getDatabaseCompletions : ( ) => databases
15
17
} ;
16
18
const sharded440 = {
17
19
topology : ( ) => Topologies . Sharded ,
@@ -20,7 +22,8 @@ const sharded440 = {
20
22
is_data_lake : false ,
21
23
server_version : '4.4.0'
22
24
} ) ,
23
- getCollectionCompletionsForCurrentDb : ( ) => collections
25
+ getCollectionCompletionsForCurrentDb : ( ) => collections ,
26
+ getDatabaseCompletions : ( ) => databases
24
27
} ;
25
28
26
29
const standalone300 = {
@@ -30,7 +33,8 @@ const standalone300 = {
30
33
is_data_lake : false ,
31
34
server_version : '3.0.0'
32
35
} ) ,
33
- getCollectionCompletionsForCurrentDb : ( ) => collections
36
+ getCollectionCompletionsForCurrentDb : ( ) => collections ,
37
+ getDatabaseCompletions : ( ) => databases
34
38
} ;
35
39
const datalake440 = {
36
40
topology : ( ) => Topologies . Sharded ,
@@ -39,13 +43,15 @@ const datalake440 = {
39
43
is_data_lake : true ,
40
44
server_version : '4.4.0'
41
45
} ) ,
42
- getCollectionCompletionsForCurrentDb : ( ) => collections
46
+ getCollectionCompletionsForCurrentDb : ( ) => collections ,
47
+ getDatabaseCompletions : ( ) => databases
43
48
} ;
44
49
45
50
const noParams = {
46
51
topology : ( ) => Topologies . Standalone ,
47
52
connectionInfo : ( ) => undefined ,
48
- getCollectionCompletionsForCurrentDb : ( ) => collections
53
+ getCollectionCompletionsForCurrentDb : ( ) => collections ,
54
+ getDatabaseCompletions : ( ) => databases
49
55
} ;
50
56
51
57
describe ( 'completer.completer' , ( ) => {
@@ -66,7 +72,7 @@ describe('completer.completer', () => {
66
72
67
73
it ( 'is an exact match to one of shell completions' , async ( ) => {
68
74
const i = 'use' ;
69
- expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [ [ i ] , i ] ) ;
75
+ expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [ [ ] , i , 'exclusive' ] ) ;
70
76
} ) ;
71
77
} ) ;
72
78
@@ -482,4 +488,50 @@ describe('completer.completer', () => {
482
488
expect ( await completer ( standalone440 , i ) ) . to . deep . equal ( [ [ ] , i ] ) ;
483
489
} ) ;
484
490
} ) ;
491
+
492
+ context ( 'for shell commands' , ( ) => {
493
+ it ( 'completes partial commands' , async ( ) => {
494
+ const i = 'sho' ;
495
+ expect ( await completer ( noParams , i ) )
496
+ . to . deep . equal ( [ [ 'show' ] , i ] ) ;
497
+ } ) ;
498
+
499
+ it ( 'completes partial commands' , async ( ) => {
500
+ const i = 'show' ;
501
+ const result = await completer ( noParams , i ) ;
502
+ expect ( result [ 0 ] ) . to . contain ( 'show databases' ) ;
503
+ } ) ;
504
+
505
+ it ( 'completes show databases' , async ( ) => {
506
+ const i = 'show d' ;
507
+ expect ( await completer ( noParams , i ) )
508
+ . to . deep . equal ( [ [ 'show databases' ] , i , 'exclusive' ] ) ;
509
+ } ) ;
510
+
511
+ it ( 'completes show profile' , async ( ) => {
512
+ const i = 'show pr' ;
513
+ expect ( await completer ( noParams , i ) )
514
+ . to . deep . equal ( [ [ 'show profile' ] , i , 'exclusive' ] ) ;
515
+ } ) ;
516
+
517
+ it ( 'completes use db' , async ( ) => {
518
+ databases = [ 'db1' , 'db2' ] ;
519
+ const i = 'use' ;
520
+ expect ( await completer ( noParams , i ) )
521
+ . to . deep . equal ( [ [ 'use db1' , 'use db2' ] , i , 'exclusive' ] ) ;
522
+ } ) ;
523
+
524
+ it ( 'does not try to complete over-long commands' , async ( ) => {
525
+ databases = [ 'db1' , 'db2' ] ;
526
+ const i = 'use db1 d' ;
527
+ expect ( await completer ( noParams , i ) )
528
+ . to . deep . equal ( [ [ ] , i , 'exclusive' ] ) ;
529
+ } ) ;
530
+
531
+ it ( 'completes commands like exit' , async ( ) => {
532
+ const i = 'exi' ;
533
+ expect ( await completer ( noParams , i ) )
534
+ . to . deep . equal ( [ [ 'exit' ] , i ] ) ;
535
+ } ) ;
536
+ } ) ;
485
537
} ) ;
0 commit comments