@@ -1345,12 +1345,7 @@ describe('server', () => {
1345
1345
const { connection } = await initializeServer ( )
1346
1346
1347
1347
return connection . onPrepareRename . mock . calls [ 0 ] [ 0 ] (
1348
- {
1349
- textDocument : {
1350
- uri : FIXTURE_URI . RENAMING ,
1351
- } ,
1352
- position : { line, character } ,
1353
- } ,
1348
+ { textDocument : { uri : FIXTURE_URI . RENAMING } , position : { line, character } } ,
1354
1349
{ } as any ,
1355
1350
)
1356
1351
}
@@ -1467,4 +1462,41 @@ describe('server', () => {
1467
1462
` )
1468
1463
} )
1469
1464
} )
1465
+
1466
+ describe ( 'onRenameRequest' , ( ) => {
1467
+ async function getRenameRequestResult (
1468
+ line : LSP . uinteger ,
1469
+ character : LSP . uinteger ,
1470
+ newName = 'newName' ,
1471
+ ) {
1472
+ const { connection } = await initializeServer ( )
1473
+
1474
+ return connection . onRenameRequest . mock . calls [ 0 ] [ 0 ] (
1475
+ {
1476
+ textDocument : { uri : FIXTURE_URI . RENAMING } ,
1477
+ position : { line, character } ,
1478
+ newName,
1479
+ } ,
1480
+ { } as any ,
1481
+ { } as any ,
1482
+ )
1483
+ }
1484
+
1485
+ // Sanity check; these cases should already be covered by onPrepareRename.
1486
+ it ( 'returns null when a renamable symbol is not found' , async ( ) => {
1487
+ // Comment
1488
+ expect ( await getRenameRequestResult ( 2 , 9 ) ) . toBeNull ( )
1489
+ } )
1490
+
1491
+ it ( 'throws an error when newName is invalid' , async ( ) => {
1492
+ // Variables
1493
+ await expect ( getRenameRequestResult ( 12 , 0 , '_' ) ) . rejects . toThrow ( )
1494
+ await expect ( getRenameRequestResult ( 12 , 0 , '2' ) ) . rejects . toThrow ( )
1495
+ await expect ( getRenameRequestResult ( 12 , 0 , '1abc' ) ) . rejects . toThrow ( )
1496
+ await expect ( getRenameRequestResult ( 12 , 0 , 'ab%c' ) ) . rejects . toThrow ( )
1497
+ // Functions
1498
+ await expect ( getRenameRequestResult ( 13 , 0 , '$' ) ) . rejects . toThrow ( )
1499
+ await expect ( getRenameRequestResult ( 13 , 0 , 'new$name' ) ) . rejects . toThrow ( )
1500
+ } )
1501
+ } )
1470
1502
} )
0 commit comments