Skip to content

Commit 638c19a

Browse files
committed
Add more onRenameRequest tests and cases
1 parent 676b571 commit 638c19a

File tree

4 files changed

+101
-9
lines changed

4 files changed

+101
-9
lines changed

server/src/__tests__/analyzer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Logger } from '../util/logger'
1616
const CURRENT_URI = 'dummy-uri.sh'
1717

1818
// if you add a .sh file to testing/fixtures, update this value
19-
const FIXTURE_FILES_MATCHING_GLOB = 16
19+
const FIXTURE_FILES_MATCHING_GLOB = 17
2020

2121
const defaultConfig = getDefaultConfiguration()
2222

server/src/__tests__/server.test.ts

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,14 +1471,16 @@ describe('server', () => {
14711471
) {
14721472
const { connection } = await initializeServer()
14731473

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,
1474+
return updateSnapshotUris(
1475+
await connection.onRenameRequest.mock.calls[0][0](
1476+
{
1477+
textDocument: { uri: FIXTURE_URI.RENAMING },
1478+
position: { line, character },
1479+
newName,
1480+
},
1481+
{} as any,
1482+
{} as any,
1483+
),
14821484
)
14831485
}
14841486

@@ -1498,5 +1500,82 @@ describe('server', () => {
14981500
await expect(getRenameRequestResult(13, 0, '$')).rejects.toThrow()
14991501
await expect(getRenameRequestResult(13, 0, 'new$name')).rejects.toThrow()
15001502
})
1503+
1504+
it('returns all instances within file when no declaration is found', async () => {
1505+
// $HOME variable
1506+
expect(await getRenameRequestResult(29, 9)).toMatchInlineSnapshot(`
1507+
{
1508+
"changes": {
1509+
"file://__REPO_ROOT_FOLDER__/testing/fixtures/renaming.sh": [
1510+
{
1511+
"newText": "newName",
1512+
"range": {
1513+
"end": {
1514+
"character": 11,
1515+
"line": 29,
1516+
},
1517+
"start": {
1518+
"character": 7,
1519+
"line": 29,
1520+
},
1521+
},
1522+
},
1523+
{
1524+
"newText": "newName",
1525+
"range": {
1526+
"end": {
1527+
"character": 9,
1528+
"line": 30,
1529+
},
1530+
"start": {
1531+
"character": 5,
1532+
"line": 30,
1533+
},
1534+
},
1535+
},
1536+
],
1537+
},
1538+
}
1539+
`)
1540+
// ls command
1541+
expect(await getRenameRequestResult(30, 0)).toMatchInlineSnapshot(`
1542+
{
1543+
"changes": {
1544+
"file://__REPO_ROOT_FOLDER__/testing/fixtures/renaming.sh": [
1545+
{
1546+
"newText": "newName",
1547+
"range": {
1548+
"end": {
1549+
"character": 13,
1550+
"line": 12,
1551+
},
1552+
"start": {
1553+
"character": 11,
1554+
"line": 12,
1555+
},
1556+
},
1557+
},
1558+
{
1559+
"newText": "newName",
1560+
"range": {
1561+
"end": {
1562+
"character": 2,
1563+
"line": 30,
1564+
},
1565+
"start": {
1566+
"character": 0,
1567+
"line": 30,
1568+
},
1569+
},
1570+
},
1571+
],
1572+
},
1573+
}
1574+
`)
1575+
})
1576+
1577+
it.todo('returns all instances within file when declaration is local to file')
1578+
it.todo('returns all instances within scope when declaration is local to scope')
1579+
it.todo('returns all instances across linked files')
15011580
})
15021581
})

testing/fixtures.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ export function updateSnapshotUris<
5353
}
5454

5555
if (typeof data === 'object') {
56+
if (data.changes) {
57+
for (const key in data.changes) {
58+
data.changes[key.replace(REPO_ROOT_FOLDER, '__REPO_ROOT_FOLDER__')] =
59+
data.changes[key]
60+
delete data.changes[key]
61+
}
62+
63+
return data
64+
}
65+
5666
if (data.uri) {
5767
data.uri = data.uri.replace(REPO_ROOT_FOLDER, '__REPO_ROOT_FOLDER__')
5868
}

testing/fixtures/renaming.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ done
2626
for ((i = 0; i < 10; i++)); do
2727
echo "$((i * 2))"
2828
done
29+
30+
echo "$HOME"
31+
ls "$HOME"

0 commit comments

Comments
 (0)