@@ -8,6 +8,7 @@ import * as path from 'path';
8
8
import { SemVer } from 'semver' ;
9
9
import * as TypeMoq from 'typemoq' ;
10
10
import { Position , Range , Selection , TextDocument , TextEditor , TextLine , Uri } from 'vscode' ;
11
+ import * as sinon from 'sinon' ;
11
12
import * as fs from '../../../client/common/platform/fs-paths' ;
12
13
import {
13
14
IActiveResourceService ,
@@ -49,6 +50,7 @@ suite('Terminal - Code Execution Helper', () => {
49
50
let workspaceService : TypeMoq . IMock < IWorkspaceService > ;
50
51
let configurationService : TypeMoq . IMock < IConfigurationService > ;
51
52
let pythonSettings : TypeMoq . IMock < IPythonSettings > ;
53
+ let jsonParseStub : sinon . SinonStub ;
52
54
const workingPython : PythonEnvironment = {
53
55
path : PYTHON_PATH ,
54
56
version : new SemVer ( '3.6.6-final' ) ,
@@ -134,7 +136,68 @@ suite('Terminal - Code Execution Helper', () => {
134
136
editor . setup ( ( e ) => e . document ) . returns ( ( ) => document . object ) ;
135
137
} ) ;
136
138
139
+ test ( 'normalizeLines should handle attach_bracket_paste correctly' , async ( ) => {
140
+ configurationService
141
+ . setup ( ( c ) => c . getSettings ( TypeMoq . It . isAny ( ) ) )
142
+ . returns ( {
143
+ REPL : {
144
+ EnableREPLSmartSend : false ,
145
+ REPLSmartSend : false ,
146
+ } ,
147
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
+ } as any ) ;
149
+ const actualProcessService = new ProcessService ( ) ;
150
+ processService
151
+ . setup ( ( p ) => p . execObservable ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
152
+ . returns ( ( file , args , options ) =>
153
+ actualProcessService . execObservable . apply ( actualProcessService , [ file , args , options ] ) ,
154
+ ) ;
155
+
156
+ jsonParseStub = sinon . stub ( JSON , 'parse' ) ;
157
+ const mockResult = {
158
+ normalized : 'print("Looks like you are on 3.13")' ,
159
+ attach_bracket_paste : true ,
160
+ } ;
161
+ jsonParseStub . returns ( mockResult ) ;
162
+
163
+ const result = await helper . normalizeLines ( 'print("Looks like you are on 3.13")' ) ;
164
+
165
+ expect ( result ) . to . equal ( `\u001b[200~print("Looks like you are on 3.13")\u001b[201~` ) ;
166
+ jsonParseStub . restore ( ) ;
167
+ } ) ;
168
+
169
+ test ( 'normalizeLines should not attach bracketed paste for < 3.13' , async ( ) => {
170
+ jsonParseStub = sinon . stub ( JSON , 'parse' ) ;
171
+ const mockResult = {
172
+ normalized : 'print("Looks like you are not on 3.13")' ,
173
+ attach_bracket_paste : false ,
174
+ } ;
175
+ jsonParseStub . returns ( mockResult ) ;
176
+
177
+ configurationService
178
+ . setup ( ( c ) => c . getSettings ( TypeMoq . It . isAny ( ) ) )
179
+ . returns ( {
180
+ REPL : {
181
+ EnableREPLSmartSend : false ,
182
+ REPLSmartSend : false ,
183
+ } ,
184
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
185
+ } as any ) ;
186
+ const actualProcessService = new ProcessService ( ) ;
187
+ processService
188
+ . setup ( ( p ) => p . execObservable ( TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) , TypeMoq . It . isAny ( ) ) )
189
+ . returns ( ( file , args , options ) =>
190
+ actualProcessService . execObservable . apply ( actualProcessService , [ file , args , options ] ) ,
191
+ ) ;
192
+
193
+ const result = await helper . normalizeLines ( 'print("Looks like you are not on 3.13")' ) ;
194
+
195
+ expect ( result ) . to . equal ( 'print("Looks like you are not on 3.13")' ) ;
196
+ jsonParseStub . restore ( ) ;
197
+ } ) ;
198
+
137
199
test ( 'normalizeLines should call normalizeSelection.py' , async ( ) => {
200
+ jsonParseStub . restore ( ) ;
138
201
let execArgs = '' ;
139
202
140
203
processService
@@ -186,7 +249,6 @@ suite('Terminal - Code Execution Helper', () => {
186
249
path . join ( TEST_FILES_PATH , `sample${ fileNameSuffix } _normalized_selection.py` ) ,
187
250
'utf8' ,
188
251
) ;
189
-
190
252
await ensureCodeIsNormalized ( code , expectedCode ) ;
191
253
} ) ;
192
254
} ) ;
0 commit comments