1
1
// Note: This example test is leveraging the Mocha test framework.
2
2
// Please refer to their documentation on https://mochajs.org/ for help.
3
3
4
-
5
4
// The module 'assert' provides assertion methods from node
6
5
import * as assert from 'assert' ;
7
6
import { EOL } from 'os' ;
8
7
// You can import and use all API from the 'vscode' module
9
8
// as well as import your extension to test it
10
- import * as vscode from 'vscode' ;
11
9
import * as path from 'path' ;
12
- import { initialize , closeActiveWindows , initializeTest } from '../initialize' ;
10
+ import * as vscode from 'vscode' ;
11
+ import { closeActiveWindows , initialize , initializeTest } from '../initialize' ;
13
12
import { normalizeMarkedString } from '../textUtils' ;
14
13
15
14
const autoCompPath = path . join ( __dirname , '..' , '..' , '..' , 'src' , 'test' , 'pythonFiles' , 'autocomp' ) ;
@@ -21,11 +20,12 @@ const fileEncodingUsed = path.join(autoCompPath, 'five.py');
21
20
const fileHover = path . join ( autoCompPath , 'hoverTest.py' ) ;
22
21
const fileStringFormat = path . join ( hoverPath , 'stringFormat.py' ) ;
23
22
23
+ // tslint:disable-next-line:max-func-body-length
24
24
suite ( 'Hover Definition' , ( ) => {
25
- suiteSetup ( ( ) => initialize ( ) ) ;
26
- setup ( ( ) => initializeTest ( ) ) ;
27
- suiteTeardown ( ( ) => closeActiveWindows ( ) ) ;
28
- teardown ( ( ) => closeActiveWindows ( ) ) ;
25
+ suiteSetup ( initialize ) ;
26
+ setup ( initializeTest ) ;
27
+ suiteTeardown ( closeActiveWindows ) ;
28
+ teardown ( closeActiveWindows ) ;
29
29
30
30
test ( 'Method' , done => {
31
31
let textEditor : vscode . TextEditor ;
@@ -43,6 +43,7 @@ suite('Hover Definition', () => {
43
43
assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '30,4' , 'Start position is incorrect' ) ;
44
44
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '30,11' , 'End position is incorrect' ) ;
45
45
assert . equal ( def [ 0 ] . contents . length , 1 , 'Invalid content items' ) ;
46
+ // tslint:disable-next-line:prefer-template
46
47
const expectedContent = '```python' + EOL + 'def method1()' + EOL + '```' + EOL + 'This is method1' ;
47
48
assert . equal ( normalizeMarkedString ( def [ 0 ] . contents [ 0 ] ) , expectedContent , 'function signature incorrect' ) ;
48
49
} ) . then ( done , done ) ;
@@ -63,6 +64,7 @@ suite('Hover Definition', () => {
63
64
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
64
65
assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '1,9' , 'Start position is incorrect' ) ;
65
66
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '1,12' , 'End position is incorrect' ) ;
67
+ // tslint:disable-next-line:prefer-template
66
68
assert . equal ( normalizeMarkedString ( def [ 0 ] . contents [ 0 ] ) , '```python' + EOL + 'def fun()' + EOL + '```' + EOL + 'This is fun' , 'Invalid conents' ) ;
67
69
} ) . then ( done , done ) ;
68
70
} ) ;
@@ -82,6 +84,7 @@ suite('Hover Definition', () => {
82
84
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
83
85
assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '25,4' , 'Start position is incorrect' ) ;
84
86
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '25,7' , 'End position is incorrect' ) ;
87
+ // tslint:disable-next-line:prefer-template
85
88
assert . equal ( normalizeMarkedString ( def [ 0 ] . contents [ 0 ] ) , '```python' + EOL + 'def bar()' + EOL + '```' + EOL +
86
89
'说明 - keep this line, it works' + EOL + 'delete following line, it works' +
87
90
EOL + '如果存在需要等待审批或正在执行的任务,将不刷新页面' , 'Invalid conents' ) ;
@@ -103,6 +106,7 @@ suite('Hover Definition', () => {
103
106
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
104
107
assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '1,5' , 'Start position is incorrect' ) ;
105
108
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '1,16' , 'End position is incorrect' ) ;
109
+ // tslint:disable-next-line:prefer-template
106
110
assert . equal ( normalizeMarkedString ( def [ 0 ] . contents [ 0 ] ) , '```python' + EOL +
107
111
'def showMessage()' + EOL +
108
112
'```' + EOL +
@@ -158,19 +162,20 @@ suite('Hover Definition', () => {
158
162
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
159
163
assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '11,12' , 'Start position is incorrect' ) ;
160
164
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '11,18' , 'End position is incorrect' ) ;
161
- let documentation = "```python" + EOL +
162
- "class Random(x=None)" + EOL +
163
- "```" + EOL +
164
- "Random number generator base class used by bound module functions." + EOL +
165
- "" + EOL +
166
- "Used to instantiate instances of Random to get generators that don't" + EOL +
167
- "share state." + EOL +
168
- "" + EOL +
169
- "Class Random can also be subclassed if you want to use a different basic" + EOL +
170
- "generator of your own devising: in that case, override the following" + EOL + EOL +
171
- "`methods` random(), seed(), getstate(), and setstate()." + EOL + EOL +
172
- "Optionally, implement a getrandbits() method so that randrange()" + EOL +
173
- "can cover arbitrarily large ranges." ;
165
+ // tslint:disable-next-line:prefer-template
166
+ const documentation = '```python' + EOL +
167
+ 'class Random(x=None)' + EOL +
168
+ '```' + EOL +
169
+ 'Random number generator base class used by bound module functions.' + EOL +
170
+ '' + EOL +
171
+ 'Used to instantiate instances of Random to get generators that don\'t' + EOL +
172
+ 'share state.' + EOL +
173
+ '' + EOL +
174
+ 'Class Random can also be subclassed if you want to use a different basic' + EOL +
175
+ 'generator of your own devising: in that case, override the following' + EOL + EOL +
176
+ '`methods` random(), seed(), getstate(), and setstate().' + EOL + EOL +
177
+ 'Optionally, implement a getrandbits() method so that randrange()' + EOL +
178
+ 'can cover arbitrarily large ranges.' ;
174
179
175
180
assert . equal ( normalizeMarkedString ( def [ 0 ] . contents [ 0 ] ) , documentation , 'Invalid conents' ) ;
176
181
} ) . then ( done , done ) ;
@@ -191,6 +196,7 @@ suite('Hover Definition', () => {
191
196
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
192
197
assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '12,5' , 'Start position is incorrect' ) ;
193
198
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '12,12' , 'End position is incorrect' ) ;
199
+ // tslint:disable-next-line:prefer-template
194
200
assert . equal ( normalizeMarkedString ( def [ 0 ] . contents [ 0 ] ) , '```python' + EOL +
195
201
'def randint(a, b)' + EOL +
196
202
'```' + EOL +
@@ -213,6 +219,7 @@ suite('Hover Definition', () => {
213
219
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
214
220
assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '8,11' , 'Start position is incorrect' ) ;
215
221
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '8,15' , 'End position is incorrect' ) ;
222
+ // tslint:disable-next-line:prefer-template
216
223
assert . equal ( normalizeMarkedString ( def [ 0 ] . contents [ 0 ] ) , '```python' + EOL +
217
224
'def acos(x)' + EOL +
218
225
'```' + EOL +
@@ -235,6 +242,7 @@ suite('Hover Definition', () => {
235
242
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
236
243
assert . equal ( `${ def [ 0 ] . range . start . line } ,${ def [ 0 ] . range . start . character } ` , '14,9' , 'Start position is incorrect' ) ;
237
244
assert . equal ( `${ def [ 0 ] . range . end . line } ,${ def [ 0 ] . range . end . character } ` , '14,15' , 'End position is incorrect' ) ;
245
+ // tslint:disable-next-line:prefer-template
238
246
assert . equal ( normalizeMarkedString ( def [ 0 ] . contents [ 0 ] ) , '```python' + EOL +
239
247
'class Thread(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)' + EOL +
240
248
'```' + EOL +
@@ -262,14 +270,14 @@ suite('Hover Definition', () => {
262
270
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
263
271
assert . equal ( def [ 0 ] . contents . length , 1 , 'Only expected one result' ) ;
264
272
const contents = normalizeMarkedString ( def [ 0 ] . contents [ 0 ] ) ;
265
- if ( contents . indexOf ( " ```python" ) === - 1 ) {
266
- assert . fail ( contents , "" , " First line is incorrect" , " compare" ) ;
273
+ if ( contents . indexOf ( ' ```python' ) === - 1 ) {
274
+ assert . fail ( contents , '' , ' First line is incorrect' , ' compare' ) ;
267
275
}
268
- if ( contents . indexOf ( " Random number generator base class used by bound module functions." ) === - 1 ) {
269
- assert . fail ( contents , "" , "' Random number generator' message missing" , " compare" ) ;
276
+ if ( contents . indexOf ( ' Random number generator base class used by bound module functions.' ) === - 1 ) {
277
+ assert . fail ( contents , '' , '\' Random number generator\ ' message missing' , ' compare' ) ;
270
278
}
271
- if ( contents . indexOf ( " Class Random can also be subclassed if you want to use a different basic" ) === - 1 ) {
272
- assert . fail ( contents , "" , "' Class Random message' missing" , " compare" ) ;
279
+ if ( contents . indexOf ( ' Class Random can also be subclassed if you want to use a different basic' ) === - 1 ) {
280
+ assert . fail ( contents , '' , '\' Class Random message\ ' missing' , ' compare' ) ;
273
281
}
274
282
} ) . then ( done , done ) ;
275
283
} ) ;
@@ -282,12 +290,12 @@ suite('Hover Definition', () => {
282
290
assert . equal ( def . length , 1 , 'Definition length is incorrect' ) ;
283
291
assert . equal ( def [ 0 ] . contents . length , 1 , 'Only expected one result' ) ;
284
292
const contents = normalizeMarkedString ( def [ 0 ] . contents [ 0 ] ) ;
285
- if ( contents . indexOf ( " def capitalize" ) === - 1 ) {
286
- assert . fail ( contents , "" , "' def capitalize' is missing" , " compare" ) ;
293
+ if ( contents . indexOf ( ' def capitalize' ) === - 1 ) {
294
+ assert . fail ( contents , '' , '\' def capitalize\ ' is missing' , ' compare' ) ;
287
295
}
288
- if ( contents . indexOf ( " Return a capitalized version of S" ) === - 1 &&
289
- contents . indexOf ( " Return a copy of the string S with only its first character" ) === - 1 ) {
290
- assert . fail ( contents , "" , "' Return a capitalized version of S/Return a copy of the string S with only its first character' message missing" , " compare" ) ;
296
+ if ( contents . indexOf ( ' Return a capitalized version of S' ) === - 1 &&
297
+ contents . indexOf ( ' Return a copy of the string S with only its first character' ) === - 1 ) {
298
+ assert . fail ( contents , '' , '\' Return a capitalized version of S/Return a copy of the string S with only its first character\ ' message missing' , ' compare' ) ;
291
299
}
292
300
} ) ;
293
301
} ) ;
0 commit comments