Skip to content

Commit

Permalink
fix: adding tests for covering the special characters case for auto t…
Browse files Browse the repository at this point in the history
…rigger (#680)

Co-authored-by: Supraja Venkatesh <[email protected]>
  • Loading branch information
suprajaven and Supraja Venkatesh authored Dec 30, 2024
1 parent fad6582 commit 873fdae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
SOME_FILE_WITH_EXTENSION,
SOME_SINGLE_LINE_FILE,
SOME_UNSUPPORTED_FILE,
SPECIAL_CHARACTER_HELLO_WORLD,
} from './testUtils'
import { CodeDiffTracker } from './telemetry/codeDiffTracker'
import { TelemetryService } from './telemetryService'
Expand Down Expand Up @@ -922,6 +923,34 @@ describe('CodeWhisperer Server', () => {
features.dispose()
})

it('should return recommendations even on a below-threshold auto-trigger position when special characters are present', async () => {
const SOME_FILE = TextDocument.create('file:///test.cs', 'csharp', 1, SPECIAL_CHARACTER_HELLO_WORLD)
features.openDocument(SOME_FILE)

const result = await features.doInlineCompletionWithReferences(
{
textDocument: { uri: SOME_FILE.uri },
position: { line: 0, character: 1 },
context: { triggerKind: InlineCompletionTriggerKind.Automatic },
},
CancellationToken.None
)

assert.deepEqual(result, EXPECTED_RESULT)

const expectedGenerateSuggestionsRequest = {
fileContext: {
filename: SOME_FILE.uri,
programmingLanguage: { languageName: 'csharp' },
leftFileContent: SPECIAL_CHARACTER_HELLO_WORLD.substring(0, 1),
rightFileContent: SPECIAL_CHARACTER_HELLO_WORLD.substring(1, SPECIAL_CHARACTER_HELLO_WORLD.length),
},
maxResults: 1,
supplementalContexts: [],
}
sinon.assert.calledOnceWithExactly(service.generateSuggestions, expectedGenerateSuggestionsRequest)
})

it('should return recommendations on an above-threshold auto-trigger position', async () => {
// Similar to test from above, this test case also depends on file contents not starting with a new line
const HELLO_WORLD_IN_CSHARP_WITHOUT_NEWLINE = HELLO_WORLD_IN_CSHARP.trimStart()
Expand Down
2 changes: 2 additions & 0 deletions server/aws-lsp-codewhisperer/src/language-server/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export const HELLO_WORLD_IN_CSHARP = `class HelloWorld
}
}`

export const SPECIAL_CHARACTER_HELLO_WORLD = `{class HelloWorld`

export const HELLO_WORLD_WITH_WINDOWS_ENDING = HELLO_WORLD_IN_CSHARP.replaceAll('\n', '\r\n')

export const SOME_FILE = TextDocument.create('file:///test.cs', 'csharp', 1, HELLO_WORLD_IN_CSHARP)
Expand Down

0 comments on commit 873fdae

Please sign in to comment.