|
| 1 | +import * as vscode from "vscode"; |
| 2 | +import * as assert from "assert"; |
| 3 | +import { createDiagnosticFilter } from "../lsp/client"; |
| 4 | + |
| 5 | +suite("Diagnostic Filtering", function () { |
| 6 | + |
| 7 | + test("Diagnostic filter removes diagnostics for virtual documents", async function () { |
| 8 | + // Create mocks |
| 9 | + const virtualDocUri = vscode.Uri.file("/tmp/.vdoc.12345678-1234-1234-1234-123456789abc.py"); |
| 10 | + const regularDocUri = vscode.Uri.file("/tmp/regular-file.py"); |
| 11 | + |
| 12 | + // Create some test diagnostics |
| 13 | + const testDiagnostics = [ |
| 14 | + new vscode.Diagnostic( |
| 15 | + new vscode.Range(0, 0, 0, 10), |
| 16 | + "Test diagnostic message", |
| 17 | + vscode.DiagnosticSeverity.Error |
| 18 | + ) |
| 19 | + ]; |
| 20 | + |
| 21 | + // Create a mock diagnostics handler function to verify behavior |
| 22 | + let capturedUri: vscode.Uri | undefined; |
| 23 | + let capturedDiagnostics: vscode.Diagnostic[] | undefined; |
| 24 | + |
| 25 | + const mockHandler = (uri: vscode.Uri, diagnostics: vscode.Diagnostic[]) => { |
| 26 | + capturedUri = uri; |
| 27 | + capturedDiagnostics = diagnostics; |
| 28 | + }; |
| 29 | + |
| 30 | + // Create the filter function |
| 31 | + const diagnosticFilter = createDiagnosticFilter(); |
| 32 | + |
| 33 | + // Test with a virtual document |
| 34 | + diagnosticFilter(virtualDocUri, testDiagnostics, mockHandler); |
| 35 | + |
| 36 | + // Verify diagnostics were filtered (empty array) |
| 37 | + assert.strictEqual(capturedUri, virtualDocUri, "URI should be passed through"); |
| 38 | + assert.strictEqual(capturedDiagnostics!.length, 0, "Diagnostics should be empty for virtual documents"); |
| 39 | + |
| 40 | + // Reset captured values |
| 41 | + capturedUri = undefined; |
| 42 | + capturedDiagnostics = undefined; |
| 43 | + |
| 44 | + // Test with a regular document |
| 45 | + diagnosticFilter(regularDocUri, testDiagnostics, mockHandler); |
| 46 | + |
| 47 | + // Verify diagnostics were not filtered |
| 48 | + assert.strictEqual(capturedUri, regularDocUri, "URI should be passed through"); |
| 49 | + assert.strictEqual(capturedDiagnostics!.length, testDiagnostics.length, "Diagnostics should not be filtered for regular documents"); |
| 50 | + assert.deepStrictEqual(capturedDiagnostics!, testDiagnostics, "Original diagnostics should be passed through unchanged"); |
| 51 | + }); |
| 52 | + |
| 53 | +}); |
0 commit comments