@@ -181,7 +181,7 @@ suite('Playground Selected CodeAction Provider Test Suite', function () {
181
181
expect ( codeActions ) . to . exist ;
182
182
183
183
if ( codeActions ) {
184
- expect ( codeActions . length ) . to . be . equal ( 6 ) ;
184
+ expect ( codeActions . length ) . to . be . equal ( 7 ) ;
185
185
const actionCommand = codeActions [ 2 ] . command ;
186
186
187
187
if ( actionCommand ) {
@@ -217,7 +217,7 @@ suite('Playground Selected CodeAction Provider Test Suite', function () {
217
217
expect ( codeActions ) . to . exist ;
218
218
219
219
if ( codeActions ) {
220
- expect ( codeActions . length ) . to . be . equal ( 6 ) ;
220
+ expect ( codeActions . length ) . to . be . equal ( 7 ) ;
221
221
const actionCommand = codeActions [ 2 ] . command ;
222
222
223
223
if ( actionCommand ) {
@@ -282,7 +282,7 @@ suite('Playground Selected CodeAction Provider Test Suite', function () {
282
282
expect ( codeActions ) . to . exist ;
283
283
284
284
if ( codeActions ) {
285
- expect ( codeActions . length ) . to . be . equal ( 6 ) ;
285
+ expect ( codeActions . length ) . to . be . equal ( 7 ) ;
286
286
const actionCommand = codeActions [ 3 ] . command ;
287
287
288
288
if ( actionCommand ) {
@@ -351,7 +351,7 @@ suite('Playground Selected CodeAction Provider Test Suite', function () {
351
351
expect ( codeActions ) . to . exist ;
352
352
353
353
if ( codeActions ) {
354
- expect ( codeActions . length ) . to . be . equal ( 6 ) ;
354
+ expect ( codeActions . length ) . to . be . equal ( 7 ) ;
355
355
const actionCommand = codeActions [ 1 ] . command ;
356
356
357
357
if ( actionCommand ) {
@@ -426,7 +426,7 @@ suite('Playground Selected CodeAction Provider Test Suite', function () {
426
426
expect ( codeActions ) . to . exist ;
427
427
428
428
if ( codeActions ) {
429
- expect ( codeActions . length ) . to . be . equal ( 6 ) ;
429
+ expect ( codeActions . length ) . to . be . equal ( 7 ) ;
430
430
const actionCommand = codeActions [ 5 ] . command ;
431
431
432
432
if ( actionCommand ) {
@@ -474,6 +474,81 @@ suite('Playground Selected CodeAction Provider Test Suite', function () {
474
474
}
475
475
}
476
476
} ) ;
477
+
478
+ test ( 'exports to go and includes driver syntax' , async ( ) => {
479
+ const textFromEditor = "use('db'); db.coll.find({ name: '22' })" ;
480
+ const selection = {
481
+ start : { line : 0 , character : 24 } ,
482
+ end : { line : 0 , character : 38 } ,
483
+ } as vscode . Selection ;
484
+ const mode = ExportToLanguageMode . QUERY ;
485
+ const activeTextEditor = {
486
+ document : { getText : ( ) => textFromEditor } ,
487
+ } as vscode . TextEditor ;
488
+
489
+ mdbTestExtension . testExtensionController . _playgroundController . _selectedText =
490
+ "{ name: '22' }" ;
491
+ mdbTestExtension . testExtensionController . _playgroundController . _playgroundSelectedCodeActionProvider . selection =
492
+ selection ;
493
+ mdbTestExtension . testExtensionController . _playgroundController . _playgroundSelectedCodeActionProvider . mode =
494
+ mode ;
495
+ mdbTestExtension . testExtensionController . _playgroundController . _activeTextEditor =
496
+ activeTextEditor ;
497
+
498
+ testCodeActionProvider . refresh ( { selection, mode } ) ;
499
+
500
+ const codeActions = testCodeActionProvider . provideCodeActions ( ) ;
501
+ expect ( codeActions ) . to . exist ;
502
+
503
+ if ( codeActions ) {
504
+ expect ( codeActions . length ) . to . be . equal ( 7 ) ;
505
+ const actionCommand = codeActions [ 6 ] . command ;
506
+
507
+ if ( actionCommand ) {
508
+ expect ( actionCommand . command ) . to . be . equal ( 'mdb.exportToGo' ) ;
509
+ expect ( actionCommand . title ) . to . be . equal ( 'Export To Go' ) ;
510
+
511
+ await vscode . commands . executeCommand ( actionCommand . command ) ;
512
+
513
+ let expectedResult : PlaygroundResult = {
514
+ namespace : 'DATABASE_NAME.COLLECTION_NAME' ,
515
+ type : null ,
516
+ content : 'bson.D{{"name", "22"}}' ,
517
+ language : 'go' ,
518
+ } ;
519
+ expect (
520
+ mdbTestExtension . testExtensionController . _playgroundController
521
+ . _playgroundResult
522
+ ) . to . be . deep . equal ( expectedResult ) ;
523
+
524
+ const codeLenses =
525
+ mdbTestExtension . testExtensionController . _playgroundController . _exportToLanguageCodeLensProvider . provideCodeLenses ( ) ;
526
+ expect ( codeLenses . length ) . to . be . equal ( 2 ) ;
527
+
528
+ await vscode . commands . executeCommand (
529
+ 'mdb.changeExportToLanguageAddons' ,
530
+ {
531
+ ...mdbTestExtension . testExtensionController . _playgroundController
532
+ . _exportToLanguageCodeLensProvider . _exportToLanguageAddons ,
533
+ driverSyntax : true ,
534
+ }
535
+ ) ;
536
+
537
+ expectedResult = {
538
+ namespace : 'db.coll' ,
539
+ type : null ,
540
+ content :
541
+ '// Requires the MongoDB Go Driver\n// https://go.mongodb.org/mongo-driver\nctx := context.TODO()\n\n// Set client options\nclientOptions := options.Client().ApplyURI("mongodb://localhost:27018/?appname=mongodb-vscode+0.0.0-dev.0")\n\n// Connect to MongoDB\nclient, err := mongo.Connect(ctx, clientOptions)\nif err != nil {\n log.Fatal(err)\n}\ndefer func() {\n if err := client.Disconnect(ctx); err != nil {\n log.Fatal(err)\n }\n}()\n\n// Find data\ncoll := client.Database("db").Collection("coll")\n_, err = coll.Find(ctx, bson.D{{"name", "22"}})\nif err != nil {\n log.Fatal(err)\n}' ,
542
+ language : 'go' ,
543
+ } ;
544
+
545
+ expect (
546
+ mdbTestExtension . testExtensionController . _playgroundController
547
+ . _playgroundResult
548
+ ) . to . be . deep . equal ( expectedResult ) ;
549
+ }
550
+ }
551
+ } ) ;
477
552
} ) ;
478
553
479
554
suite ( 'the regular JS file' , ( ) => {
0 commit comments