|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 | 6 | import * as assert from 'assert';
|
| 7 | +import { DisposableStore } from 'vs/base/common/lifecycle'; |
| 8 | +import { Schemas } from 'vs/base/common/network'; |
7 | 9 | import { URI } from 'vs/base/common/uri';
|
8 |
| -import { isEditorInput, isResourceDiffEditorInput, isResourceEditorInput, isResourceMergeEditorInput, isResourceSideBySideEditorInput, isUntitledResourceEditorInput } from 'vs/workbench/common/editor'; |
| 10 | +import { IResourceEditorInput, ITextResourceEditorInput } from 'vs/platform/editor/common/editor'; |
| 11 | +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; |
| 12 | +import { DEFAULT_EDITOR_ASSOCIATION, IResourceDiffEditorInput, IResourceMergeEditorInput, IResourceSideBySideEditorInput, isEditorInput, isResourceDiffEditorInput, isResourceEditorInput, isResourceMergeEditorInput, isResourceSideBySideEditorInput, isUntitledResourceEditorInput, IUntitledTextResourceEditorInput } from 'vs/workbench/common/editor'; |
9 | 13 | import { EditorInput } from 'vs/workbench/common/editor/editorInput';
|
10 |
| -import { TestEditorInput } from 'vs/workbench/test/browser/workbenchTestServices'; |
| 14 | +import { TextResourceEditorInput } from 'vs/workbench/common/editor/textResourceEditorInput'; |
| 15 | +import { FileEditorInput } from 'vs/workbench/contrib/files/browser/editors/fileEditorInput'; |
| 16 | +import { MergeEditorInput, MergeEditorInputData } from 'vs/workbench/contrib/mergeEditor/browser/mergeEditorInput'; |
| 17 | +import { UntitledTextEditorInput } from 'vs/workbench/services/untitled/common/untitledTextEditorInput'; |
| 18 | +import { TestEditorInput, TestServiceAccessor, workbenchInstantiationService } from 'vs/workbench/test/browser/workbenchTestServices'; |
11 | 19 |
|
12 | 20 | suite('EditorInput', () => {
|
13 | 21 |
|
| 22 | + let instantiationService: IInstantiationService; |
| 23 | + let accessor: TestServiceAccessor; |
| 24 | + let disposables: DisposableStore; |
| 25 | + |
| 26 | + const testResource: URI = URI.from({ scheme: 'random', path: '/path' }); |
| 27 | + const untypedResourceEditorInput: IResourceEditorInput = { resource: testResource, options: { override: DEFAULT_EDITOR_ASSOCIATION.id } }; |
| 28 | + const untypedTextResourceEditorInput: ITextResourceEditorInput = { resource: testResource, options: { override: DEFAULT_EDITOR_ASSOCIATION.id } }; |
| 29 | + const untypedResourceSideBySideEditorInput: IResourceSideBySideEditorInput = { primary: untypedResourceEditorInput, secondary: untypedResourceEditorInput, options: { override: DEFAULT_EDITOR_ASSOCIATION.id } }; |
| 30 | + const untypedUntitledResourceEditorinput: IUntitledTextResourceEditorInput = { resource: URI.from({ scheme: Schemas.untitled, path: '/path' }), options: { override: DEFAULT_EDITOR_ASSOCIATION.id } }; |
| 31 | + const untypedResourceDiffEditorInput: IResourceDiffEditorInput = { original: untypedResourceEditorInput, modified: untypedResourceEditorInput, options: { override: DEFAULT_EDITOR_ASSOCIATION.id } }; |
| 32 | + const untypedResourceMergeEditorInput: IResourceMergeEditorInput = { base: untypedResourceEditorInput, input1: untypedResourceEditorInput, input2: untypedResourceEditorInput, result: untypedResourceEditorInput, options: { override: DEFAULT_EDITOR_ASSOCIATION.id } }; |
| 33 | + |
| 34 | + setup(() => { |
| 35 | + disposables = new DisposableStore(); |
| 36 | + instantiationService = workbenchInstantiationService(undefined, disposables); |
| 37 | + accessor = instantiationService.createInstance(TestServiceAccessor); |
| 38 | + }); |
| 39 | + |
| 40 | + teardown(() => { |
| 41 | + disposables.dispose(); |
| 42 | + }); |
| 43 | + |
14 | 44 | class MyEditorInput extends EditorInput {
|
15 | 45 | readonly resource = undefined;
|
16 | 46 |
|
@@ -62,4 +92,58 @@ suite('EditorInput', () => {
|
62 | 92 | assert.ok(!testInput.matches(testUntypedInputWrong));
|
63 | 93 |
|
64 | 94 | });
|
| 95 | + |
| 96 | + test('Untpyed inputs properly match TextResourceEditorInput', () => { |
| 97 | + const textResourceEditorInput = instantiationService.createInstance(TextResourceEditorInput, testResource, undefined, undefined, undefined, undefined); |
| 98 | + |
| 99 | + assert.ok(textResourceEditorInput.matches(untypedResourceEditorInput)); |
| 100 | + assert.ok(textResourceEditorInput.matches(untypedTextResourceEditorInput)); |
| 101 | + assert.ok(!textResourceEditorInput.matches(untypedResourceSideBySideEditorInput)); |
| 102 | + assert.ok(!textResourceEditorInput.matches(untypedUntitledResourceEditorinput)); |
| 103 | + assert.ok(!textResourceEditorInput.matches(untypedResourceDiffEditorInput)); |
| 104 | + assert.ok(!textResourceEditorInput.matches(untypedResourceMergeEditorInput)); |
| 105 | + |
| 106 | + textResourceEditorInput.dispose(); |
| 107 | + }); |
| 108 | + |
| 109 | + test('Untyped inputs properly match FileEditorInput', () => { |
| 110 | + const fileEditorInput = instantiationService.createInstance(FileEditorInput, testResource, undefined, undefined, undefined, undefined, undefined, undefined); |
| 111 | + |
| 112 | + assert.ok(fileEditorInput.matches(untypedResourceEditorInput)); |
| 113 | + assert.ok(fileEditorInput.matches(untypedTextResourceEditorInput)); |
| 114 | + assert.ok(!fileEditorInput.matches(untypedResourceSideBySideEditorInput)); |
| 115 | + assert.ok(!fileEditorInput.matches(untypedUntitledResourceEditorinput)); |
| 116 | + assert.ok(!fileEditorInput.matches(untypedResourceDiffEditorInput)); |
| 117 | + assert.ok(!fileEditorInput.matches(untypedResourceMergeEditorInput)); |
| 118 | + |
| 119 | + fileEditorInput.dispose(); |
| 120 | + }); |
| 121 | + |
| 122 | + test('Untyped inputs properly match MergeEditorInput', () => { |
| 123 | + const mergeData: MergeEditorInputData = { uri: testResource, description: undefined, detail: undefined, title: undefined }; |
| 124 | + const mergeEditorInput = instantiationService.createInstance(MergeEditorInput, testResource, mergeData, mergeData, testResource); |
| 125 | + |
| 126 | + assert.ok(!mergeEditorInput.matches(untypedResourceEditorInput)); |
| 127 | + assert.ok(!mergeEditorInput.matches(untypedTextResourceEditorInput)); |
| 128 | + assert.ok(!mergeEditorInput.matches(untypedResourceSideBySideEditorInput)); |
| 129 | + assert.ok(!mergeEditorInput.matches(untypedUntitledResourceEditorinput)); |
| 130 | + assert.ok(!mergeEditorInput.matches(untypedResourceDiffEditorInput)); |
| 131 | + assert.ok(mergeEditorInput.matches(untypedResourceMergeEditorInput)); |
| 132 | + |
| 133 | + mergeEditorInput.dispose(); |
| 134 | + }); |
| 135 | + |
| 136 | + test('Untyped inputs properly match UntitledTextEditorInput', () => { |
| 137 | + const untitledModel = accessor.untitledTextEditorService.create({ associatedResource: { authority: '', path: '/path', fragment: '', query: '' } }); |
| 138 | + const untitledTextEditorInput: UntitledTextEditorInput = instantiationService.createInstance(UntitledTextEditorInput, untitledModel); |
| 139 | + |
| 140 | + assert.ok(!untitledTextEditorInput.matches(untypedResourceEditorInput)); |
| 141 | + assert.ok(!untitledTextEditorInput.matches(untypedTextResourceEditorInput)); |
| 142 | + assert.ok(!untitledTextEditorInput.matches(untypedResourceSideBySideEditorInput)); |
| 143 | + assert.ok(untitledTextEditorInput.matches(untypedUntitledResourceEditorinput)); |
| 144 | + assert.ok(!untitledTextEditorInput.matches(untypedResourceDiffEditorInput)); |
| 145 | + assert.ok(!untitledTextEditorInput.matches(untypedResourceMergeEditorInput)); |
| 146 | + |
| 147 | + untitledTextEditorInput.dispose(); |
| 148 | + }); |
65 | 149 | });
|
0 commit comments