aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/test/utils/diagnotics/vscode.test.ts
blob: 542dec1f54f833fce9ea36a861760dd81dbbb5e2 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import * as assert from 'assert';
import * as vscode from 'vscode';

import { areDiagnosticsEqual } from '../../../utils/diagnostics/vscode';

const range1 = new vscode.Range(
    new vscode.Position(1, 2),
    new vscode.Position(3, 4)
);

const range2 = new vscode.Range(
    new vscode.Position(5, 6),
    new vscode.Position(7, 8)
);

describe('areDiagnosticsEqual', () => {
    it('should treat identical diagnostics as equal', () => {
        const diagnostic1 = new vscode.Diagnostic(
            range1,
            'Hello, world!',
            vscode.DiagnosticSeverity.Error
        );

        const diagnostic2 = new vscode.Diagnostic(
            range1,
            'Hello, world!',
            vscode.DiagnosticSeverity.Error
        );

        assert(areDiagnosticsEqual(diagnostic1, diagnostic2));
    });

    it('should treat diagnostics with different sources as inequal', () => {
        const diagnostic1 = new vscode.Diagnostic(
            range1,
            'Hello, world!',
            vscode.DiagnosticSeverity.Error
        );
        diagnostic1.source = 'rustc';

        const diagnostic2 = new vscode.Diagnostic(
            range1,
            'Hello, world!',
            vscode.DiagnosticSeverity.Error
        );
        diagnostic2.source = 'clippy';

        assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
    });

    it('should treat diagnostics with different ranges as inequal', () => {
        const diagnostic1 = new vscode.Diagnostic(
            range1,
            'Hello, world!',
            vscode.DiagnosticSeverity.Error
        );

        const diagnostic2 = new vscode.Diagnostic(
            range2,
            'Hello, world!',
            vscode.DiagnosticSeverity.Error
        );

        assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
    });

    it('should treat diagnostics with different messages as inequal', () => {
        const diagnostic1 = new vscode.Diagnostic(
            range1,
            'Hello, world!',
            vscode.DiagnosticSeverity.Error
        );

        const diagnostic2 = new vscode.Diagnostic(
            range1,
            'Goodbye!, world!',
            vscode.DiagnosticSeverity.Error
        );

        assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
    });

    it('should treat diagnostics with different severities as inequal', () => {
        const diagnostic1 = new vscode.Diagnostic(
            range1,
            'Hello, world!',
            vscode.DiagnosticSeverity.Warning
        );

        const diagnostic2 = new vscode.Diagnostic(
            range1,
            'Hello, world!',
            vscode.DiagnosticSeverity.Error
        );

        assert(!areDiagnosticsEqual(diagnostic1, diagnostic2));
    });
});