|
1 |
| - |
2 | 1 | // @ts-nocheck
|
3 | 2 | // Mocked Uri interface
|
4 | 3 | export interface Uri {
|
5 |
| - scheme: string; |
6 |
| - path: string; |
| 4 | + scheme: string; |
| 5 | + path: string; |
7 | 6 | }
|
8 | 7 |
|
9 | 8 | // Mocked Position class
|
10 | 9 | export class Position {
|
11 |
| - constructor(public line: number, public character: number) { } |
| 10 | + constructor(public line: number, public character: number) {} |
12 | 11 |
|
13 |
| - isBefore(other: Position): boolean { |
14 |
| - return this.line < other.line || (this.line === other.line && this.character < other.character); |
15 |
| - } |
| 12 | + isBefore(other: Position): boolean { |
| 13 | + return this.line < other.line || (this.line === other.line && this.character < other.character); |
| 14 | + } |
16 | 15 |
|
17 |
| - // Mocked methods |
18 |
| - isBeforeOrEqual = jest.fn((other: Position) => this.isBefore(other) || this.isEqual(other)); |
19 |
| - isAfter = jest.fn((other: Position) => !this.isBeforeOrEqual(other)); |
20 |
| - isAfterOrEqual = jest.fn((other: Position) => this.isAfter(other) || this.isEqual(other)); |
21 |
| - isEqual = jest.fn((other: Position) => this.line === other.line && this.character === other.character); |
22 |
| - compareTo = jest.fn((other: Position) => { |
23 |
| - if (this.isBefore(other)) return -1; |
24 |
| - if (this.isAfter(other)) return 1; |
25 |
| - return 0; |
26 |
| - }); |
27 |
| - translate = jest.fn((lineDelta?: number, characterDelta?: number) => { |
28 |
| - const line = typeof lineDelta === 'number' ? this.line + lineDelta : this.line; |
29 |
| - const character = typeof characterDelta === 'number' ? this.character + characterDelta : this.character; |
30 |
| - return new Position(line, character); |
31 |
| - }); |
32 |
| - with = jest.fn((line?: number, character?: number) => new Position(line ?? this.line, character ?? this.character)); |
| 16 | + // Mocked methods |
| 17 | + isBeforeOrEqual = jest.fn((other: Position) => this.isBefore(other) || this.isEqual(other)); |
| 18 | + isAfter = jest.fn((other: Position) => !this.isBeforeOrEqual(other)); |
| 19 | + isAfterOrEqual = jest.fn((other: Position) => this.isAfter(other) || this.isEqual(other)); |
| 20 | + isEqual = jest.fn( |
| 21 | + (other: Position) => this.line === other.line && this.character === other.character, |
| 22 | + ); |
| 23 | + compareTo = jest.fn((other: Position) => { |
| 24 | + if (this.isBefore(other)) return -1; |
| 25 | + if (this.isAfter(other)) return 1; |
| 26 | + return 0; |
| 27 | + }); |
| 28 | + translate = jest.fn((lineDelta?: number, characterDelta?: number) => { |
| 29 | + const line = typeof lineDelta === 'number' ? this.line + lineDelta : this.line; |
| 30 | + const character = |
| 31 | + typeof characterDelta === 'number' ? this.character + characterDelta : this.character; |
| 32 | + return new Position(line, character); |
| 33 | + }); |
| 34 | + with = jest.fn( |
| 35 | + (line?: number, character?: number) => |
| 36 | + new Position(line ?? this.line, character ?? this.character), |
| 37 | + ); |
33 | 38 | }
|
34 | 39 |
|
35 | 40 | // Mocked Range class
|
36 | 41 | export class Range {
|
37 |
| - constructor(public start: Position, public end: Position) { } |
| 42 | + constructor(public start: Position, public end: Position) {} |
38 | 43 |
|
39 |
| - isEmpty = jest.fn(() => this.start.isEqual(this.end)); |
40 |
| - isSingleLine = jest.fn(() => this.start.line === this.end.line); |
41 |
| - contains = jest.fn((positionOrRange: Position | Range) => { |
42 |
| - if (positionOrRange instanceof Position) { |
43 |
| - return ( |
44 |
| - (positionOrRange.isAfterOrEqual(this.start) && positionOrRange.isBefore(this.end)) || |
45 |
| - positionOrRange.isEqual(this.start) || |
46 |
| - positionOrRange.isEqual(this.end) |
47 |
| - ); |
48 |
| - } |
49 |
| - return ( |
50 |
| - this.contains(positionOrRange.start) || |
51 |
| - this.contains(positionOrRange.end) || |
52 |
| - (positionOrRange.start.isBeforeOrEqual(this.start) && positionOrRange.end.isAfterOrEqual(this.end)) |
53 |
| - ); |
54 |
| - }); |
55 |
| - isEqual = jest.fn((other: Range) => this.start.isEqual(other.start) && this.end.isEqual(other.end)); |
56 |
| - intersection = jest.fn((range: Range) => { |
57 |
| - const start = this.start.isBefore(range.start) ? range.start : this.start; |
58 |
| - const end = this.end.isAfter(range.end) ? range.end : this.end; |
59 |
| - return start.isBefore(end) ? new Range(start, end) : undefined; |
60 |
| - }); |
61 |
| - union = jest.fn((other: Range) => { |
62 |
| - const start = this.start.isBefore(other.start) ? this.start : other.start; |
63 |
| - const end = this.end.isAfter(other.end) ? this.end : other.end; |
64 |
| - return new Range(start, end); |
65 |
| - }); |
66 |
| - with = jest.fn((start?: Position, end?: Position) => new Range(start ?? this.start, end ?? this.end)); |
| 44 | + isEmpty = jest.fn(() => this.start.isEqual(this.end)); |
| 45 | + isSingleLine = jest.fn(() => this.start.line === this.end.line); |
| 46 | + contains = jest.fn((positionOrRange: Position | Range) => { |
| 47 | + if (positionOrRange instanceof Position) { |
| 48 | + return ( |
| 49 | + (positionOrRange.isAfterOrEqual(this.start) && positionOrRange.isBefore(this.end)) || |
| 50 | + positionOrRange.isEqual(this.start) || |
| 51 | + positionOrRange.isEqual(this.end) |
| 52 | + ); |
| 53 | + } |
| 54 | + return ( |
| 55 | + this.contains(positionOrRange.start) || |
| 56 | + this.contains(positionOrRange.end) || |
| 57 | + (positionOrRange.start.isBeforeOrEqual(this.start) && |
| 58 | + positionOrRange.end.isAfterOrEqual(this.end)) |
| 59 | + ); |
| 60 | + }); |
| 61 | + isEqual = jest.fn( |
| 62 | + (other: Range) => this.start.isEqual(other.start) && this.end.isEqual(other.end), |
| 63 | + ); |
| 64 | + intersection = jest.fn((range: Range) => { |
| 65 | + const start = this.start.isBefore(range.start) ? range.start : this.start; |
| 66 | + const end = this.end.isAfter(range.end) ? range.end : this.end; |
| 67 | + return start.isBefore(end) ? new Range(start, end) : undefined; |
| 68 | + }); |
| 69 | + union = jest.fn((other: Range) => { |
| 70 | + const start = this.start.isBefore(other.start) ? this.start : other.start; |
| 71 | + const end = this.end.isAfter(other.end) ? this.end : other.end; |
| 72 | + return new Range(start, end); |
| 73 | + }); |
| 74 | + with = jest.fn( |
| 75 | + (start?: Position, end?: Position) => new Range(start ?? this.start, end ?? this.end), |
| 76 | + ); |
67 | 77 | }
|
68 | 78 |
|
69 | 79 | // Mocked TextDocument interface
|
70 | 80 | export interface TextDocument {
|
71 |
| - uri: Uri; |
72 |
| - fileName: string; |
73 |
| - languageId: string; |
74 |
| - version: number; |
75 |
| - isDirty: boolean; |
76 |
| - isClosed: boolean; |
| 81 | + uri: Uri; |
| 82 | + fileName: string; |
| 83 | + languageId: string; |
| 84 | + version: number; |
| 85 | + isDirty: boolean; |
| 86 | + isClosed: boolean; |
77 | 87 |
|
78 |
| - // Implement other properties and methods |
| 88 | + // Implement other properties and methods |
79 | 89 | }
|
80 | 90 |
|
81 | 91 | export class ExtensionContextMock {
|
82 |
| - // Add any necessary properties and methods here for your tests |
83 |
| - subscriptions: { dispose: jest.Mock }[] = []; |
| 92 | + // Add any necessary properties and methods here for your tests |
| 93 | + subscriptions: { dispose: jest.Mock }[] = []; |
84 | 94 |
|
85 |
| - // Mock method to subscribe to events |
86 |
| - subscribe(subscription: { dispose: jest.Mock }): void { |
87 |
| - this.subscriptions.push(subscription); |
88 |
| - } |
| 95 | + // Mock method to subscribe to events |
| 96 | + subscribe(subscription: { dispose: jest.Mock }): void { |
| 97 | + this.subscriptions.push(subscription); |
| 98 | + } |
89 | 99 |
|
90 |
| - // Mock method to trigger disposal of subscriptions |
91 |
| - dispose(): void { |
92 |
| - this.subscriptions.forEach(sub => sub.dispose()); |
93 |
| - this.subscriptions = []; |
94 |
| - } |
| 100 | + // Mock method to trigger disposal of subscriptions |
| 101 | + dispose(): void { |
| 102 | + this.subscriptions.forEach(sub => sub.dispose()); |
| 103 | + this.subscriptions = []; |
| 104 | + } |
95 | 105 | }
|
96 | 106 |
|
97 | 107 | // Mocked vscode module
|
98 | 108 | const vscode = {
|
99 |
| - version: '1.0.0', |
100 |
| - Position, |
101 |
| - Range, |
102 |
| - Uri: { scheme: '', path: '' }, |
103 |
| - window: { |
104 |
| - activeTextEditor: { |
105 |
| - document: null as TextDocument | null, |
106 |
| - }, |
107 |
| - }, |
108 |
| - commands: { |
109 |
| - executeCommand: jest.fn(), |
110 |
| - }, |
111 |
| - languages: { |
112 |
| - getTextDocument: jest.fn(), |
113 |
| - }, |
114 |
| - env: { |
115 |
| - isTelemetryEnabled: true, |
116 |
| - machineId: '123456789', |
| 109 | + version: '1.0.0', |
| 110 | + Position, |
| 111 | + Range, |
| 112 | + Uri: { scheme: '', path: '' }, |
| 113 | + window: { |
| 114 | + activeTextEditor: { |
| 115 | + document: null as TextDocument | null, |
117 | 116 | },
|
| 117 | + }, |
| 118 | + commands: { |
| 119 | + executeCommand: jest.fn(), |
| 120 | + }, |
| 121 | + languages: { |
| 122 | + getTextDocument: jest.fn(), |
| 123 | + }, |
| 124 | + env: { |
| 125 | + isTelemetryEnabled: true, |
| 126 | + machineId: '123456789', |
| 127 | + }, |
118 | 128 | };
|
119 | 129 |
|
120 | 130 | vscode.ExtensionContext = ExtensionContextMock;
|
|
0 commit comments