| OLD | NEW |
| 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'; | 8 import 'dart:core'; |
| 9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 class FileTest extends _BaseTest { | 37 class FileTest extends _BaseTest { |
| 38 String path; | 38 String path; |
| 39 File file; | 39 File file; |
| 40 | 40 |
| 41 setUp() { | 41 setUp() { |
| 42 super.setUp(); | 42 super.setUp(); |
| 43 path = join(tempPath, 'file.txt'); | 43 path = join(tempPath, 'file.txt'); |
| 44 file = PhysicalResourceProvider.INSTANCE.getResource(path); | 44 file = PhysicalResourceProvider.INSTANCE.getResource(path); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void test_copy() { |
| 48 PhysicalResourceProvider provider = PhysicalResourceProvider.INSTANCE; |
| 49 String contents = 'contents'; |
| 50 new io.File(path).writeAsStringSync(contents); |
| 51 Folder destination = provider.getFolder(join(tempPath, 'destination')); |
| 52 |
| 53 File copy = file.copyTo(destination); |
| 54 expect(copy.parent, destination); |
| 55 expect(copy.shortName, file.shortName); |
| 56 expect(copy.readAsStringSync(), contents); |
| 57 } |
| 58 |
| 47 void test_createSource() { | 59 void test_createSource() { |
| 48 new io.File(path).writeAsStringSync('contents'); | 60 new io.File(path).writeAsStringSync('contents'); |
| 49 Source source = file.createSource(); | 61 Source source = file.createSource(); |
| 50 expect(source.uriKind, UriKind.FILE_URI); | 62 expect(source.uriKind, UriKind.FILE_URI); |
| 51 expect(source.exists(), isTrue); | 63 expect(source.exists(), isTrue); |
| 52 expect(source.contents.data, 'contents'); | 64 expect(source.contents.data, 'contents'); |
| 53 } | 65 } |
| 54 | 66 |
| 55 void test_delete() { | 67 void test_delete() { |
| 56 new io.File(path).writeAsStringSync('contents'); | 68 new io.File(path).writeAsStringSync('contents'); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 equals(join(path2, 'baz'))); | 305 equals(join(path2, 'baz'))); |
| 294 } | 306 } |
| 295 | 307 |
| 296 void test_contains() { | 308 void test_contains() { |
| 297 expect(folder.contains(join(path, 'aaa.txt')), isTrue); | 309 expect(folder.contains(join(path, 'aaa.txt')), isTrue); |
| 298 expect(folder.contains(join(path, 'aaa', 'bbb.txt')), isTrue); | 310 expect(folder.contains(join(path, 'aaa', 'bbb.txt')), isTrue); |
| 299 expect(folder.contains(join(tempPath, 'baz.txt')), isFalse); | 311 expect(folder.contains(join(tempPath, 'baz.txt')), isFalse); |
| 300 expect(folder.contains(path), isFalse); | 312 expect(folder.contains(path), isFalse); |
| 301 } | 313 } |
| 302 | 314 |
| 315 void test_copy() { |
| 316 PhysicalResourceProvider provider = PhysicalResourceProvider.INSTANCE; |
| 317 String sourcePath = join(tempPath, 'source'); |
| 318 String subdirPath = join(sourcePath, 'subdir'); |
| 319 new io.Directory(sourcePath).createSync(); |
| 320 new io.Directory(subdirPath).createSync(); |
| 321 new io.File(join(sourcePath, 'file1.txt')).writeAsStringSync('file1'); |
| 322 new io.File(join(subdirPath, 'file2.txt')).writeAsStringSync('file2'); |
| 323 Folder source = provider.getFolder(sourcePath); |
| 324 Folder destination = provider.getFolder(join(tempPath, 'destination')); |
| 325 |
| 326 Folder copy = source.copyTo(destination); |
| 327 expect(copy.parent, destination); |
| 328 _verifyStructure(copy, source); |
| 329 } |
| 330 |
| 303 void test_delete() { | 331 void test_delete() { |
| 304 new io.File(join(path, 'myFile')).createSync(); | 332 new io.File(join(path, 'myFile')).createSync(); |
| 305 var child = folder.getChild('myFile'); | 333 var child = folder.getChild('myFile'); |
| 306 expect(child, _isFile); | 334 expect(child, _isFile); |
| 307 expect(child.exists, isTrue); | 335 expect(child.exists, isTrue); |
| 308 // delete "folder" | 336 // delete "folder" |
| 309 folder.delete(); | 337 folder.delete(); |
| 310 expect(child.exists, isFalse); | 338 expect(child.exists, isFalse); |
| 311 } | 339 } |
| 312 | 340 |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 expect(grandParent.path.length, lessThan(parent.path.length)); | 470 expect(grandParent.path.length, lessThan(parent.path.length)); |
| 443 parent = grandParent; | 471 parent = grandParent; |
| 444 } | 472 } |
| 445 } | 473 } |
| 446 | 474 |
| 447 void test_toUri() { | 475 void test_toUri() { |
| 448 String path = '/foo/directory'; | 476 String path = '/foo/directory'; |
| 449 Folder folder = PhysicalResourceProvider.INSTANCE.getFolder(path); | 477 Folder folder = PhysicalResourceProvider.INSTANCE.getFolder(path); |
| 450 expect(folder.toUri(), new Uri.directory(path)); | 478 expect(folder.toUri(), new Uri.directory(path)); |
| 451 } | 479 } |
| 480 |
| 481 /** |
| 482 * Verify that the [copy] has the same name and content as the [source]. |
| 483 */ |
| 484 void _verifyStructure(Folder copy, Folder source) { |
| 485 expect(copy.shortName, source.shortName); |
| 486 Map<String, File> sourceFiles = <String, File>{}; |
| 487 Map<String, Folder> sourceFolders = <String, Folder>{}; |
| 488 for (Resource child in source.getChildren()) { |
| 489 if (child is File) { |
| 490 sourceFiles[child.shortName] = child; |
| 491 } else if (child is Folder) { |
| 492 sourceFolders[child.shortName] = child; |
| 493 } else { |
| 494 fail('Unknown class of resource: ${child.runtimeType}'); |
| 495 } |
| 496 } |
| 497 Map<String, File> copyFiles = <String, File>{}; |
| 498 Map<String, Folder> copyFolders = <String, Folder>{}; |
| 499 for (Resource child in source.getChildren()) { |
| 500 if (child is File) { |
| 501 copyFiles[child.shortName] = child; |
| 502 } else if (child is Folder) { |
| 503 copyFolders[child.shortName] = child; |
| 504 } else { |
| 505 fail('Unknown class of resource: ${child.runtimeType}'); |
| 506 } |
| 507 } |
| 508 for (String fileName in sourceFiles.keys) { |
| 509 File sourceChild = sourceFiles[fileName]; |
| 510 File copiedChild = copyFiles[fileName]; |
| 511 if (copiedChild == null) { |
| 512 fail('Failed to copy file ${sourceChild.path}'); |
| 513 } |
| 514 expect(copiedChild.readAsStringSync(), sourceChild.readAsStringSync(), |
| 515 reason: 'Incorrectly copied file ${sourceChild.path}'); |
| 516 } |
| 517 for (String fileName in sourceFolders.keys) { |
| 518 Folder sourceChild = sourceFolders[fileName]; |
| 519 Folder copiedChild = copyFolders[fileName]; |
| 520 if (copiedChild == null) { |
| 521 fail('Failed to copy folder ${sourceChild.path}'); |
| 522 } |
| 523 _verifyStructure(copiedChild, sourceChild); |
| 524 } |
| 525 } |
| 452 } | 526 } |
| 453 | 527 |
| 454 @reflectiveTest | 528 @reflectiveTest |
| 455 class PhysicalResourceProviderTest extends _BaseTest { | 529 class PhysicalResourceProviderTest extends _BaseTest { |
| 456 test_getFolder_trailingSeparator() { | 530 test_getFolder_trailingSeparator() { |
| 457 String path = tempPath; | 531 String path = tempPath; |
| 458 PhysicalResourceProvider provider = PhysicalResourceProvider.INSTANCE; | 532 PhysicalResourceProvider provider = PhysicalResourceProvider.INSTANCE; |
| 459 Folder folder = provider.getFolder('$path${pathos.separator}'); | 533 Folder folder = provider.getFolder('$path${pathos.separator}'); |
| 460 expect(folder.path, path); | 534 expect(folder.path, path); |
| 461 } | 535 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 710 |
| 637 setUp() { | 711 setUp() { |
| 638 tempDirectory = io.Directory.systemTemp.createTempSync('test_resource'); | 712 tempDirectory = io.Directory.systemTemp.createTempSync('test_resource'); |
| 639 tempPath = tempDirectory.absolute.path; | 713 tempPath = tempDirectory.absolute.path; |
| 640 } | 714 } |
| 641 | 715 |
| 642 tearDown() { | 716 tearDown() { |
| 643 tempDirectory.deleteSync(recursive: true); | 717 tempDirectory.deleteSync(recursive: true); |
| 644 } | 718 } |
| 645 } | 719 } |
| OLD | NEW |