1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
import * as vscode from 'vscode';
import * as assert from 'assert';
import { getDocUri, activate } from './helper';
suite('Should get diagnostics', () => {
const docUri = getDocUri('MyLib/MyClass.pm');
test('Checks perl compilation warnings', async () => {
await testDiagnostics(docUri, [
{ message: 'Syntax: "my" variable $genWarning masks earlier declaration in same scope at /home/brian/github/PerlNavigator/testWorkspace/MyLib/MyClass.pm line 27.',
range: toRange(26, 0, 26, 500), severity: vscode.DiagnosticSeverity.Warning, source: 'perlnavigator' },
]);
});
});
function toRange(sLine: number, sChar: number, eLine: number, eChar: number) {
const start = new vscode.Position(sLine, sChar);
const end = new vscode.Position(eLine, eChar);
return new vscode.Range(start, end);
}
async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]) {
await activate(docUri);
const actualDiagnostics = vscode.languages.getDiagnostics(docUri);
assert.equal(actualDiagnostics.length, expectedDiagnostics.length);
expectedDiagnostics.forEach((expectedDiagnostic, i) => {
const actualDiagnostic = actualDiagnostics[i];
assert.equal(actualDiagnostic.message, expectedDiagnostic.message);
assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range);
assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity);
});
}
|