Skip to content

Commit

Permalink
Chore: Add additional tests to onRename
Browse files Browse the repository at this point in the history
  • Loading branch information
idillon-sfl committed Jul 12, 2024
1 parent c0db294 commit 3f712ae
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 10 deletions.
1 change: 1 addition & 0 deletions server/src/__tests__/fixtures/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const FIXTURE_URI = {
EMBEDDED: `file://${path.join(FIXTURE_FOLDER, 'embedded.bb')}`,
SEMANTIC_TOKENS: `file://${path.join(FIXTURE_FOLDER, 'semanticTokens.bb')}`,
DIRECTIVE: `file://${path.join(FIXTURE_FOLDER, 'directive.bb')}`,
RENAME: `file://${path.join(FIXTURE_FOLDER, 'rename.bb')}`,
BAZ_BBCLASS: `file://${path.join(FIXTURE_FOLDER, 'bbclass', 'baz.bbclass')}`,
BAR_INC: `file://${path.join(FIXTURE_FOLDER, 'inc', 'bar.inc')}`,
FOO_INC: `file://${path.join(FIXTURE_FOLDER, 'inc', 'foo.inc')}`,
Expand Down
11 changes: 11 additions & 0 deletions server/src/__tests__/fixtures/rename.bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FOO="FOO"
BAR="${FOO}"
python() {
FOO = 'FOO'
d.getVar("FOO")
}
FOO() {
"${@d.getVar('FOO')}"
FOO="$FOO ${FOO} FOO"
FOO
}
102 changes: 92 additions & 10 deletions server/src/__tests__/onRename.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import { bitBakeDocScanner } from '../BitBakeDocScanner'
import { onRenameRequestHandler, onPrepareRenameHandler } from '../connectionHandlers/onRename'
import { analyzer } from '../tree-sitter/analyzer'
import { generateBashParser, generateBitBakeParser } from '../tree-sitter/parser'
Expand All @@ -21,11 +22,11 @@ describe('onRenameRequestHandler', () => {
it('should not prompt rename if it is not a symbol', () => {
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.HOVER
document: FIXTURE_DOCUMENT.RENAME
})

const renameParams = {
position: { line: 1, character: 17 },
position: { line: 2, character: 1 },
newName: 'newName',
textDocument: { uri: DUMMY_URI }
}
Expand All @@ -36,13 +37,14 @@ describe('onRenameRequestHandler', () => {
})

it('should return expect edits', () => {
bitBakeDocScanner.parsePythonDatastoreFunction()
analyzer.analyze({
uri: DUMMY_URI,
document: FIXTURE_DOCUMENT.HOVER
document: FIXTURE_DOCUMENT.RENAME
})

const renameParams = {
position: { line: 2, character: 1 },
position: { line: 0, character: 1 },
newName: 'newName',
textDocument: { uri: DUMMY_URI }
}
Expand All @@ -52,24 +54,104 @@ describe('onRenameRequestHandler', () => {
expect(result).toEqual(
expect.objectContaining({
changes: {
[DUMMY_URI]: expect.arrayContaining([
[DUMMY_URI]: [
{
range: {
start: {
line: 0,
character: 0
},
end: {
line: 0,
character: 3
}
},
newText: 'newName'
},
{
range: {
start: {
line: 1,
character: 7
},
end: {
line: 1,
character: 10
}
},
newText: 'newName'
},
{
range: {
start: {
line: 8,
character: 4
},
end: {
line: 8,
character: 7
}
},
newText: 'newName'
},
{
range: {
start: {
line: 8,
character: 10
},
end: {
line: 8,
character: 13
}
},
newText: 'newName'
},
{
range: {
start: { line: 2, character: 0 },
end: { line: 2, character: 5 }
start: {
line: 8,
character: 16
},
end: {
line: 8,
character: 19
}
},
newText: 'newName'
},
{
range: {
start: { line: 3, character: 0 },
end: { line: 3, character: 5 }
start: {
line: 4,
character: 14
},
end: {
line: 4,
character: 17
}
},
newText: 'newName'
},
{
range: {
start: {
line: 7,
character: 18
},
end: {
line: 7,
character: 21
}
},
newText: 'newName'
}
])
]
}
})
)

// Make sure there is not additional changes
expect(result?.changes?.[DUMMY_URI]?.length).toBe(7)
})
})

0 comments on commit 3f712ae

Please sign in to comment.