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

Unified Diff: pkg/analyzer/test/file_system/memory_file_system_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/memory_file_system_test.dart
diff --git a/pkg/analyzer/test/file_system/memory_file_system_test.dart b/pkg/analyzer/test/file_system/memory_file_system_test.dart
index 87a82bfc09dae33df8bb7cbfe854dd5e46414b60..759362b9551ce8f6396c800fee525ec637ef75be 100644
--- a/pkg/analyzer/test/file_system/memory_file_system_test.dart
+++ b/pkg/analyzer/test/file_system/memory_file_system_test.dart
@@ -148,6 +148,43 @@ class FileTest {
expect(file.readAsStringSync(), 'abc');
}
+ void test_renameSync_newDoesNotExist() {
+ String oldPath = '/foo/bar/file.txt';
+ String newPath = '/foo/bar/new-file.txt';
+ File file = provider.newFile(oldPath, 'text');
+ 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 = '/foo/bar/file.txt';
+ String newPath = '/foo/bar/new-file.txt';
+ File file = provider.newFile(oldPath, 'text');
+ provider.newFile(newPath, 'new text');
+ 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 = '/foo/bar/file.txt';
+ String newPath = '/foo/bar/baz';
+ File file = provider.newFile(oldPath, 'text');
+ provider.newFolder(newPath);
+ expect(() {
+ file.renameSync(newPath);
+ }, throwsA(_isFileSystemException));
+ expect(file.path, oldPath);
+ expect(file.exists, isTrue);
+ }
+
void test_shortName() {
File file = provider.getResource('/foo/bar/file.txt');
expect(file.shortName, 'file.txt');
@@ -158,13 +195,22 @@ class FileTest {
expect(file.toString(), '/foo/bar/file.txt');
}
- void test_writeAsBytesSync() {
- File file = provider.newFileWithBytes('/file.bin', <int>[1, 2]);
+ void test_writeAsBytesSync_existing() {
+ File file = provider.newFileWithBytes('/foo/file.bin', <int>[1, 2]);
expect(file.readAsBytesSync(), <int>[1, 2]);
// write new bytes
file.writeAsBytesSync(<int>[10, 20]);
expect(file.readAsBytesSync(), <int>[10, 20]);
}
+
+ void test_writeAsBytesSync_new() {
+ File file = provider.getFile('/foo/file.bin');
+ expect(file.exists, false);
+ // write new bytes
+ file.writeAsBytesSync(<int>[10, 20]);
+ expect(file.exists, true);
+ expect(file.readAsBytesSync(), <int>[10, 20]);
+ }
}
@reflectiveTest
@@ -498,14 +544,14 @@ class MemoryResourceProviderTest {
expect(file.readAsBytesSync(), bytes);
}
- void test_newFolder_aleadyExists_asFile() {
+ void test_newFolder_alreadyExists_asFile() {
provider.newFile('/my/file', 'qwerty');
expect(() {
provider.newFolder('/my/file');
}, throwsA(new isInstanceOf<ArgumentError>()));
}
- void test_newFolder_aleadyExists_asFolder() {
+ void test_newFolder_alreadyExists_asFolder() {
Folder folder = provider.newFolder('/my/folder');
Folder newFolder = provider.newFolder('/my/folder');
expect(newFolder, folder);

Powered by Google App Engine
This is Rietveld 408576698