6
6
// tslint:disable:no-any
7
7
8
8
import { expect } from 'chai' ;
9
+ import * as sinon from 'sinon' ;
9
10
import { buildApi } from '../client/api' ;
10
11
import { EXTENSION_ROOT_DIR } from '../client/common/constants' ;
11
12
13
+ // Stub sourceMapSupport.initialize before we import from extension.ts (we don't actually need it)
14
+ // tslint:disable-next-line: no-require-imports no-var-requires
15
+ const sourceMapSupport = require ( '../client/sourceMapSupport' ) ;
16
+ sinon . stub ( sourceMapSupport , 'initialize' ) ;
17
+ import { DECREASE_INDENT_REGEX , INCREASE_INDENT_REGEX } from '../client/extension' ;
18
+
12
19
const expectedPath = `${ EXTENSION_ROOT_DIR . fileToCommandArgument ( ) } /pythonFiles/ptvsd_launcher.py` ;
13
20
14
21
suite ( 'Extension API Debugger' , ( ) => {
@@ -22,4 +29,84 @@ suite('Extension API Debugger', () => {
22
29
const expectedArgs = [ expectedPath , '--default' , '--host' , 'something' , '--port' , '1234' , '--wait' ] ;
23
30
expect ( args ) . to . be . deep . equal ( expectedArgs ) ;
24
31
} ) ;
32
+ [
33
+ {
34
+ keyword : 'def' ,
35
+ line : 'def foo:' ,
36
+ dedent : false
37
+ } ,
38
+ {
39
+ keyword : 'class' ,
40
+ line : 'class TestClass:' ,
41
+ dedent : false
42
+ } ,
43
+ {
44
+ keyword : 'for' ,
45
+ line : 'for item in items:' ,
46
+ dedent : false
47
+ } ,
48
+ {
49
+ keyword : 'if' ,
50
+ line : 'if foo is None:' ,
51
+ dedent : false
52
+ } ,
53
+ {
54
+ keyword : 'elif' ,
55
+ line : 'elif x < 5:' ,
56
+ dedent : true
57
+ } ,
58
+ {
59
+ keyword : 'else' ,
60
+ line : 'else:' ,
61
+ dedent : true
62
+ } ,
63
+ {
64
+ keyword : 'while' ,
65
+ line : 'while \'::\' in macaddress:' ,
66
+ dedent : false
67
+ } ,
68
+ {
69
+ keyword : 'try' ,
70
+ line : 'try:' ,
71
+ dedent : false
72
+ } ,
73
+ {
74
+ keyword : 'with' ,
75
+ line : 'with self.test:' ,
76
+ dedent : false
77
+ } ,
78
+ {
79
+ keyword : 'finally' ,
80
+ line : 'finally:' ,
81
+ dedent : false
82
+ } ,
83
+ {
84
+ keyword : 'except' ,
85
+ line : 'except TestError:' ,
86
+ dedent : false
87
+ } ,
88
+ {
89
+ keyword : 'async' ,
90
+ line : 'async def test(self):' ,
91
+ dedent : false
92
+ }
93
+ ] . forEach ( ( { keyword, line, dedent} ) => {
94
+ test ( `Increase indent regex should pick up lines containing the ${ keyword } keyword` , async ( ) => {
95
+ const result = INCREASE_INDENT_REGEX . test ( line ) ;
96
+ expect ( result ) . to . be . equal ( true , `Increase indent regex should pick up lines containing the ${ keyword } keyword` ) ;
97
+ } ) ;
98
+
99
+ test ( `Decrease indent regex should ${ dedent ? '' : 'not ' } pick up lines containing the ${ keyword } keyword` , async ( ) => {
100
+ const result = DECREASE_INDENT_REGEX . test ( line ) ;
101
+ expect ( result ) . to . be . equal ( dedent , `Decrease indent regex should ${ dedent ? '' : 'not ' } pick up lines containing the ${ keyword } keyword` ) ;
102
+ } ) ;
103
+ } ) ;
104
+ test ( 'Increase indent regex should not pick up lines without keywords' , async ( ) => {
105
+ const result = INCREASE_INDENT_REGEX . test ( 'a = \'hello \\n \'' ) ;
106
+ expect ( result ) . to . be . equal ( false , 'Increase indent regex should not pick up lines without keywords' ) ;
107
+ } ) ;
108
+ test ( 'Decrease indent regex should not pick up lines without keywords' , async ( ) => {
109
+ const result = DECREASE_INDENT_REGEX . test ( 'a = \'hello \\n \'' ) ;
110
+ expect ( result ) . to . be . equal ( false , 'Decrease indent regex should not pick up lines without keywords' ) ;
111
+ } ) ;
25
112
} ) ;
0 commit comments