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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/file_system/physical_resource_provider_test.dart
diff --git a/pkg/analyzer/test/file_system/physical_resource_provider_test.dart b/pkg/analyzer/test/file_system/physical_resource_provider_test.dart
index ff0a308a1d096ca5823b48dd4b0fc209033d0649..181fc54f0f8c7cec383a2c24ab4c7658a30e265a 100644
--- a/pkg/analyzer/test/file_system/physical_resource_provider_test.dart
+++ b/pkg/analyzer/test/file_system/physical_resource_provider_test.dart
@@ -132,6 +132,46 @@ class FileTest extends _BaseTest {
expect(file.readAsStringSync(), 'abc');
}
+ void test_renameSync_newDoesNotExist() {
+ String oldPath = '$tempPath/file.txt';
+ String newPath = '$tempPath/new-file.txt';
+ new io.File(oldPath).writeAsStringSync('text');
+ File file = PhysicalResourceProvider.INSTANCE.getResource(oldPath);
+ File newFile = file.renameSync(newPath);
+ expect(file.path, oldPath);
+ expect(file.exists, isFalse);
+ expect(newFile.path, newPath);
+ expect(newFile.exists, isTrue);
+ expect(newFile.readAsStringSync(), 'text');
+ }
+
+ void test_renameSync_newExists_file() {
+ String oldPath = '$tempPath/file.txt';
+ String newPath = '$tempPath/new-file.txt';
+ new io.File(oldPath).writeAsStringSync('text');
+ new io.File(newPath).writeAsStringSync('new text');
+ File file = PhysicalResourceProvider.INSTANCE.getResource(oldPath);
+ File newFile = file.renameSync(newPath);
+ expect(file.path, oldPath);
+ expect(file.exists, isFalse);
+ expect(newFile.path, newPath);
+ expect(newFile.exists, isTrue);
+ expect(newFile.readAsStringSync(), 'text');
+ }
+
+ void test_renameSync_newExists_folder() {
+ String oldPath = '$tempPath/file.txt';
+ String newPath = '$tempPath/foo';
+ new io.File(oldPath).writeAsStringSync('text');
+ new io.Directory(newPath).createSync();
+ File file = PhysicalResourceProvider.INSTANCE.getResource(oldPath);
+ expect(() {
+ file.renameSync(newPath);
+ }, throwsA(_isFileSystemException));
+ expect(file.path, oldPath);
+ expect(file.exists, isTrue);
+ }
+
void test_shortName() {
expect(file.shortName, 'file.txt');
}

Powered by Google App Engine
This is Rietveld 408576698