/
TextEditor.ts
70 lines (58 loc) · 2.02 KB
/
TextEditor.ts
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
// eslint-disable-next-line node/no-missing-import
import type * as vscode from 'vscode';
import * as mockedTypes from './extHostTypes';
import { TestFramework } from '../TestFramework';
export function createMockTextEditor(
jest: TestFramework,
document: vscode.TextDocument,
_viewColumn?: vscode.ViewColumn | undefined,
selection?: vscode.Selection,
) {
class MockTextEditor implements vscode.TextEditor {
_options: vscode.TextEditorOptions = {};
_visibleRanges: vscode.Range[] = [];
_selections: vscode.Selection[];
constructor(
public _document: vscode.TextDocument,
public _viewColumn?: vscode.ViewColumn | undefined,
selection: vscode.Selection = new mockedTypes.Selection(
new mockedTypes.Position(0, 0),
new mockedTypes.Position(0, 0),
),
) {
this._selections = [selection];
}
get document(): vscode.TextDocument {
return this._document;
}
/**
* The primary selection on this text editor. Shorthand for `TextEditor.selections[0]`.
*/
get selection(): vscode.Selection {
return this.selections[0];
}
get selections(): vscode.Selection[] {
return this._selections;
}
get visibleRanges(): vscode.Range[] {
return this._visibleRanges;
}
get options(): vscode.TextEditorOptions {
return this._options;
}
set options(s: vscode.TextEditorOptions) {
this._options = s;
}
get viewColumn(): vscode.ViewColumn | undefined {
return this._viewColumn;
}
edit = jest.fn();
insertSnippet = jest.fn();
setDecorations = jest.fn();
revealRange = jest.fn();
show = jest.fn();
hide = jest.fn();
}
return new MockTextEditor(document, _viewColumn, selection);
}
export type MockTextEditor = ReturnType<typeof createMockTextEditor>;