55import * as assert from 'assert' ;
66import { URI } from 'vs/base/common/uri' ;
77import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle' ;
8- import { workbenchInstantiationService , TestLifecycleService , TestTextFileService , TestContextService , TestFileService , TestElectronService , TestFilesConfigurationService , TestFileDialogService } from 'vs/workbench/test/workbenchTestServices' ;
8+ import { workbenchInstantiationService , TestLifecycleService , TestContextService , TestFileService , TestElectronService , TestFilesConfigurationService , TestFileDialogService , TestTextFileService } from 'vs/workbench/test/workbenchTestServices' ;
99import { toResource } from 'vs/base/test/common/utils' ;
1010import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
1111import { TextFileEditorModel } from 'vs/workbench/services/textfile/common/textFileEditorModel' ;
@@ -126,6 +126,19 @@ suite('Files - TextFileService', () => {
126126 assert . ok ( ! accessor . textFileService . isDirty ( model . resource ) ) ;
127127 } ) ;
128128
129+ test ( 'create' , async function ( ) {
130+ model = instantiationService . createInstance ( TextFileEditorModel , toResource . call ( this , '/path/file.txt' ) , 'utf8' , undefined ) ;
131+ ( < TextFileEditorModelManager > accessor . textFileService . files ) . add ( model . resource , model ) ;
132+
133+ await model . load ( ) ;
134+ model ! . textEditorModel ! . setValue ( 'foo' ) ;
135+ assert . ok ( accessor . textFileService . isDirty ( model . resource ) ) ;
136+
137+
138+ await accessor . textFileService . create ( model . resource , 'Foo' ) ;
139+ assert . ok ( ! accessor . textFileService . isDirty ( model . resource ) ) ;
140+ } ) ;
141+
129142 test ( 'delete - dirty file' , async function ( ) {
130143 model = instantiationService . createInstance ( TextFileEditorModel , toResource . call ( this , '/path/file.txt' ) , 'utf8' , undefined ) ;
131144 ( < TextFileEditorModelManager > accessor . textFileService . files ) . add ( model . resource , model ) ;
@@ -139,14 +152,22 @@ suite('Files - TextFileService', () => {
139152 } ) ;
140153
141154 test ( 'move - dirty file' , async function ( ) {
142- await testMove ( toResource . call ( this , '/path/file.txt' ) , toResource . call ( this , '/path/file_target.txt' ) ) ;
155+ await testMoveOrCopy ( toResource . call ( this , '/path/file.txt' ) , toResource . call ( this , '/path/file_target.txt' ) , true ) ;
143156 } ) ;
144157
145158 test ( 'move - dirty file (target exists and is dirty)' , async function ( ) {
146- await testMove ( toResource . call ( this , '/path/file.txt' ) , toResource . call ( this , '/path/file_target.txt' ) , true ) ;
159+ await testMoveOrCopy ( toResource . call ( this , '/path/file.txt' ) , toResource . call ( this , '/path/file_target.txt' ) , true , true ) ;
160+ } ) ;
161+
162+ test ( 'copy - dirty file' , async function ( ) {
163+ await testMoveOrCopy ( toResource . call ( this , '/path/file.txt' ) , toResource . call ( this , '/path/file_target.txt' ) , false ) ;
147164 } ) ;
148165
149- async function testMove ( source : URI , target : URI , targetDirty ?: boolean ) : Promise < void > {
166+ test ( 'copy - dirty file (target exists and is dirty)' , async function ( ) {
167+ await testMoveOrCopy ( toResource . call ( this , '/path/file.txt' ) , toResource . call ( this , '/path/file_target.txt' ) , false , true ) ;
168+ } ) ;
169+
170+ async function testMoveOrCopy ( source : URI , target : URI , move : boolean , targetDirty ?: boolean ) : Promise < void > {
150171 let sourceModel : TextFileEditorModel = instantiationService . createInstance ( TextFileEditorModel , source , 'utf8' , undefined ) ;
151172 let targetModel : TextFileEditorModel = instantiationService . createInstance ( TextFileEditorModel , target , 'utf8' , undefined ) ;
152173 ( < TextFileEditorModelManager > accessor . textFileService . files ) . add ( sourceModel . resource , sourceModel ) ;
@@ -162,11 +183,19 @@ suite('Files - TextFileService', () => {
162183 assert . ok ( accessor . textFileService . isDirty ( targetModel . resource ) ) ;
163184 }
164185
165- await accessor . textFileService . move ( sourceModel . resource , targetModel . resource , true ) ;
186+ if ( move ) {
187+ await accessor . textFileService . move ( sourceModel . resource , targetModel . resource , true ) ;
188+ } else {
189+ await accessor . textFileService . copy ( sourceModel . resource , targetModel . resource , true ) ;
190+ }
166191
167192 assert . equal ( targetModel . textEditorModel ! . getValue ( ) , 'foo' ) ;
168193
169- assert . ok ( ! accessor . textFileService . isDirty ( sourceModel . resource ) ) ;
194+ if ( move ) {
195+ assert . ok ( ! accessor . textFileService . isDirty ( sourceModel . resource ) ) ;
196+ } else {
197+ assert . ok ( accessor . textFileService . isDirty ( sourceModel . resource ) ) ;
198+ }
170199 assert . ok ( accessor . textFileService . isDirty ( targetModel . resource ) ) ;
171200
172201 sourceModel . dispose ( ) ;
0 commit comments