Skip to content

Commit ad379eb

Browse files
committed
Add more onRenameRequest tests
1 parent 638c19a commit ad379eb

File tree

2 files changed

+108
-5
lines changed

2 files changed

+108
-5
lines changed

server/src/__tests__/server.test.ts

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ describe('server', () => {
13821382
})
13831383

13841384
it('returns range when a renamable symbol is found', async () => {
1385-
// echo builtin command
1385+
// echo builtin
13861386
expect(await getPrepareRenameResult(3, 2)).toMatchInlineSnapshot(`
13871387
{
13881388
"end": {
@@ -1395,7 +1395,7 @@ describe('server', () => {
13951395
},
13961396
}
13971397
`)
1398-
// ls executable command
1398+
// ls executable
13991399
expect(await getPrepareRenameResult(12, 12)).toMatchInlineSnapshot(`
14001400
{
14011401
"end": {
@@ -1502,7 +1502,7 @@ describe('server', () => {
15021502
})
15031503

15041504
it('returns all instances within file when no declaration is found', async () => {
1505-
// $HOME variable
1505+
// $HOME
15061506
expect(await getRenameRequestResult(29, 9)).toMatchInlineSnapshot(`
15071507
{
15081508
"changes": {
@@ -1537,7 +1537,7 @@ describe('server', () => {
15371537
},
15381538
}
15391539
`)
1540-
// ls command
1540+
// ls
15411541
expect(await getRenameRequestResult(30, 0)).toMatchInlineSnapshot(`
15421542
{
15431543
"changes": {
@@ -1574,7 +1574,99 @@ describe('server', () => {
15741574
`)
15751575
})
15761576

1577-
it.todo('returns all instances within file when declaration is local to file')
1577+
it('returns all instances within file when declaration is local to file', async () => {
1578+
// $somevar
1579+
expect(await getRenameRequestResult(12, 0)).toMatchInlineSnapshot(`
1580+
{
1581+
"changes": {
1582+
"file://__REPO_ROOT_FOLDER__/testing/fixtures/renaming.sh": [
1583+
{
1584+
"newText": "newName",
1585+
"range": {
1586+
"end": {
1587+
"character": 7,
1588+
"line": 12,
1589+
},
1590+
"start": {
1591+
"character": 0,
1592+
"line": 12,
1593+
},
1594+
},
1595+
},
1596+
{
1597+
"newText": "newName",
1598+
"range": {
1599+
"end": {
1600+
"character": 15,
1601+
"line": 18,
1602+
},
1603+
"start": {
1604+
"character": 8,
1605+
"line": 18,
1606+
},
1607+
},
1608+
},
1609+
],
1610+
},
1611+
}
1612+
`)
1613+
// somecommand
1614+
expect(await getRenameRequestResult(17, 13)).toMatchInlineSnapshot(`
1615+
{
1616+
"changes": {
1617+
"file://__REPO_ROOT_FOLDER__/testing/fixtures/renaming.sh": [
1618+
{
1619+
"newText": "newName",
1620+
"range": {
1621+
"end": {
1622+
"character": 11,
1623+
"line": 13,
1624+
},
1625+
"start": {
1626+
"character": 0,
1627+
"line": 13,
1628+
},
1629+
},
1630+
},
1631+
{
1632+
"newText": "newName",
1633+
"range": {
1634+
"end": {
1635+
"character": 19,
1636+
"line": 17,
1637+
},
1638+
"start": {
1639+
"character": 8,
1640+
"line": 17,
1641+
},
1642+
},
1643+
},
1644+
],
1645+
},
1646+
}
1647+
`)
1648+
})
1649+
1650+
it('differentiates between variables and functions with same name', async () => {
1651+
const getChangeRanges = async (line: LSP.uinteger, character: LSP.uinteger) =>
1652+
Object.values(
1653+
((await getRenameRequestResult(line, character)) as LSP.WorkspaceEdit)
1654+
.changes as {
1655+
[uri: LSP.DocumentUri]: LSP.TextEdit[]
1656+
},
1657+
)[0].map((c) => c.range)
1658+
1659+
// $variable_or_function
1660+
const varRanges = await getChangeRanges(32, 9)
1661+
// variable_or_function
1662+
const funcRanges = await getChangeRanges(33, 21)
1663+
1664+
expect(varRanges).toHaveLength(4)
1665+
expect(funcRanges).toHaveLength(2)
1666+
expect(varRanges).not.toContainEqual(funcRanges[0])
1667+
expect(varRanges).not.toContainEqual(funcRanges[1])
1668+
})
1669+
15781670
it.todo('returns all instances within scope when declaration is local to scope')
15791671
it.todo('returns all instances across linked files')
15801672
})

testing/fixtures/renaming.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@ done
2929

3030
echo "$HOME"
3131
ls "$HOME"
32+
33+
variable_or_function="some value"
34+
function variable_or_function {
35+
echo "$variable_or_function"
36+
37+
if [[ "$variable_or_function" == "true" ]]; then
38+
variable_or_function
39+
fi
40+
41+
variable_or_function="true"
42+
}

0 commit comments

Comments
 (0)