@@ -10,6 +10,7 @@ import { URI } from 'vs/base/common/uri';
10
10
import { IResourceEditorInput , ITextResourceEditorInput } from 'vs/platform/editor/common/editor' ;
11
11
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
12
12
import { DEFAULT_EDITOR_ASSOCIATION , IResourceDiffEditorInput , IResourceMergeEditorInput , IResourceSideBySideEditorInput , isEditorInput , isResourceDiffEditorInput , isResourceEditorInput , isResourceMergeEditorInput , isResourceSideBySideEditorInput , isUntitledResourceEditorInput , IUntitledTextResourceEditorInput } from 'vs/workbench/common/editor' ;
13
+ import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput' ;
13
14
import { EditorInput } from 'vs/workbench/common/editor/editorInput' ;
14
15
import { TextResourceEditorInput } from 'vs/workbench/common/editor/textResourceEditorInput' ;
15
16
import { FileEditorInput } from 'vs/workbench/contrib/files/browser/editors/fileEditorInput' ;
@@ -31,10 +32,45 @@ suite('EditorInput', () => {
31
32
const untypedResourceDiffEditorInput : IResourceDiffEditorInput = { original : untypedResourceEditorInput , modified : untypedResourceEditorInput , options : { override : DEFAULT_EDITOR_ASSOCIATION . id } } ;
32
33
const untypedResourceMergeEditorInput : IResourceMergeEditorInput = { base : untypedResourceEditorInput , input1 : untypedResourceEditorInput , input2 : untypedResourceEditorInput , result : untypedResourceEditorInput , options : { override : DEFAULT_EDITOR_ASSOCIATION . id } } ;
33
34
35
+ // Function to easily remove the overrides from the untyped inputs
36
+ const stripOverrides = ( ) => {
37
+ if (
38
+ ! untypedResourceEditorInput . options ||
39
+ ! untypedTextResourceEditorInput . options ||
40
+ ! untypedUntitledResourceEditorinput . options ||
41
+ ! untypedResourceDiffEditorInput . options ||
42
+ ! untypedResourceMergeEditorInput . options
43
+ ) {
44
+ throw new Error ( 'Malformed options on untyped inputs' ) ;
45
+ }
46
+ // Some of the tests mutate the overrides so we want to reset them on each test
47
+ untypedResourceEditorInput . options . override = undefined ;
48
+ untypedTextResourceEditorInput . options . override = undefined ;
49
+ untypedUntitledResourceEditorinput . options . override = undefined ;
50
+ untypedResourceDiffEditorInput . options . override = undefined ;
51
+ untypedResourceMergeEditorInput . options . override = undefined ;
52
+ } ;
53
+
34
54
setup ( ( ) => {
35
55
disposables = new DisposableStore ( ) ;
36
56
instantiationService = workbenchInstantiationService ( undefined , disposables ) ;
37
57
accessor = instantiationService . createInstance ( TestServiceAccessor ) ;
58
+
59
+ if (
60
+ ! untypedResourceEditorInput . options ||
61
+ ! untypedTextResourceEditorInput . options ||
62
+ ! untypedUntitledResourceEditorinput . options ||
63
+ ! untypedResourceDiffEditorInput . options ||
64
+ ! untypedResourceMergeEditorInput . options
65
+ ) {
66
+ throw new Error ( 'Malformed options on untyped inputs' ) ;
67
+ }
68
+ // Some of the tests mutate the overrides so we want to reset them on each test
69
+ untypedResourceEditorInput . options . override = DEFAULT_EDITOR_ASSOCIATION . id ;
70
+ untypedTextResourceEditorInput . options . override = DEFAULT_EDITOR_ASSOCIATION . id ;
71
+ untypedUntitledResourceEditorinput . options . override = DEFAULT_EDITOR_ASSOCIATION . id ;
72
+ untypedResourceDiffEditorInput . options . override = DEFAULT_EDITOR_ASSOCIATION . id ;
73
+ untypedResourceMergeEditorInput . options . override = DEFAULT_EDITOR_ASSOCIATION . id ;
38
74
} ) ;
39
75
40
76
teardown ( ( ) => {
@@ -116,6 +152,16 @@ suite('EditorInput', () => {
116
152
assert . ok ( ! fileEditorInput . matches ( untypedResourceDiffEditorInput ) ) ;
117
153
assert . ok ( ! fileEditorInput . matches ( untypedResourceMergeEditorInput ) ) ;
118
154
155
+ // Now we remove the override on the untyped to ensure that FileEditorInput supports lightweight resource matching
156
+ stripOverrides ( ) ;
157
+
158
+ assert . ok ( fileEditorInput . matches ( untypedResourceEditorInput ) ) ;
159
+ assert . ok ( fileEditorInput . matches ( untypedTextResourceEditorInput ) ) ;
160
+ assert . ok ( ! fileEditorInput . matches ( untypedResourceSideBySideEditorInput ) ) ;
161
+ assert . ok ( ! fileEditorInput . matches ( untypedUntitledResourceEditorinput ) ) ;
162
+ assert . ok ( ! fileEditorInput . matches ( untypedResourceDiffEditorInput ) ) ;
163
+ assert . ok ( ! fileEditorInput . matches ( untypedResourceMergeEditorInput ) ) ;
164
+
119
165
fileEditorInput . dispose ( ) ;
120
166
} ) ;
121
167
@@ -130,6 +176,15 @@ suite('EditorInput', () => {
130
176
assert . ok ( ! mergeEditorInput . matches ( untypedResourceDiffEditorInput ) ) ;
131
177
assert . ok ( mergeEditorInput . matches ( untypedResourceMergeEditorInput ) ) ;
132
178
179
+ stripOverrides ( ) ;
180
+
181
+ assert . ok ( ! mergeEditorInput . matches ( untypedResourceEditorInput ) ) ;
182
+ assert . ok ( ! mergeEditorInput . matches ( untypedTextResourceEditorInput ) ) ;
183
+ assert . ok ( ! mergeEditorInput . matches ( untypedResourceSideBySideEditorInput ) ) ;
184
+ assert . ok ( ! mergeEditorInput . matches ( untypedUntitledResourceEditorinput ) ) ;
185
+ assert . ok ( ! mergeEditorInput . matches ( untypedResourceDiffEditorInput ) ) ;
186
+ assert . ok ( mergeEditorInput . matches ( untypedResourceMergeEditorInput ) ) ;
187
+
133
188
mergeEditorInput . dispose ( ) ;
134
189
} ) ;
135
190
@@ -144,6 +199,41 @@ suite('EditorInput', () => {
144
199
assert . ok ( ! untitledTextEditorInput . matches ( untypedResourceDiffEditorInput ) ) ;
145
200
assert . ok ( ! untitledTextEditorInput . matches ( untypedResourceMergeEditorInput ) ) ;
146
201
202
+ stripOverrides ( ) ;
203
+
204
+ assert . ok ( ! untitledTextEditorInput . matches ( untypedResourceEditorInput ) ) ;
205
+ assert . ok ( ! untitledTextEditorInput . matches ( untypedTextResourceEditorInput ) ) ;
206
+ assert . ok ( ! untitledTextEditorInput . matches ( untypedResourceSideBySideEditorInput ) ) ;
207
+ assert . ok ( untitledTextEditorInput . matches ( untypedUntitledResourceEditorinput ) ) ;
208
+ assert . ok ( ! untitledTextEditorInput . matches ( untypedResourceDiffEditorInput ) ) ;
209
+ assert . ok ( ! untitledTextEditorInput . matches ( untypedResourceMergeEditorInput ) ) ;
210
+
147
211
untitledTextEditorInput . dispose ( ) ;
148
212
} ) ;
213
+
214
+ test ( 'Untyped inputs properly match DiffEditorInput' , ( ) => {
215
+ const fileEditorInput1 = instantiationService . createInstance ( FileEditorInput , testResource , undefined , undefined , undefined , undefined , undefined , undefined ) ;
216
+ const fileEditorInput2 = instantiationService . createInstance ( FileEditorInput , testResource , undefined , undefined , undefined , undefined , undefined , undefined ) ;
217
+ const diffEditorInput : DiffEditorInput = instantiationService . createInstance ( DiffEditorInput , undefined , undefined , fileEditorInput1 , fileEditorInput2 , false ) ;
218
+
219
+ assert . ok ( ! diffEditorInput . matches ( untypedResourceEditorInput ) ) ;
220
+ assert . ok ( ! diffEditorInput . matches ( untypedTextResourceEditorInput ) ) ;
221
+ assert . ok ( ! diffEditorInput . matches ( untypedResourceSideBySideEditorInput ) ) ;
222
+ assert . ok ( ! diffEditorInput . matches ( untypedUntitledResourceEditorinput ) ) ;
223
+ assert . ok ( diffEditorInput . matches ( untypedResourceDiffEditorInput ) ) ;
224
+ assert . ok ( ! diffEditorInput . matches ( untypedResourceMergeEditorInput ) ) ;
225
+
226
+ stripOverrides ( ) ;
227
+
228
+ assert . ok ( ! diffEditorInput . matches ( untypedResourceEditorInput ) ) ;
229
+ assert . ok ( ! diffEditorInput . matches ( untypedTextResourceEditorInput ) ) ;
230
+ assert . ok ( ! diffEditorInput . matches ( untypedResourceSideBySideEditorInput ) ) ;
231
+ assert . ok ( ! diffEditorInput . matches ( untypedUntitledResourceEditorinput ) ) ;
232
+ assert . ok ( diffEditorInput . matches ( untypedResourceDiffEditorInput ) ) ;
233
+ assert . ok ( ! diffEditorInput . matches ( untypedResourceMergeEditorInput ) ) ;
234
+
235
+ diffEditorInput . dispose ( ) ;
236
+ fileEditorInput1 . dispose ( ) ;
237
+ fileEditorInput2 . dispose ( ) ;
238
+ } ) ;
149
239
} ) ;
0 commit comments