Skip to content

Commit 5f845ee

Browse files
committed
more tests for #434
1 parent fca5dfa commit 5f845ee

2 files changed

Lines changed: 30 additions & 21 deletions

File tree

src/client/providers/hoverProvider.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ function extractHoverInfo(definition: proxy.IAutoCompleteItem): vscode.Hover {
7676
const rawDocString = typeof definition.raw_docstring === 'string' ? definition.raw_docstring.trim() : '';
7777
const firstLineOfRawDocString = rawDocString.length > 0 ? rawDocString.split(EOL)[0] : '';
7878
const lines = txt.split(EOL);
79-
const startIndexOfDocString = lines.findIndex(line => line.indexOf(firstLineOfRawDocString) === 0);
79+
const startIndexOfDocString = firstLineOfRawDocString === '' ? -1 : lines.findIndex(line => line.indexOf(firstLineOfRawDocString) === 0);
8080

8181
let signatureLines = startIndexOfDocString === -1 ? [lines.shift()] : lines.splice(0, startIndexOfDocString);
82-
let signature = signatureLines.filter(line=>line.trim().length > 0).join(EOL);
82+
let signature = signatureLines.filter(line => line.trim().length > 0).join(EOL);
8383

8484
switch (definition.type) {
8585
case vscode.CompletionItemKind.Constructor:
@@ -95,7 +95,7 @@ function extractHoverInfo(definition: proxy.IAutoCompleteItem): vscode.Hover {
9595
}
9696
const hoverInfo: vscode.MarkedString[] = [{ language: 'python', value: signature }];
9797
if (lines.some(line => line.trim().length > 0)) {
98-
hoverInfo.push(lines.join(EOL));
98+
hoverInfo.push(lines.join(EOL).trim().replace(/^\s+|\s+$/g, '').trim());
9999
}
100100
return new vscode.Hover(hoverInfo);
101101
}

src/test/extension.autocomplete.test.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,28 @@ suite('Hover Definition', () => {
379379
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '12,5', 'Start position is incorrect');
380380
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '12,12', 'End position is incorrect');
381381
assert.equal(def[0].contents[0].value, 'def randint(self, a, b)', 'Invalid content items');
382-
const documentation = `Return random integer in range [a, b], including both end points.${EOL} `;
382+
const documentation = `Return random integer in range [a, b], including both end points.`;
383+
assert.equal(def[0].contents[1], documentation, 'Invalid conents');
384+
}).then(done, done);
385+
});
386+
387+
test('Highlight Function', done => {
388+
let textEditor: vscode.TextEditor;
389+
let textDocument: vscode.TextDocument;
390+
return vscode.workspace.openTextDocument(fileHover).then(document => {
391+
textDocument = document;
392+
return vscode.window.showTextDocument(textDocument);
393+
}).then(editor => {
394+
assert(vscode.window.activeTextEditor, 'No active editor');
395+
textEditor = editor;
396+
const position = new vscode.Position(8, 14);
397+
return vscode.commands.executeCommand('vscode.executeHoverProvider', textDocument.uri, position);
398+
}).then((def: [{ range: vscode.Range, contents: { language: string, value: string }[] }]) => {
399+
assert.equal(def.length, 1, 'Definition lenght is incorrect');
400+
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '8,11', 'Start position is incorrect');
401+
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '8,15', 'End position is incorrect');
402+
assert.equal(def[0].contents[0].value, 'def acos(x)', 'Invalid content items');
403+
const documentation = `Return the arc cosine (measured in radians) of x.`;
383404
assert.equal(def[0].contents[1], documentation, 'Invalid conents');
384405
}).then(done, done);
385406
});
@@ -393,27 +414,15 @@ suite('Hover Definition', () => {
393414
}).then(editor => {
394415
assert(vscode.window.activeTextEditor, 'No active editor');
395416
textEditor = editor;
396-
const position = new vscode.Position(15, 10);
417+
const position = new vscode.Position(14, 14);
397418
return vscode.commands.executeCommand('vscode.executeHoverProvider', textDocument.uri, position);
398419
}).then((def: [{ range: vscode.Range, contents: { language: string, value: string }[] }]) => {
399420
assert.equal(def.length, 1, 'Definition lenght is incorrect');
400-
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '15,2', 'Start position is incorrect');
401-
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '15,10', 'End position is incorrect');
402-
const signature = `def __init__(self, group=None, target=None, name=None,${EOL}args=(), kwargs=None, verbose=None)`;
421+
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '14,9', 'Start position is incorrect');
422+
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '14,15', 'End position is incorrect');
423+
const signature = `"class Thread(self, group=None, target=None, name=None,${EOL}args=(), kwargs=None, verbose=None)"`;
403424
assert.equal(def[0].contents[0].value, signature, 'Invalid content items');
404-
const documentation = `This constructor should always be called with keyword arguments. Arguments are:${EOL}${EOL}` +
405-
`*group* should be None; reserved for future extension when a ThreadGroup${EOL}` +
406-
`class is implemented.${EOL}${EOL}` +
407-
`*target* is the callable object to be invoked by the run()${EOL}` +
408-
`method. Defaults to None, meaning nothing is called.${EOL}${EOL}` +
409-
`*name* is the thread name. By default, a unique name is constructed of${EOL}` +
410-
`the form "Thread-N" where N is a small decimal number.${EOL}${EOL}` +
411-
`*args* is the argument tuple for the target invocation. Defaults to ().${EOL}${EOL}` +
412-
`*kwargs* is a dictionary of keyword arguments for the target${EOL}` +
413-
`invocation. Defaults to {}.${EOL}${EOL}` +
414-
`If a subclass overrides the constructor, it must make sure to invoke${EOL}` +
415-
`the base class constructor (Thread.__init__()) before doing anything${EOL}` +
416-
`else to the thread.`;
425+
const documentation = `A class that represents a thread of control.${EOL}${EOL}This class can be safely subclassed in a limited fashion.`;
417426
assert.equal(def[0].contents[1], documentation, 'Invalid conents');
418427
}).then(done, done);
419428
});

0 commit comments

Comments
 (0)