Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1224)

Side by Side Diff: pkg/analyzer/test/file_system/physical_resource_provider_test.dart

Issue 1808213004: Add File.renameSync() to virtual file system. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.file_system.physical_resource_provider_test; 5 library analyzer.test.file_system.physical_resource_provider_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:core' hide Resource; 8 import 'dart:core' hide Resource;
9 import 'dart:io' as io; 9 import 'dart:io' as io;
10 10
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 file.readAsStringSync(); 125 file.readAsStringSync();
126 }, throwsA(_isFileSystemException)); 126 }, throwsA(_isFileSystemException));
127 } 127 }
128 128
129 void test_readAsStringSync_exists() { 129 void test_readAsStringSync_exists() {
130 new io.File(path).writeAsStringSync('abc'); 130 new io.File(path).writeAsStringSync('abc');
131 File file = PhysicalResourceProvider.INSTANCE.getResource(path); 131 File file = PhysicalResourceProvider.INSTANCE.getResource(path);
132 expect(file.readAsStringSync(), 'abc'); 132 expect(file.readAsStringSync(), 'abc');
133 } 133 }
134 134
135 void test_renameSync_newDoesNotExist() {
136 String oldPath = '$tempPath/file.txt';
137 String newPath = '$tempPath/new-file.txt';
138 new io.File(oldPath).writeAsStringSync('text');
139 File file = PhysicalResourceProvider.INSTANCE.getResource(oldPath);
140 File newFile = file.renameSync(newPath);
141 expect(file.path, oldPath);
142 expect(file.exists, isFalse);
143 expect(newFile.path, newPath);
144 expect(newFile.exists, isTrue);
145 expect(newFile.readAsStringSync(), 'text');
146 }
147
148 void test_renameSync_newExists_file() {
149 String oldPath = '$tempPath/file.txt';
150 String newPath = '$tempPath/new-file.txt';
151 new io.File(oldPath).writeAsStringSync('text');
152 new io.File(newPath).writeAsStringSync('new text');
153 File file = PhysicalResourceProvider.INSTANCE.getResource(oldPath);
154 File newFile = file.renameSync(newPath);
155 expect(file.path, oldPath);
156 expect(file.exists, isFalse);
157 expect(newFile.path, newPath);
158 expect(newFile.exists, isTrue);
159 expect(newFile.readAsStringSync(), 'text');
160 }
161
162 void test_renameSync_newExists_folder() {
163 String oldPath = '$tempPath/file.txt';
164 String newPath = '$tempPath/foo';
165 new io.File(oldPath).writeAsStringSync('text');
166 new io.Directory(newPath).createSync();
167 File file = PhysicalResourceProvider.INSTANCE.getResource(oldPath);
168 expect(() {
169 file.renameSync(newPath);
170 }, throwsA(_isFileSystemException));
171 expect(file.path, oldPath);
172 expect(file.exists, isTrue);
173 }
174
135 void test_shortName() { 175 void test_shortName() {
136 expect(file.shortName, 'file.txt'); 176 expect(file.shortName, 'file.txt');
137 } 177 }
138 178
139 void test_toString() { 179 void test_toString() {
140 expect(file.toString(), path); 180 expect(file.toString(), path);
141 } 181 }
142 182
143 void test_writeAsBytesSync() { 183 void test_writeAsBytesSync() {
144 new io.File(path).writeAsBytesSync(<int>[1, 2]); 184 new io.File(path).writeAsBytesSync(<int>[1, 2]);
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 506
467 setUp() { 507 setUp() {
468 tempDirectory = io.Directory.systemTemp.createTempSync('test_resource'); 508 tempDirectory = io.Directory.systemTemp.createTempSync('test_resource');
469 tempPath = tempDirectory.absolute.path; 509 tempPath = tempDirectory.absolute.path;
470 } 510 }
471 511
472 tearDown() { 512 tearDown() {
473 tempDirectory.deleteSync(recursive: true); 513 tempDirectory.deleteSync(recursive: true);
474 } 514 }
475 } 515 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698