Skip to content

Commit 1071d75

Browse files
committed
fix test
1 parent 963c34d commit 1071d75

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

packages/amazonq/test/unit/codewhisperer/util/commonUtil.test.ts

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
*/
55

66
import assert from 'assert'
7-
import { checkLeftContextKeywordsForJsonAndYaml, getPrefixSuffixOverlap } from 'aws-core-vscode/codewhisperer'
7+
import {
8+
JsonConfigFileNamingConvention,
9+
checkLeftContextKeywordsForJson,
10+
getPrefixSuffixOverlap,
11+
} from 'aws-core-vscode/codewhisperer'
812

913
describe('commonUtil', function () {
1014
describe('getPrefixSuffixOverlap', function () {
@@ -31,29 +35,47 @@ describe('commonUtil', function () {
3135
})
3236
})
3337

34-
describe('checkLeftContextKeywordsForJsonAndYaml', function () {
38+
describe('checkLeftContextKeywordsForJson', function () {
3539
it('Should return true for valid left context keywords', async function () {
3640
assert.strictEqual(
37-
checkLeftContextKeywordsForJsonAndYaml('Create an S3 Bucket named CodeWhisperer', 'json'),
38-
true
39-
)
40-
assert.strictEqual(
41-
checkLeftContextKeywordsForJsonAndYaml('Create an S3 Bucket named CodeWhisperer', 'yaml'),
41+
checkLeftContextKeywordsForJson('foo.json', 'Create an S3 Bucket named CodeWhisperer', 'json'),
4242
true
4343
)
4444
})
4545
it('Should return false for invalid left context keywords', async function () {
4646
assert.strictEqual(
47-
checkLeftContextKeywordsForJsonAndYaml('Create an S3 Bucket named CodeWhisperer in cfn', 'yaml'),
48-
false
49-
)
50-
assert.strictEqual(
51-
checkLeftContextKeywordsForJsonAndYaml(
47+
checkLeftContextKeywordsForJson(
48+
'foo.json',
5249
'Create an S3 Bucket named CodeWhisperer in Cloudformation',
5350
'json'
5451
),
5552
false
5653
)
5754
})
55+
56+
for (const jsonConfigFile of JsonConfigFileNamingConvention) {
57+
it(`should evalute by filename ${jsonConfigFile}`, function () {
58+
assert.strictEqual(checkLeftContextKeywordsForJson(jsonConfigFile, 'foo', 'json'), false)
59+
60+
assert.strictEqual(checkLeftContextKeywordsForJson(jsonConfigFile.toUpperCase(), 'bar', 'json'), false)
61+
62+
assert.strictEqual(checkLeftContextKeywordsForJson(jsonConfigFile.toUpperCase(), 'baz', 'json'), false)
63+
})
64+
65+
const upperCaseFilename = jsonConfigFile.toUpperCase()
66+
it(`should evalute by filename and case insensitive ${upperCaseFilename}`, function () {
67+
assert.strictEqual(checkLeftContextKeywordsForJson(upperCaseFilename, 'foo', 'json'), false)
68+
69+
assert.strictEqual(
70+
checkLeftContextKeywordsForJson(upperCaseFilename.toUpperCase(), 'bar', 'json'),
71+
false
72+
)
73+
74+
assert.strictEqual(
75+
checkLeftContextKeywordsForJson(upperCaseFilename.toUpperCase(), 'baz', 'json'),
76+
false
77+
)
78+
})
79+
}
5880
})
5981
})

packages/core/src/codewhisperer/util/commonUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function getPrefixSuffixOverlap(firstString: string, secondString: string
6565
return secondString.slice(0, i)
6666
}
6767

68-
export function isSupportedJsonFormat(fileName: string, leftFileContent: string, language: string): boolean {
68+
export function checkLeftContextKeywordsForJson(fileName: string, leftFileContent: string, language: string): boolean {
6969
if (
7070
language === 'json' &&
7171
!AWSTemplateKeyWords.some((substring) => leftFileContent.includes(substring)) &&

packages/core/src/codewhisperer/util/editorContext.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { fetchSupplementalContext } from './supplementalContext/supplementalCont
1414
import { supplementalContextTimeoutInMs } from '../models/constants'
1515
import { getSelectedCustomization } from './customizationUtil'
1616
import { selectFrom } from '../../shared/utilities/tsUtils'
17-
import { isSupportedJsonFormat } from './commonUtil'
17+
import { checkLeftContextKeywordsForJson } from './commonUtil'
1818
import { CodeWhispererSupplementalContext } from '../models/model'
1919
import { getOptOutPreference } from '../../shared/telemetry/util'
2020

@@ -39,7 +39,7 @@ export function extractContextForCodeWhisperer(editor: vscode.TextEditor): codew
3939
)
4040
)
4141
let languageName = 'plaintext'
42-
if (!isSupportedJsonFormat(document.fileName, caretLeftFileContext, editor.document.languageId)) {
42+
if (!checkLeftContextKeywordsForJson(document.fileName, caretLeftFileContext, editor.document.languageId)) {
4343
languageName =
4444
runtimeLanguageContext.normalizeLanguage(editor.document.languageId) ?? editor.document.languageId
4545
}

0 commit comments

Comments
 (0)