@@ -7,12 +7,15 @@ import assert from 'assert'
77import * as FakeTimers from '@sinonjs/fake-timers'
88import * as vscode from 'vscode'
99import * as sinon from 'sinon'
10+ import * as os from 'os'
1011import * as crossFile from 'aws-core-vscode/codewhisperer'
1112import { TestFolder , assertTabCount , installFakeClock } from 'aws-core-vscode/test'
1213import { CodeWhispererSupplementalContext , FeatureConfigProvider } from 'aws-core-vscode/codewhisperer'
1314import { toTextEditor } from 'aws-core-vscode/test'
1415import { LspController } from 'aws-core-vscode/amazonq'
1516
17+ const newLine = os . EOL
18+
1619describe ( 'supplementalContextUtil' , function ( ) {
1720 let testFolder : TestFolder
1821 let clock : FakeTimers . InstalledClock
@@ -116,51 +119,51 @@ describe('supplementalContextUtil', function () {
116119 it ( 'truncateLineByLine should drop the last line if max length is greater than threshold' , function ( ) {
117120 const input =
118121 repeatString ( 'a' , 11 ) +
119- '\n' +
122+ newLine +
120123 repeatString ( 'b' , 11 ) +
121- '\n' +
124+ newLine +
122125 repeatString ( 'c' , 11 ) +
123- '\n' +
126+ newLine +
124127 repeatString ( 'd' , 11 ) +
125- '\n' +
128+ newLine +
126129 repeatString ( 'e' , 11 )
127130
128131 assert . ok ( input . length > 50 )
129132 const actual = crossFile . truncateLineByLine ( input , 50 )
130133 assert . strictEqual (
131134 actual ,
132135 repeatString ( 'a' , 11 ) +
133- '\n' +
136+ newLine +
134137 repeatString ( 'b' , 11 ) +
135- '\n' +
138+ newLine +
136139 repeatString ( 'c' , 11 ) +
137- '\n' +
140+ newLine +
138141 repeatString ( 'd' , 11 )
139142 )
140143
141- const input2 = repeatString ( 'b\n' , 10 )
144+ const input2 = repeatString ( `b ${ newLine } ` , 10 )
142145 const actual2 = crossFile . truncateLineByLine ( input2 , 8 )
143146 assert . strictEqual ( actual2 . length , 8 )
144147 } )
145148
146149 it ( 'truncation context should make context length per item lte 10240 cap' , function ( ) {
147150 const chunkA : crossFile . CodeWhispererSupplementalContextItem = {
148- content : repeatString ( 'a\n' , 4000 ) ,
151+ content : repeatString ( `a ${ newLine } ` , 4000 ) ,
149152 filePath : 'a.java' ,
150153 score : 0 ,
151154 }
152155 const chunkB : crossFile . CodeWhispererSupplementalContextItem = {
153- content : repeatString ( 'b\n' , 6000 ) ,
156+ content : repeatString ( `b ${ newLine } ` , 6000 ) ,
154157 filePath : 'b.java' ,
155158 score : 1 ,
156159 }
157160 const chunkC : crossFile . CodeWhispererSupplementalContextItem = {
158- content : repeatString ( 'c\n' , 1000 ) ,
161+ content : repeatString ( `c ${ newLine } ` , 1000 ) ,
159162 filePath : 'c.java' ,
160163 score : 2 ,
161164 }
162165 const chunkD : crossFile . CodeWhispererSupplementalContextItem = {
163- content : repeatString ( 'd\n' , 1500 ) ,
166+ content : repeatString ( `d ${ newLine } ` , 1500 ) ,
164167 filePath : 'd.java' ,
165168 score : 3 ,
166169 }
@@ -260,7 +263,7 @@ describe('supplementalContextUtil', function () {
260263 } )
261264
262265 it ( 'should flip the value if negative max length is provided' , function ( ) {
263- const input = ' aaaaa\nbbbbb'
266+ const input = ` aaaaa${ newLine } bbbbb`
264267 const actual = crossFile . truncateLineByLine ( input , - 6 )
265268 const expected = crossFile . truncateLineByLine ( input , 6 )
266269 assert . strictEqual ( actual , expected )
0 commit comments