@@ -26,6 +26,10 @@ import { timeout } from 'vs/base/common/async';
26
26
27
27
suite ( 'Untitled text editors' , ( ) => {
28
28
29
+ class TestUntitledTextEditorInput extends UntitledTextEditorInput {
30
+ getModel ( ) { return this . model ; }
31
+ }
32
+
29
33
const disposables = new DisposableStore ( ) ;
30
34
let instantiationService : IInstantiationService ;
31
35
let accessor : TestServiceAccessor ;
@@ -44,11 +48,19 @@ suite('Untitled text editors', () => {
44
48
const service = accessor . untitledTextEditorService ;
45
49
const workingCopyService = accessor . workingCopyService ;
46
50
47
- const input1 = instantiationService . createInstance ( UntitledTextEditorInput , service . create ( ) ) ;
51
+ const events : IUntitledTextEditorModel [ ] = [ ] ;
52
+ disposables . add ( service . onDidCreate ( model => {
53
+ events . push ( model ) ;
54
+ } ) ) ;
55
+
56
+ const input1 = instantiationService . createInstance ( TestUntitledTextEditorInput , service . create ( ) ) ;
48
57
await input1 . resolve ( ) ;
49
- assert . strictEqual ( service . get ( input1 . resource ) , input1 . model ) ;
58
+ assert . strictEqual ( service . get ( input1 . resource ) , input1 . getModel ( ) ) ;
50
59
assert . ok ( ! accessor . untitledTextEditorService . isUntitledWithAssociatedResource ( input1 . resource ) ) ;
51
60
61
+ assert . strictEqual ( events . length , 1 ) ;
62
+ assert . strictEqual ( events [ 0 ] . resource . toString ( ) , input1 . getModel ( ) . resource . toString ( ) ) ;
63
+
52
64
assert . ok ( service . get ( input1 . resource ) ) ;
53
65
assert . ok ( ! service . get ( URI . file ( 'testing' ) ) ) ;
54
66
@@ -59,16 +71,16 @@ suite('Untitled text editors', () => {
59
71
assert . ok ( ! input1 . hasCapability ( EditorInputCapabilities . RequiresTrust ) ) ;
60
72
assert . ok ( ! input1 . hasCapability ( EditorInputCapabilities . Scratchpad ) ) ;
61
73
62
- const input2 = instantiationService . createInstance ( UntitledTextEditorInput , service . create ( ) ) ;
63
- assert . strictEqual ( service . get ( input2 . resource ) , input2 . model ) ;
74
+ const input2 = instantiationService . createInstance ( TestUntitledTextEditorInput , service . create ( ) ) ;
75
+ assert . strictEqual ( service . get ( input2 . resource ) , input2 . getModel ( ) ) ;
64
76
65
77
// toUntyped()
66
78
const untypedInput = input1 . toUntyped ( { preserveViewState : 0 } ) ;
67
79
assert . strictEqual ( untypedInput . forceUntitled , true ) ;
68
80
69
81
// get()
70
- assert . strictEqual ( service . get ( input1 . resource ) , input1 . model ) ;
71
- assert . strictEqual ( service . get ( input2 . resource ) , input2 . model ) ;
82
+ assert . strictEqual ( service . get ( input1 . resource ) , input1 . getModel ( ) ) ;
83
+ assert . strictEqual ( service . get ( input2 . resource ) , input2 . getModel ( ) ) ;
72
84
73
85
// revert()
74
86
await input1 . revert ( 0 ) ;
@@ -80,6 +92,9 @@ suite('Untitled text editors', () => {
80
92
assert . strictEqual ( await service . resolve ( { untitledResource : input2 . resource } ) , model ) ;
81
93
assert . ok ( service . get ( model . resource ) ) ;
82
94
95
+ assert . strictEqual ( events . length , 2 ) ;
96
+ assert . strictEqual ( events [ 1 ] . resource . toString ( ) , input2 . resource . toString ( ) ) ;
97
+
83
98
assert . ok ( ! input2 . isDirty ( ) ) ;
84
99
85
100
const resourcePromise = awaitDidChangeDirty ( accessor . untitledTextEditorService ) ;
@@ -214,10 +229,10 @@ suite('Untitled text editors', () => {
214
229
const service = accessor . untitledTextEditorService ;
215
230
const workingCopyService = accessor . workingCopyService ;
216
231
217
- const untitled = disposables . add ( instantiationService . createInstance ( UntitledTextEditorInput , service . create ( { initialValue : 'Hello World' } ) ) ) ;
232
+ const untitled = disposables . add ( instantiationService . createInstance ( TestUntitledTextEditorInput , service . create ( { initialValue : 'Hello World' } ) ) ) ;
218
233
assert . ok ( untitled . isDirty ( ) ) ;
219
234
220
- const backup = ( await untitled . model . backup ( CancellationToken . None ) ) . content ;
235
+ const backup = ( await untitled . getModel ( ) . backup ( CancellationToken . None ) ) . content ;
221
236
if ( isReadableStream ( backup ) ) {
222
237
const value = await streamToBuffer ( backup as VSBufferReadableStream ) ;
223
238
assert . strictEqual ( value . toString ( ) , 'Hello World' ) ;
@@ -307,9 +322,9 @@ suite('Untitled text editors', () => {
307
322
const model = disposables . add ( service . create ( ) ) ;
308
323
const input = disposables . add ( instantiationService . createInstance ( UntitledTextEditorInput , model ) ) ;
309
324
310
- assert . ok ( ! input . model . hasLanguageSetExplicitly ) ;
325
+ assert . ok ( ! input . hasLanguageSetExplicitly ) ;
311
326
input . setLanguageId ( PLAINTEXT_LANGUAGE_ID ) ;
312
- assert . ok ( input . model . hasLanguageSetExplicitly ) ;
327
+ assert . ok ( input . hasLanguageSetExplicitly ) ;
313
328
314
329
assert . strictEqual ( input . getLanguageId ( ) , PLAINTEXT_LANGUAGE_ID ) ;
315
330
} ) ;
@@ -327,9 +342,9 @@ suite('Untitled text editors', () => {
327
342
const input = disposables . add ( instantiationService . createInstance ( UntitledTextEditorInput , model ) ) ;
328
343
disposables . add ( await input . resolve ( ) ) ;
329
344
330
- assert . ok ( ! input . model . hasLanguageSetExplicitly ) ;
345
+ assert . ok ( ! input . hasLanguageSetExplicitly ) ;
331
346
model . textEditorModel ! . setLanguage ( accessor . languageService . createById ( language ) ) ;
332
- assert . ok ( input . model . hasLanguageSetExplicitly ) ;
347
+ assert . ok ( input . hasLanguageSetExplicitly ) ;
333
348
334
349
assert . strictEqual ( model . getLanguageId ( ) , language ) ;
335
350
} ) ;
@@ -346,12 +361,12 @@ suite('Untitled text editors', () => {
346
361
const input = disposables . add ( instantiationService . createInstance ( UntitledTextEditorInput , model ) ) ;
347
362
await input . resolve ( ) ;
348
363
349
- assert . ok ( ! input . model . hasLanguageSetExplicitly ) ;
364
+ assert . ok ( ! input . hasLanguageSetExplicitly ) ;
350
365
model . textEditorModel ! . setLanguage (
351
366
accessor . languageService . createById ( language ) ,
352
367
// This is really what this is testing
353
368
LanguageDetectionLanguageEventSource ) ;
354
- assert . ok ( ! input . model . hasLanguageSetExplicitly ) ;
369
+ assert . ok ( ! input . hasLanguageSetExplicitly ) ;
355
370
356
371
assert . strictEqual ( model . getLanguageId ( ) , language ) ;
357
372
} ) ;
0 commit comments