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

Side by Side 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 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.memory_file_system_test; 5 library analyzer.test.file_system.memory_file_system_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:core' hide Resource; 8 import 'dart:core' hide Resource;
9 9
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 expect(() { 141 expect(() {
142 file.readAsStringSync(); 142 file.readAsStringSync();
143 }, throwsA(_isFileSystemException)); 143 }, throwsA(_isFileSystemException));
144 } 144 }
145 145
146 void test_readAsStringSync_exists() { 146 void test_readAsStringSync_exists() {
147 File file = provider.newFile('/file.txt', 'abc'); 147 File file = provider.newFile('/file.txt', 'abc');
148 expect(file.readAsStringSync(), 'abc'); 148 expect(file.readAsStringSync(), 'abc');
149 } 149 }
150 150
151 void test_renameSync_newDoesNotExist() {
152 String oldPath = '/foo/bar/file.txt';
153 String newPath = '/foo/bar/new-file.txt';
154 File file = provider.newFile(oldPath, 'text');
155 File newFile = file.renameSync(newPath);
156 expect(file.path, oldPath);
157 expect(file.exists, isFalse);
158 expect(newFile.path, newPath);
159 expect(newFile.exists, isTrue);
160 expect(newFile.readAsStringSync(), 'text');
161 }
162
163 void test_renameSync_newExists_file() {
164 String oldPath = '/foo/bar/file.txt';
165 String newPath = '/foo/bar/new-file.txt';
166 File file = provider.newFile(oldPath, 'text');
167 provider.newFile(newPath, 'new text');
168 File newFile = file.renameSync(newPath);
169 expect(file.path, oldPath);
170 expect(file.exists, isFalse);
171 expect(newFile.path, newPath);
172 expect(newFile.exists, isTrue);
173 expect(newFile.readAsStringSync(), 'text');
174 }
175
176 void test_renameSync_newExists_folder() {
177 String oldPath = '/foo/bar/file.txt';
178 String newPath = '/foo/bar/baz';
179 File file = provider.newFile(oldPath, 'text');
180 provider.newFolder(newPath);
181 expect(() {
182 file.renameSync(newPath);
183 }, throwsA(_isFileSystemException));
184 expect(file.path, oldPath);
185 expect(file.exists, isTrue);
186 }
187
151 void test_shortName() { 188 void test_shortName() {
152 File file = provider.getResource('/foo/bar/file.txt'); 189 File file = provider.getResource('/foo/bar/file.txt');
153 expect(file.shortName, 'file.txt'); 190 expect(file.shortName, 'file.txt');
154 } 191 }
155 192
156 void test_toString() { 193 void test_toString() {
157 File file = provider.getResource('/foo/bar/file.txt'); 194 File file = provider.getResource('/foo/bar/file.txt');
158 expect(file.toString(), '/foo/bar/file.txt'); 195 expect(file.toString(), '/foo/bar/file.txt');
159 } 196 }
160 197
161 void test_writeAsBytesSync() { 198 void test_writeAsBytesSync_existing() {
162 File file = provider.newFileWithBytes('/file.bin', <int>[1, 2]); 199 File file = provider.newFileWithBytes('/foo/file.bin', <int>[1, 2]);
163 expect(file.readAsBytesSync(), <int>[1, 2]); 200 expect(file.readAsBytesSync(), <int>[1, 2]);
164 // write new bytes 201 // write new bytes
165 file.writeAsBytesSync(<int>[10, 20]); 202 file.writeAsBytesSync(<int>[10, 20]);
166 expect(file.readAsBytesSync(), <int>[10, 20]); 203 expect(file.readAsBytesSync(), <int>[10, 20]);
167 } 204 }
205
206 void test_writeAsBytesSync_new() {
207 File file = provider.getFile('/foo/file.bin');
208 expect(file.exists, false);
209 // write new bytes
210 file.writeAsBytesSync(<int>[10, 20]);
211 expect(file.exists, true);
212 expect(file.readAsBytesSync(), <int>[10, 20]);
213 }
168 } 214 }
169 215
170 @reflectiveTest 216 @reflectiveTest
171 class FolderTest { 217 class FolderTest {
172 static const String path = '/foo/bar'; 218 static const String path = '/foo/bar';
173 219
174 MemoryResourceProvider provider = new MemoryResourceProvider(); 220 MemoryResourceProvider provider = new MemoryResourceProvider();
175 Folder folder; 221 Folder folder;
176 222
177 void setUp() { 223 void setUp() {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 void test_newFileWithBytes() { 537 void test_newFileWithBytes() {
492 String path = '/my/file'; 538 String path = '/my/file';
493 List<int> bytes = <int>[1, 2, 3, 4, 5]; 539 List<int> bytes = <int>[1, 2, 3, 4, 5];
494 provider.newFileWithBytes(path, bytes); 540 provider.newFileWithBytes(path, bytes);
495 File file = provider.getResource(path); 541 File file = provider.getResource(path);
496 expect(file, isNotNull); 542 expect(file, isNotNull);
497 expect(file.exists, isTrue); 543 expect(file.exists, isTrue);
498 expect(file.readAsBytesSync(), bytes); 544 expect(file.readAsBytesSync(), bytes);
499 } 545 }
500 546
501 void test_newFolder_aleadyExists_asFile() { 547 void test_newFolder_alreadyExists_asFile() {
502 provider.newFile('/my/file', 'qwerty'); 548 provider.newFile('/my/file', 'qwerty');
503 expect(() { 549 expect(() {
504 provider.newFolder('/my/file'); 550 provider.newFolder('/my/file');
505 }, throwsA(new isInstanceOf<ArgumentError>())); 551 }, throwsA(new isInstanceOf<ArgumentError>()));
506 } 552 }
507 553
508 void test_newFolder_aleadyExists_asFolder() { 554 void test_newFolder_alreadyExists_asFolder() {
509 Folder folder = provider.newFolder('/my/folder'); 555 Folder folder = provider.newFolder('/my/folder');
510 Folder newFolder = provider.newFolder('/my/folder'); 556 Folder newFolder = provider.newFolder('/my/folder');
511 expect(newFolder, folder); 557 expect(newFolder, folder);
512 } 558 }
513 559
514 void test_newFolder_emptyPath() { 560 void test_newFolder_emptyPath() {
515 expect(() { 561 expect(() {
516 provider.newFolder(''); 562 provider.newFolder('');
517 }, throwsA(new isInstanceOf<ArgumentError>())); 563 }, throwsA(new isInstanceOf<ArgumentError>()));
518 } 564 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 return new Future.delayed(Duration.ZERO, computation); 638 return new Future.delayed(Duration.ZERO, computation);
593 } 639 }
594 640
595 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) { 641 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) {
596 Folder folder = provider.getResource(path); 642 Folder folder = provider.getResource(path);
597 var changesReceived = <WatchEvent>[]; 643 var changesReceived = <WatchEvent>[];
598 folder.changes.listen(changesReceived.add); 644 folder.changes.listen(changesReceived.add);
599 return test(changesReceived); 645 return test(changesReceived);
600 } 646 }
601 } 647 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698