Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41b7080

Browse files
committed
Merge remote-tracking branch 'upstream/master'
* upstream/master: Fix hover test (microsoft#398)
2 parents 8f224ab + 713c6eb commit 41b7080

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

src/client/providers/itemInfoSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class ItemInfoSource {
116116
lines.shift();
117117
}
118118

119-
const descriptionWithHighlightedCode = this.highlightCode(dnd[1]);
119+
const descriptionWithHighlightedCode = this.highlightCode(lines.join(EOL));
120120
const tooltip = new vscode.MarkdownString(['```python', signature, '```', descriptionWithHighlightedCode].join(EOL));
121121
infos.push(new LanguageItemInfo(tooltip, dnd[0], new vscode.MarkdownString(dnd[1])));
122122

src/test/definitions/hover.test.ts

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
// Note: This example test is leveraging the Mocha test framework.
22
// Please refer to their documentation on https://mochajs.org/ for help.
33

4-
54
// The module 'assert' provides assertion methods from node
65
import * as assert from 'assert';
76
import { EOL } from 'os';
87
// You can import and use all API from the 'vscode' module
98
// as well as import your extension to test it
10-
import * as vscode from 'vscode';
119
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';
1312
import { normalizeMarkedString } from '../textUtils';
1413

1514
const autoCompPath = path.join(__dirname, '..', '..', '..', 'src', 'test', 'pythonFiles', 'autocomp');
@@ -21,11 +20,12 @@ const fileEncodingUsed = path.join(autoCompPath, 'five.py');
2120
const fileHover = path.join(autoCompPath, 'hoverTest.py');
2221
const fileStringFormat = path.join(hoverPath, 'stringFormat.py');
2322

23+
// tslint:disable-next-line:max-func-body-length
2424
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);
2929

3030
test('Method', done => {
3131
let textEditor: vscode.TextEditor;
@@ -43,6 +43,7 @@ suite('Hover Definition', () => {
4343
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '30,4', 'Start position is incorrect');
4444
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '30,11', 'End position is incorrect');
4545
assert.equal(def[0].contents.length, 1, 'Invalid content items');
46+
// tslint:disable-next-line:prefer-template
4647
const expectedContent = '```python' + EOL + 'def method1()' + EOL + '```' + EOL + 'This is method1';
4748
assert.equal(normalizeMarkedString(def[0].contents[0]), expectedContent, 'function signature incorrect');
4849
}).then(done, done);
@@ -63,6 +64,7 @@ suite('Hover Definition', () => {
6364
assert.equal(def.length, 1, 'Definition length is incorrect');
6465
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '1,9', 'Start position is incorrect');
6566
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
6668
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL + 'def fun()' + EOL + '```' + EOL + 'This is fun', 'Invalid conents');
6769
}).then(done, done);
6870
});
@@ -82,6 +84,7 @@ suite('Hover Definition', () => {
8284
assert.equal(def.length, 1, 'Definition length is incorrect');
8385
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '25,4', 'Start position is incorrect');
8486
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
8588
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL + 'def bar()' + EOL + '```' + EOL +
8689
'说明 - keep this line, it works' + EOL + 'delete following line, it works' +
8790
EOL + '如果存在需要等待审批或正在执行的任务,将不刷新页面', 'Invalid conents');
@@ -103,6 +106,7 @@ suite('Hover Definition', () => {
103106
assert.equal(def.length, 1, 'Definition length is incorrect');
104107
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '1,5', 'Start position is incorrect');
105108
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
106110
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL +
107111
'def showMessage()' + EOL +
108112
'```' + EOL +
@@ -158,19 +162,20 @@ suite('Hover Definition', () => {
158162
assert.equal(def.length, 1, 'Definition length is incorrect');
159163
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '11,12', 'Start position is incorrect');
160164
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.';
174179

175180
assert.equal(normalizeMarkedString(def[0].contents[0]), documentation, 'Invalid conents');
176181
}).then(done, done);
@@ -191,6 +196,7 @@ suite('Hover Definition', () => {
191196
assert.equal(def.length, 1, 'Definition length is incorrect');
192197
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '12,5', 'Start position is incorrect');
193198
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
194200
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL +
195201
'def randint(a, b)' + EOL +
196202
'```' + EOL +
@@ -213,6 +219,7 @@ suite('Hover Definition', () => {
213219
assert.equal(def.length, 1, 'Definition length is incorrect');
214220
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '8,11', 'Start position is incorrect');
215221
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
216223
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL +
217224
'def acos(x)' + EOL +
218225
'```' + EOL +
@@ -235,6 +242,7 @@ suite('Hover Definition', () => {
235242
assert.equal(def.length, 1, 'Definition length is incorrect');
236243
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '14,9', 'Start position is incorrect');
237244
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
238246
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL +
239247
'class Thread(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)' + EOL +
240248
'```' + EOL +
@@ -262,14 +270,14 @@ suite('Hover Definition', () => {
262270
assert.equal(def.length, 1, 'Definition length is incorrect');
263271
assert.equal(def[0].contents.length, 1, 'Only expected one result');
264272
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');
267275
}
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');
270278
}
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');
273281
}
274282
}).then(done, done);
275283
});
@@ -282,12 +290,12 @@ suite('Hover Definition', () => {
282290
assert.equal(def.length, 1, 'Definition length is incorrect');
283291
assert.equal(def[0].contents.length, 1, 'Only expected one result');
284292
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');
287295
}
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');
291299
}
292300
});
293301
});

0 commit comments

Comments
 (0)