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
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { isEditorInput, isResourceDiffEditorInput, isResourceEditorInput, isResourceMergeEditorInput, isResourceSideBySideEditorInput, isUntitledResourceEditorInput } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { TestEditorInput } from 'vs/workbench/test/browser/workbenchTestServices';
suite('EditorInput', () => {
class MyEditorInput extends EditorInput {
readonly resource = undefined;
override get typeId(): string { return 'myEditorInput'; }
override resolve(): any { return null; }
}
test('basics', () => {
let counter = 0;
const input = new MyEditorInput();
const otherInput = new MyEditorInput();
assert.ok(isEditorInput(input));
assert.ok(!isEditorInput(undefined));
assert.ok(!isEditorInput({ resource: URI.file('/') }));
assert.ok(!isEditorInput({}));
assert.ok(!isResourceEditorInput(input));
assert.ok(!isUntitledResourceEditorInput(input));
assert.ok(!isResourceDiffEditorInput(input));
assert.ok(!isResourceMergeEditorInput(input));
assert.ok(!isResourceSideBySideEditorInput(input));
assert(input.matches(input));
assert(!input.matches(otherInput));
assert(input.getName());
input.onWillDispose(() => {
assert(true);
counter++;
});
input.dispose();
assert.strictEqual(counter, 1);
});
test('untyped matches', () => {
const testInputID = 'untypedMatches';
const testInputResource = URI.file('/fake');
const testInput = new TestEditorInput(testInputResource, testInputID);
const testUntypedInput = { resource: testInputResource, options: { override: testInputID } };
const tetUntypedInputWrongResource = { resource: URI.file('/incorrectFake'), options: { override: testInputID } };
const testUntypedInputWrongId = { resource: testInputResource, options: { override: 'wrongId' } };
const testUntypedInputWrong = { resource: URI.file('/incorrectFake'), options: { override: 'wrongId' } };
assert(testInput.matches(testUntypedInput));
assert.ok(!testInput.matches(tetUntypedInputWrongResource));
assert.ok(!testInput.matches(testUntypedInputWrongId));
assert.ok(!testInput.matches(testUntypedInputWrong));
});
});
|