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

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

Issue 2733053002: Add support for copying directory structures (Closed)
Patch Set: Created 3 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'; 8 import 'dart:core';
9 9
10 import 'package:analyzer/file_system/file_system.dart'; 10 import 'package:analyzer/file_system/file_system.dart';
(...skipping 29 matching lines...) Expand all
40 expect(exception.message, 'my message'); 40 expect(exception.message, 'my message');
41 expect(exception.toString(), 41 expect(exception.toString(),
42 'FileSystemException(path=/my/path; message=my message)'); 42 'FileSystemException(path=/my/path; message=my message)');
43 } 43 }
44 } 44 }
45 45
46 @reflectiveTest 46 @reflectiveTest
47 class FileTest { 47 class FileTest {
48 MemoryResourceProvider provider = new MemoryResourceProvider(); 48 MemoryResourceProvider provider = new MemoryResourceProvider();
49 49
50 void test_copy() {
51 String contents = 'contents';
52 File file =
53 provider.newFile(provider.convertPath('/foo/file.txt'), contents);
54 Folder destination =
55 provider.getFolder(provider.convertPath('/destination'));
56
57 File copy = file.copyTo(destination);
58 expect(copy.parent, destination);
59 expect(copy.shortName, file.shortName);
60 expect(copy.readAsStringSync(), contents);
61 }
62
50 void test_delete() { 63 void test_delete() {
51 File file = 64 File file =
52 provider.newFile(provider.convertPath('/foo/file.txt'), 'content'); 65 provider.newFile(provider.convertPath('/foo/file.txt'), 'content');
53 expect(file.exists, isTrue); 66 expect(file.exists, isTrue);
54 // delete 67 // delete
55 file.delete(); 68 file.delete();
56 expect(file.exists, isFalse); 69 expect(file.exists, isFalse);
57 } 70 }
58 71
59 void test_equals_beforeAndAfterCreate() { 72 void test_equals_beforeAndAfterCreate() {
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 317 }
305 318
306 void test_contains() { 319 void test_contains() {
307 expect(folder.contains(provider.convertPath('/foo/bar/aaa.txt')), isTrue); 320 expect(folder.contains(provider.convertPath('/foo/bar/aaa.txt')), isTrue);
308 expect( 321 expect(
309 folder.contains(provider.convertPath('/foo/bar/aaa/bbb.txt')), isTrue); 322 folder.contains(provider.convertPath('/foo/bar/aaa/bbb.txt')), isTrue);
310 expect(folder.contains(provider.convertPath('/baz.txt')), isFalse); 323 expect(folder.contains(provider.convertPath('/baz.txt')), isFalse);
311 expect(folder.contains(provider.convertPath('/foo/bar')), isFalse); 324 expect(folder.contains(provider.convertPath('/foo/bar')), isFalse);
312 } 325 }
313 326
327 void test_copy() {
328 String sourcePath = provider.convertPath('/source');
329 String subdirPath = provider.convertPath('/source/subdir');
330 provider.newFolder(sourcePath);
331 provider.newFolder(subdirPath);
332 provider.newFile(provider.convertPath('/source/file1.txt'), 'file1');
333 provider.newFile(provider.convertPath('/source/subdir/file2.txt'), 'file2');
334 Folder source = provider.getFolder(sourcePath);
335 Folder destination =
336 provider.getFolder(provider.convertPath('/destination'));
337
338 Folder copy = source.copyTo(destination);
339 expect(copy.parent, destination);
340 _verifyStructure(copy, source);
341 }
342
314 void test_delete() { 343 void test_delete() {
315 Folder folder = provider.newFolder(provider.convertPath('/foo')); 344 Folder folder = provider.newFolder(provider.convertPath('/foo'));
316 Folder barFolder = provider.newFolder(provider.convertPath('/foo/bar')); 345 Folder barFolder = provider.newFolder(provider.convertPath('/foo/bar'));
317 File aFile = provider.newFile(provider.convertPath('/foo/bar/a.txt'), ''); 346 File aFile = provider.newFile(provider.convertPath('/foo/bar/a.txt'), '');
318 File bFile = provider.newFile(provider.convertPath('/foo/b.txt'), ''); 347 File bFile = provider.newFile(provider.convertPath('/foo/b.txt'), '');
319 expect(folder.exists, isTrue); 348 expect(folder.exists, isTrue);
320 expect(barFolder.exists, isTrue); 349 expect(barFolder.exists, isTrue);
321 expect(aFile.exists, isTrue); 350 expect(aFile.exists, isTrue);
322 expect(bFile.exists, isTrue); 351 expect(bFile.exists, isTrue);
323 // delete 'folder' 352 // delete 'folder'
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 expect(parent2, new isInstanceOf<Folder>()); 479 expect(parent2, new isInstanceOf<Folder>());
451 expect(parent2.path, equals(provider.convertPath('/'))); 480 expect(parent2.path, equals(provider.convertPath('/')));
452 expect(parent2.parent, isNull); 481 expect(parent2.parent, isNull);
453 } 482 }
454 483
455 void test_toUri() { 484 void test_toUri() {
456 String path = provider.convertPath('/foo/directory'); 485 String path = provider.convertPath('/foo/directory');
457 Folder folder = provider.newFolder(path); 486 Folder folder = provider.newFolder(path);
458 expect(folder.toUri(), provider.pathContext.toUri(path)); 487 expect(folder.toUri(), provider.pathContext.toUri(path));
459 } 488 }
489
490 /**
491 * Verify that the [copy] has the same name and content as the [source].
492 */
493 void _verifyStructure(Folder copy, Folder source) {
494 expect(copy.shortName, source.shortName);
495 Map<String, File> sourceFiles = <String, File>{};
496 Map<String, Folder> sourceFolders = <String, Folder>{};
497 for (Resource child in source.getChildren()) {
498 if (child is File) {
499 sourceFiles[child.shortName] = child;
500 } else if (child is Folder) {
501 sourceFolders[child.shortName] = child;
502 } else {
503 fail('Unknown class of resource: ${child.runtimeType}');
504 }
505 }
506 Map<String, File> copyFiles = <String, File>{};
507 Map<String, Folder> copyFolders = <String, Folder>{};
508 for (Resource child in source.getChildren()) {
509 if (child is File) {
510 copyFiles[child.shortName] = child;
511 } else if (child is Folder) {
512 copyFolders[child.shortName] = child;
513 } else {
514 fail('Unknown class of resource: ${child.runtimeType}');
515 }
516 }
517 for (String fileName in sourceFiles.keys) {
518 File sourceChild = sourceFiles[fileName];
519 File copiedChild = copyFiles[fileName];
520 if (copiedChild == null) {
521 fail('Failed to copy file ${sourceChild.path}');
522 }
523 expect(copiedChild.readAsStringSync(), sourceChild.readAsStringSync(),
524 reason: 'Incorrectly copied file ${sourceChild.path}');
525 }
526 for (String fileName in sourceFolders.keys) {
527 Folder sourceChild = sourceFolders[fileName];
528 Folder copiedChild = copyFolders[fileName];
529 if (copiedChild == null) {
530 fail('Failed to copy folder ${sourceChild.path}');
531 }
532 _verifyStructure(copiedChild, sourceChild);
533 }
534 }
460 } 535 }
461 536
462 @reflectiveTest 537 @reflectiveTest
463 class MemoryFileSourceExistingTest { 538 class MemoryFileSourceExistingTest {
464 MemoryResourceProvider provider = new MemoryResourceProvider(); 539 MemoryResourceProvider provider = new MemoryResourceProvider();
465 String path; 540 String path;
466 Source source; 541 Source source;
467 542
468 setUp() { 543 setUp() {
469 path = provider.convertPath('/foo/test.dart'); 544 path = provider.convertPath('/foo/test.dart');
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 return new Future.delayed(Duration.ZERO, computation); 875 return new Future.delayed(Duration.ZERO, computation);
801 } 876 }
802 877
803 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) { 878 _watchingFolder(String path, test(List<WatchEvent> changesReceived)) {
804 Folder folder = provider.getResource(path); 879 Folder folder = provider.getResource(path);
805 var changesReceived = <WatchEvent>[]; 880 var changesReceived = <WatchEvent>[];
806 folder.changes.listen(changesReceived.add); 881 folder.changes.listen(changesReceived.add);
807 return test(changesReceived); 882 return test(changesReceived);
808 } 883 }
809 } 884 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698