44
55
66// Place this right on top
7- import { initialize , IS_TRAVIS , PYTHON_PATH , closeActiveWindows } from './initialize' ;
7+ import { initialize , PYTHON_PATH , closeActiveWindows } from './initialize' ;
88// The module 'assert' provides assertion methods from node
99import * as assert from 'assert' ;
1010
@@ -17,7 +17,7 @@ import * as fs from 'fs-extra';
1717import { BlockFormatProviders } from '../client/typeFormatters/blockFormatProvider' ;
1818let pythonSettings = settings . PythonSettings . getInstance ( ) ;
1919let srcPythoFilesPath = path . join ( __dirname , '..' , '..' , 'src' , 'test' , 'pythonFiles' , 'typeFormatFiles' ) ;
20- let outPythoFilesPath = path . join ( __dirname , '..' , ' pythonFiles', 'typeFormatFiles' ) ;
20+ let outPythoFilesPath = path . join ( __dirname , 'pythonFiles' , 'typeFormatFiles' ) ;
2121
2222const tryBlock2OutFilePath = path . join ( outPythoFilesPath , 'tryBlocks2.py' ) ;
2323const tryBlock4OutFilePath = path . join ( outPythoFilesPath , 'tryBlocks4.py' ) ;
@@ -27,6 +27,10 @@ const elseBlock2OutFilePath = path.join(outPythoFilesPath, 'elseBlocks2.py');
2727const elseBlock4OutFilePath = path . join ( outPythoFilesPath , 'elseBlocks4.py' ) ;
2828const elseBlockTabOutFilePath = path . join ( outPythoFilesPath , 'elseBlocksTab.py' ) ;
2929
30+ const elseBlockFirstLine2OutFilePath = path . join ( outPythoFilesPath , 'elseBlocksFirstLine2.py' ) ;
31+ const elseBlockFirstLine4OutFilePath = path . join ( outPythoFilesPath , 'elseBlocksFirstLine4.py' ) ;
32+ const elseBlockFirstLineTabOutFilePath = path . join ( outPythoFilesPath , 'elseBlocksFirstLineTab.py' ) ;
33+
3034const provider = new BlockFormatProviders ( ) ;
3135
3236function testFormatting ( fileToFormat : string , position : vscode . Position , expectedEdits : vscode . TextEdit [ ] , formatOptions : vscode . FormattingOptions ) : PromiseLike < void > {
@@ -50,6 +54,75 @@ function testFormatting(fileToFormat: string, position: vscode.Position, expecte
5054 } ) ;
5155}
5256
57+
58+ suite ( 'Else block with if in first line of file' , ( ) => {
59+ suiteSetup ( done => {
60+ initialize ( ) . then ( ( ) => {
61+ pythonSettings . pythonPath = PYTHON_PATH ;
62+ fs . ensureDirSync ( path . dirname ( outPythoFilesPath ) ) ;
63+
64+ [ 'elseBlocksFirstLine2.py' , 'elseBlocksFirstLine4.py' , 'elseBlocksFirstLineTab.py' ] . forEach ( file => {
65+ const targetFile = path . join ( outPythoFilesPath , file ) ;
66+ if ( fs . existsSync ( targetFile ) ) { fs . unlinkSync ( targetFile ) ; }
67+ fs . copySync ( path . join ( srcPythoFilesPath , file ) , targetFile ) ;
68+ } ) ;
69+ } ) . then ( done ) . catch ( done ) ;
70+ } ) ;
71+ suiteTeardown ( done => {
72+ closeActiveWindows ( ) . then ( done , done ) ;
73+ } ) ;
74+ teardown ( done => {
75+ closeActiveWindows ( ) . then ( done , done ) ;
76+ } ) ;
77+
78+ interface TestCase {
79+ title : string ;
80+ line : number ;
81+ column : number ;
82+ expectedEdits : vscode . TextEdit [ ] ;
83+ formatOptions : vscode . FormattingOptions ;
84+ filePath : string ;
85+ }
86+ const TAB = ' ' ;
87+ const testCases : TestCase [ ] = [
88+ {
89+ title : 'else block with 2 spaces' ,
90+ line : 3 , column : 7 ,
91+ expectedEdits : [
92+ vscode . TextEdit . delete ( new vscode . Range ( 3 , 0 , 3 , 2 ) )
93+ ] ,
94+ formatOptions : { insertSpaces : true , tabSize : 2 } ,
95+ filePath : elseBlockFirstLine2OutFilePath
96+ } ,
97+ {
98+ title : 'else block with 4 spaces' ,
99+ line : 3 , column : 9 ,
100+ expectedEdits : [
101+ vscode . TextEdit . delete ( new vscode . Range ( 3 , 0 , 3 , 4 ) )
102+ ] ,
103+ formatOptions : { insertSpaces : true , tabSize : 4 } ,
104+ filePath : elseBlockFirstLine4OutFilePath
105+ } ,
106+ {
107+ title : 'else block with Tab' ,
108+ line : 3 , column : 6 ,
109+ expectedEdits : [
110+ vscode . TextEdit . delete ( new vscode . Range ( 3 , 0 , 3 , 1 ) ) ,
111+ vscode . TextEdit . insert ( new vscode . Position ( 3 , 0 ) , '' )
112+ ] ,
113+ formatOptions : { insertSpaces : false , tabSize : 4 } ,
114+ filePath : elseBlockFirstLineTabOutFilePath
115+ }
116+ ] ;
117+
118+ testCases . forEach ( ( testCase , index ) => {
119+ test ( `${ index + 1 } . ${ testCase . title } ` , done => {
120+ const pos = new vscode . Position ( testCase . line , testCase . column ) ;
121+ testFormatting ( testCase . filePath , pos , testCase . expectedEdits , testCase . formatOptions ) . then ( done , done ) ;
122+ } ) ;
123+ } ) ;
124+ } ) ;
125+
53126suite ( 'Try blocks with indentation of 2 spaces' , ( ) => {
54127 suiteSetup ( done => {
55128 initialize ( ) . then ( ( ) => {
@@ -650,7 +723,6 @@ suite('Else blocks with indentation of Tab', () => {
650723 closeActiveWindows ( ) . then ( done , done ) ;
651724 } ) ;
652725
653- const TAB = ' ' ;
654726 interface TestCase {
655727 title : string ;
656728 line : number ;
0 commit comments