summaryrefslogtreecommitdiff
path: root/client/src/test/diagnostics.test.ts
diff options
context:
space:
mode:
authorbscan <10503608+bscan@users.noreply.github.com>2022-01-17 22:27:13 -0500
committerbscan <10503608+bscan@users.noreply.github.com>2022-01-17 22:27:13 -0500
commitfa03b409a799cd540bc07e2d466cb6cbf790baab (patch)
treeb85dfdd2f76faf33175dc1b9d67194883ed19122 /client/src/test/diagnostics.test.ts
parent7e7a4e52d485afba9931ea7013cf05bea272b8c7 (diff)
downloadPerlNavigator-fa03b409a799cd540bc07e2d466cb6cbf790baab.zip
Initial commit
Diffstat (limited to 'client/src/test/diagnostics.test.ts')
-rw-r--r--client/src/test/diagnostics.test.ts41
1 files changed, 41 insertions, 0 deletions
diff --git a/client/src/test/diagnostics.test.ts b/client/src/test/diagnostics.test.ts
new file mode 100644
index 0000000..1aa8a36
--- /dev/null
+++ b/client/src/test/diagnostics.test.ts
@@ -0,0 +1,41 @@
+/* --------------------------------------------------------------------------------------------
+ * 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('diagnostics.txt');
+
+ test('Diagnoses uppercase texts', async () => {
+ await testDiagnostics(docUri, [
+ { message: 'ANY is all uppercase.', range: toRange(0, 0, 0, 3), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' },
+ { message: 'ANY is all uppercase.', range: toRange(0, 14, 0, 17), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' },
+ { message: 'OS is all uppercase.', range: toRange(0, 18, 0, 20), severity: vscode.DiagnosticSeverity.Warning, source: 'ex' }
+ ]);
+ });
+});
+
+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);
+ });
+} \ No newline at end of file