Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
* upstream/master:
  Fix hover test (#398)
  • Loading branch information
DonJayamanne committed Dec 12, 2017
2 parents 8f224ab + 713c6eb commit 41b7080
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/client/providers/itemInfoSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class ItemInfoSource {
lines.shift();
}

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

Expand Down
70 changes: 39 additions & 31 deletions src/test/definitions/hover.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
// Note: This example test is leveraging the Mocha test framework.
// Please refer to their documentation on https://mochajs.org/ for help.


// The module 'assert' provides assertion methods from node
import * as assert from 'assert';
import { EOL } from 'os';
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
import * as path from 'path';
import { initialize, closeActiveWindows, initializeTest } from '../initialize';
import * as vscode from 'vscode';
import { closeActiveWindows, initialize, initializeTest } from '../initialize';
import { normalizeMarkedString } from '../textUtils';

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

// tslint:disable-next-line:max-func-body-length
suite('Hover Definition', () => {
suiteSetup(() => initialize());
setup(() => initializeTest());
suiteTeardown(() => closeActiveWindows());
teardown(() => closeActiveWindows());
suiteSetup(initialize);
setup(initializeTest);
suiteTeardown(closeActiveWindows);
teardown(closeActiveWindows);

test('Method', done => {
let textEditor: vscode.TextEditor;
Expand All @@ -43,6 +43,7 @@ suite('Hover Definition', () => {
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '30,4', 'Start position is incorrect');
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '30,11', 'End position is incorrect');
assert.equal(def[0].contents.length, 1, 'Invalid content items');
// tslint:disable-next-line:prefer-template
const expectedContent = '```python' + EOL + 'def method1()' + EOL + '```' + EOL + 'This is method1';
assert.equal(normalizeMarkedString(def[0].contents[0]), expectedContent, 'function signature incorrect');
}).then(done, done);
Expand All @@ -63,6 +64,7 @@ suite('Hover Definition', () => {
assert.equal(def.length, 1, 'Definition length is incorrect');
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '1,9', 'Start position is incorrect');
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '1,12', 'End position is incorrect');
// tslint:disable-next-line:prefer-template
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL + 'def fun()' + EOL + '```' + EOL + 'This is fun', 'Invalid conents');
}).then(done, done);
});
Expand All @@ -82,6 +84,7 @@ suite('Hover Definition', () => {
assert.equal(def.length, 1, 'Definition length is incorrect');
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '25,4', 'Start position is incorrect');
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '25,7', 'End position is incorrect');
// tslint:disable-next-line:prefer-template
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL + 'def bar()' + EOL + '```' + EOL +
'说明 - keep this line, it works' + EOL + 'delete following line, it works' +
EOL + '如果存在需要等待审批或正在执行的任务,将不刷新页面', 'Invalid conents');
Expand All @@ -103,6 +106,7 @@ suite('Hover Definition', () => {
assert.equal(def.length, 1, 'Definition length is incorrect');
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '1,5', 'Start position is incorrect');
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '1,16', 'End position is incorrect');
// tslint:disable-next-line:prefer-template
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL +
'def showMessage()' + EOL +
'```' + EOL +
Expand Down Expand Up @@ -158,19 +162,20 @@ suite('Hover Definition', () => {
assert.equal(def.length, 1, 'Definition length is incorrect');
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '11,12', 'Start position is incorrect');
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '11,18', 'End position is incorrect');
let documentation = "```python" + EOL +
"class Random(x=None)" + EOL +
"```" + EOL +
"Random number generator base class used by bound module functions." + EOL +
"" + EOL +
"Used to instantiate instances of Random to get generators that don't" + EOL +
"share state." + EOL +
"" + EOL +
"Class Random can also be subclassed if you want to use a different basic" + EOL +
"generator of your own devising: in that case, override the following" + EOL + EOL +
"`methods` random(), seed(), getstate(), and setstate()." + EOL + EOL +
"Optionally, implement a getrandbits() method so that randrange()" + EOL +
"can cover arbitrarily large ranges.";
// tslint:disable-next-line:prefer-template
const documentation = '```python' + EOL +
'class Random(x=None)' + EOL +
'```' + EOL +
'Random number generator base class used by bound module functions.' + EOL +
'' + EOL +
'Used to instantiate instances of Random to get generators that don\'t' + EOL +
'share state.' + EOL +
'' + EOL +
'Class Random can also be subclassed if you want to use a different basic' + EOL +
'generator of your own devising: in that case, override the following' + EOL + EOL +
'`methods` random(), seed(), getstate(), and setstate().' + EOL + EOL +
'Optionally, implement a getrandbits() method so that randrange()' + EOL +
'can cover arbitrarily large ranges.';

assert.equal(normalizeMarkedString(def[0].contents[0]), documentation, 'Invalid conents');
}).then(done, done);
Expand All @@ -191,6 +196,7 @@ suite('Hover Definition', () => {
assert.equal(def.length, 1, 'Definition length is incorrect');
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '12,5', 'Start position is incorrect');
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '12,12', 'End position is incorrect');
// tslint:disable-next-line:prefer-template
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL +
'def randint(a, b)' + EOL +
'```' + EOL +
Expand All @@ -213,6 +219,7 @@ suite('Hover Definition', () => {
assert.equal(def.length, 1, 'Definition length is incorrect');
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '8,11', 'Start position is incorrect');
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '8,15', 'End position is incorrect');
// tslint:disable-next-line:prefer-template
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL +
'def acos(x)' + EOL +
'```' + EOL +
Expand All @@ -235,6 +242,7 @@ suite('Hover Definition', () => {
assert.equal(def.length, 1, 'Definition length is incorrect');
assert.equal(`${def[0].range.start.line},${def[0].range.start.character}`, '14,9', 'Start position is incorrect');
assert.equal(`${def[0].range.end.line},${def[0].range.end.character}`, '14,15', 'End position is incorrect');
// tslint:disable-next-line:prefer-template
assert.equal(normalizeMarkedString(def[0].contents[0]), '```python' + EOL +
'class Thread(group=None, target=None, name=None, args=(), kwargs=None, verbose=None)' + EOL +
'```' + EOL +
Expand Down Expand Up @@ -262,14 +270,14 @@ suite('Hover Definition', () => {
assert.equal(def.length, 1, 'Definition length is incorrect');
assert.equal(def[0].contents.length, 1, 'Only expected one result');
const contents = normalizeMarkedString(def[0].contents[0]);
if (contents.indexOf("```python") === -1) {
assert.fail(contents, "", "First line is incorrect", "compare");
if (contents.indexOf('```python') === -1) {
assert.fail(contents, '', 'First line is incorrect', 'compare');
}
if (contents.indexOf("Random number generator base class used by bound module functions.") === -1) {
assert.fail(contents, "", "'Random number generator' message missing", "compare");
if (contents.indexOf('Random number generator base class used by bound module functions.') === -1) {
assert.fail(contents, '', '\'Random number generator\' message missing', 'compare');
}
if (contents.indexOf("Class Random can also be subclassed if you want to use a different basic") === -1) {
assert.fail(contents, "", "'Class Random message' missing", "compare");
if (contents.indexOf('Class Random can also be subclassed if you want to use a different basic') === -1) {
assert.fail(contents, '', '\'Class Random message\' missing', 'compare');
}
}).then(done, done);
});
Expand All @@ -282,12 +290,12 @@ suite('Hover Definition', () => {
assert.equal(def.length, 1, 'Definition length is incorrect');
assert.equal(def[0].contents.length, 1, 'Only expected one result');
const contents = normalizeMarkedString(def[0].contents[0]);
if (contents.indexOf("def capitalize") === -1) {
assert.fail(contents, "", "'def capitalize' is missing", "compare");
if (contents.indexOf('def capitalize') === -1) {
assert.fail(contents, '', '\'def capitalize\' is missing', 'compare');
}
if (contents.indexOf("Return a capitalized version of S") === -1 &&
contents.indexOf("Return a copy of the string S with only its first character") === -1) {
assert.fail(contents, "", "'Return a capitalized version of S/Return a copy of the string S with only its first character' message missing", "compare");
if (contents.indexOf('Return a capitalized version of S') === -1 &&
contents.indexOf('Return a copy of the string S with only its first character') === -1) {
assert.fail(contents, '', '\'Return a capitalized version of S/Return a copy of the string S with only its first character\' message missing', 'compare');
}
});
});

0 comments on commit 41b7080

Please sign in to comment.