44 */
55
66import 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
913describe ( '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} )
0 commit comments