| 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 457afe3844d430d061373c3062c7462691f48e65..cc0ad1604e52737bf9002903da46d79fbd9aa87e 100644
|
| --- a/pkg/analyzer/test/file_system/memory_file_system_test.dart
|
| +++ b/pkg/analyzer/test/file_system/memory_file_system_test.dart
|
| @@ -14,550 +14,536 @@ import 'package:path/path.dart';
|
| import 'package:unittest/unittest.dart';
|
| import 'package:watcher/watcher.dart';
|
|
|
| -var _isFile = new isInstanceOf<File>();
|
| -var _isFileSystemException = new isInstanceOf<FileSystemException>();
|
| -var _isFolder = new isInstanceOf<Folder>();
|
| +import '../reflective_tests.dart';
|
|
|
| main() {
|
| groupSep = ' | ';
|
| + runReflectiveTests(FileSystemExceptionTest);
|
| + runReflectiveTests(FileTest);
|
| + runReflectiveTests(FolderTest);
|
| + runReflectiveTests(MemoryFileSourceExistingTest);
|
| + runReflectiveTests(MemoryFileSourceNotExistingTest);
|
| + runReflectiveTests(MemoryResourceProviderTest);
|
| +}
|
|
|
| - group('MemoryResourceProvider', () {
|
| - MemoryResourceProvider provider;
|
| -
|
| - setUp(() {
|
| - provider = new MemoryResourceProvider();
|
| - });
|
| -
|
| - test('FileSystemException', () {
|
| - var exception = new FileSystemException('/my/path', 'my message');
|
| - expect(exception.path, '/my/path');
|
| - expect(exception.message, 'my message');
|
| - expect(exception.toString(),
|
| - 'FileSystemException(path=/my/path; message=my message)');
|
| - });
|
| -
|
| - group('Watch', () {
|
| - Future delayed(computation()) {
|
| - return new Future.delayed(Duration.ZERO, computation);
|
| - }
|
| -
|
| - watchingFolder(String path, test(List<WatchEvent> changesReceived)) {
|
| - Folder folder = provider.getResource(path);
|
| - var changesReceived = <WatchEvent>[];
|
| - folder.changes.listen(changesReceived.add);
|
| - return test(changesReceived);
|
| - }
|
| -
|
| - test('create file', () {
|
| - String rootPath = '/my/path';
|
| - provider.newFolder(rootPath);
|
| - watchingFolder(rootPath, (changesReceived) {
|
| - expect(changesReceived, hasLength(0));
|
| - String path = posix.join(rootPath, 'foo');
|
| - provider.newFile(path, 'contents');
|
| - return delayed(() {
|
| - expect(changesReceived, hasLength(1));
|
| - expect(changesReceived[0].type, equals(ChangeType.ADD));
|
| - expect(changesReceived[0].path, equals(path));
|
| - });
|
| - });
|
| - });
|
| -
|
| - test('modify file', () {
|
| - String rootPath = '/my/path';
|
| - provider.newFolder(rootPath);
|
| - String path = posix.join(rootPath, 'foo');
|
| - provider.newFile(path, 'contents 1');
|
| - return watchingFolder(rootPath, (changesReceived) {
|
| - expect(changesReceived, hasLength(0));
|
| - provider.modifyFile(path, 'contents 2');
|
| - return delayed(() {
|
| - expect(changesReceived, hasLength(1));
|
| - expect(changesReceived[0].type, equals(ChangeType.MODIFY));
|
| - expect(changesReceived[0].path, equals(path));
|
| - });
|
| - });
|
| - });
|
| -
|
| - test('modify file in subdir', () {
|
| - String rootPath = '/my/path';
|
| - provider.newFolder(rootPath);
|
| - String subdirPath = posix.join(rootPath, 'foo');
|
| - provider.newFolder(subdirPath);
|
| - String path = posix.join(rootPath, 'bar');
|
| - provider.newFile(path, 'contents 1');
|
| - return watchingFolder(rootPath, (changesReceived) {
|
| - expect(changesReceived, hasLength(0));
|
| - provider.modifyFile(path, 'contents 2');
|
| - return delayed(() {
|
| - expect(changesReceived, hasLength(1));
|
| - expect(changesReceived[0].type, equals(ChangeType.MODIFY));
|
| - expect(changesReceived[0].path, equals(path));
|
| - });
|
| - });
|
| - });
|
| -
|
| - test('delete file', () {
|
| - String rootPath = '/my/path';
|
| - provider.newFolder(rootPath);
|
| - String path = posix.join(rootPath, 'foo');
|
| - provider.newFile(path, 'contents 1');
|
| - return watchingFolder(rootPath, (changesReceived) {
|
| - expect(changesReceived, hasLength(0));
|
| - provider.deleteFile(path);
|
| - return delayed(() {
|
| - expect(changesReceived, hasLength(1));
|
| - expect(changesReceived[0].type, equals(ChangeType.REMOVE));
|
| - expect(changesReceived[0].path, equals(path));
|
| - });
|
| - });
|
| - });
|
| - });
|
| -
|
| - group('getStateLocation', () {
|
| - test('uniqueness', () {
|
| - String idOne = 'one';
|
| - Folder folderOne = provider.getStateLocation(idOne);
|
| - expect(folderOne, isNotNull);
|
| - String idTwo = 'two';
|
| - Folder folderTwo = provider.getStateLocation(idTwo);
|
| - expect(folderTwo, isNotNull);
|
| - expect(folderTwo, isNot(equals(folderOne)));
|
| - expect(provider.getStateLocation(idOne), equals(folderOne));
|
| - });
|
| - });
|
| -
|
| - group('newFolder', () {
|
| - test('empty path', () {
|
| - expect(() {
|
| - provider.newFolder('');
|
| - }, throwsA(new isInstanceOf<ArgumentError>()));
|
| - });
|
| -
|
| - test('not absolute', () {
|
| - expect(() {
|
| - provider.newFolder('not/absolute');
|
| - }, throwsA(new isInstanceOf<ArgumentError>()));
|
| - });
|
| -
|
| - group('already exists', () {
|
| - test('as folder', () {
|
| - Folder folder = provider.newFolder('/my/folder');
|
| - Folder newFolder = provider.newFolder('/my/folder');
|
| - expect(newFolder, folder);
|
| - });
|
| -
|
| - test('as file', () {
|
| - provider.newFile('/my/file', 'qwerty');
|
| - expect(() {
|
| - provider.newFolder('/my/file');
|
| - }, throwsA(new isInstanceOf<ArgumentError>()));
|
| - });
|
| - });
|
| - });
|
| +var _isFile = new isInstanceOf<File>();
|
| +var _isFileSystemException = new isInstanceOf<FileSystemException>();
|
| +var _isFolder = new isInstanceOf<Folder>();
|
|
|
| - group('modifyFile', () {
|
| - test('nonexistent', () {
|
| - String path = '/my/file';
|
| - expect(() {
|
| - provider.modifyFile(path, 'contents');
|
| - }, throwsA(new isInstanceOf<ArgumentError>()));
|
| - Resource file = provider.getResource(path);
|
| - expect(file, isNotNull);
|
| - expect(file.exists, isFalse);
|
| - });
|
| +@reflectiveTest
|
| +class FileSystemExceptionTest {
|
| + void test_constructor() {
|
| + var exception = new FileSystemException('/my/path', 'my message');
|
| + expect(exception.path, '/my/path');
|
| + expect(exception.message, 'my message');
|
| + expect(exception.toString(),
|
| + 'FileSystemException(path=/my/path; message=my message)');
|
| + }
|
| +}
|
|
|
| - test('is folder', () {
|
| - String path = '/my/file';
|
| - provider.newFolder(path);
|
| - expect(() {
|
| - provider.modifyFile(path, 'contents');
|
| - }, throwsA(new isInstanceOf<ArgumentError>()));
|
| - expect(provider.getResource(path), new isInstanceOf<Folder>());
|
| - });
|
| +@reflectiveTest
|
| +class FileTest {
|
| + MemoryResourceProvider provider = new MemoryResourceProvider();
|
| +
|
| + void test_equals_beforeAndAfterCreate() {
|
| + String path = '/file.txt';
|
| + File file1 = provider.getResource(path);
|
| + provider.newFile(path, 'contents');
|
| + File file2 = provider.getResource(path);
|
| + expect(file1 == file2, isTrue);
|
| + }
|
| +
|
| + void test_equals_false() {
|
| + File fileA = provider.getResource('/fileA.txt');
|
| + File fileB = provider.getResource('/fileB.txt');
|
| + expect(fileA == new Object(), isFalse);
|
| + expect(fileA == fileB, isFalse);
|
| + }
|
| +
|
| + void test_equals_true() {
|
| + File file = provider.getResource('/file.txt');
|
| + expect(file == file, isTrue);
|
| + }
|
| +
|
| + void test_exists_false() {
|
| + File file = provider.getResource('/file.txt');
|
| + expect(file, isNotNull);
|
| + expect(file.exists, isFalse);
|
| + }
|
| +
|
| + void test_exists_true() {
|
| + provider.newFile('/foo/file.txt', 'qwerty');
|
| + File file = provider.getResource('/foo/file.txt');
|
| + expect(file, isNotNull);
|
| + expect(file.exists, isTrue);
|
| + }
|
| +
|
| + void test_fullName() {
|
| + File file = provider.getResource('/foo/bar/file.txt');
|
| + expect(file.path, '/foo/bar/file.txt');
|
| + }
|
| +
|
| + void test_hashCode() {
|
| + String path = '/foo/bar/file.txt';
|
| + File file1 = provider.getResource(path);
|
| + provider.newFile(path, 'contents');
|
| + File file2 = provider.getResource(path);
|
| + expect(file1.hashCode, equals(file2.hashCode));
|
| + }
|
| +
|
| + void test_isOrContains() {
|
| + String path = '/foo/bar/file.txt';
|
| + File file = provider.getResource(path);
|
| + expect(file.isOrContains(path), isTrue);
|
| + expect(file.isOrContains('/foo/bar'), isFalse);
|
| + }
|
| +
|
| + void test_modificationStamp_doesNotExist() {
|
| + String path = '/foo/bar/file.txt';
|
| + File file = provider.newFile(path, 'qwerty');
|
| + provider.deleteFile(path);
|
| + expect(() {
|
| + file.modificationStamp;
|
| + }, throwsA(_isFileSystemException));
|
| + }
|
| +
|
| + void test_modificationStamp_exists() {
|
| + String path = '/foo/bar/file.txt';
|
| + File file = provider.newFile(path, 'qwerty');
|
| + expect(file.modificationStamp, isNonNegative);
|
| + }
|
| +
|
| + void test_parent() {
|
| + provider.newFile('/foo/bar/file.txt', 'content');
|
| + File file = provider.getResource('/foo/bar/file.txt');
|
| + Resource parent = file.parent;
|
| + expect(parent, new isInstanceOf<Folder>());
|
| + expect(parent.path, equals('/foo/bar'));
|
| + }
|
| +
|
| + void test_shortName() {
|
| + File file = provider.getResource('/foo/bar/file.txt');
|
| + expect(file.shortName, 'file.txt');
|
| + }
|
| +
|
| + void test_toString() {
|
| + File file = provider.getResource('/foo/bar/file.txt');
|
| + expect(file.toString(), '/foo/bar/file.txt');
|
| + }
|
| +}
|
|
|
| - test('successful', () {
|
| - String path = '/my/file';
|
| - provider.newFile(path, 'contents 1');
|
| - Resource file = provider.getResource(path);
|
| - expect(file, new isInstanceOf<File>());
|
| - Source source = (file as File).createSource();
|
| - expect(source.contents.data, equals('contents 1'));
|
| - provider.modifyFile(path, 'contents 2');
|
| - expect(source.contents.data, equals('contents 2'));
|
| - });
|
| +@reflectiveTest
|
| +class FolderTest {
|
| + static const String path = '/foo/bar';
|
| +
|
| + MemoryResourceProvider provider = new MemoryResourceProvider();
|
| + Folder folder;
|
| +
|
| + void setUp() {
|
| + folder = provider.newFolder(path);
|
| + }
|
| +
|
| + void test_canonicalizePath() {
|
| + expect(folder.canonicalizePath('baz'), equals('/foo/bar/baz'));
|
| + expect(folder.canonicalizePath('/baz'), equals('/baz'));
|
| + expect(folder.canonicalizePath('../baz'), equals('/foo/baz'));
|
| + expect(folder.canonicalizePath('/a/b/../c'), equals('/a/c'));
|
| + expect(folder.canonicalizePath('./baz'), equals('/foo/bar/baz'));
|
| + expect(folder.canonicalizePath('/a/b/./c'), equals('/a/b/c'));
|
| + }
|
| +
|
| + void test_contains() {
|
| + expect(folder.contains('/foo/bar/aaa.txt'), isTrue);
|
| + expect(folder.contains('/foo/bar/aaa/bbb.txt'), isTrue);
|
| + expect(folder.contains('/baz.txt'), isFalse);
|
| + expect(folder.contains('/foo/bar'), isFalse);
|
| + }
|
| +
|
| + void test_equal_false() {
|
| + String path2 = '/foo/baz';
|
| + Folder folder2 = provider.newFolder(path2);
|
| + expect(folder == folder2, isFalse);
|
| + }
|
| +
|
| + void test_equal_true() {
|
| + Folder folder2 = provider.getResource(path);
|
| + expect(folder == folder2, isTrue);
|
| + }
|
| +
|
| + void test_getChild_doesNotExist() {
|
| + File file = folder.getChild('file.txt');
|
| + expect(file, isNotNull);
|
| + expect(file.exists, isFalse);
|
| + }
|
| +
|
| + void test_getChild_file() {
|
| + provider.newFile('/foo/bar/file.txt', 'content');
|
| + File child = folder.getChild('file.txt');
|
| + expect(child, isNotNull);
|
| + expect(child.exists, isTrue);
|
| + }
|
| +
|
| + void test_getChild_folder() {
|
| + provider.newFolder('/foo/bar/baz');
|
| + Folder child = folder.getChild('baz');
|
| + expect(child, isNotNull);
|
| + expect(child.exists, isTrue);
|
| + }
|
| +
|
| + void test_getChildAssumingFolder_doesNotExist() {
|
| + Folder child = folder.getChildAssumingFolder('foldername');
|
| + expect(child, isNotNull);
|
| + expect(child.exists, isFalse);
|
| + }
|
| +
|
| + void test_getChildAssumingFolder_file() {
|
| + provider.newFile('/foo/bar/foldername', 'content');
|
| + Folder child = folder.getChildAssumingFolder('foldername');
|
| + expect(child, isNotNull);
|
| + expect(child.exists, isFalse);
|
| + }
|
| +
|
| + void test_getChildAssumingFolder_folder() {
|
| + provider.newFolder('/foo/bar/foldername');
|
| + Folder child = folder.getChildAssumingFolder('foldername');
|
| + expect(child, isNotNull);
|
| + expect(child.exists, isTrue);
|
| + }
|
| +
|
| + void test_getChildren_doesNotExist() {
|
| + folder = folder.getChildAssumingFolder('no-such-folder');
|
| + expect(() {
|
| + folder.getChildren();
|
| + }, throwsA(_isFileSystemException));
|
| + }
|
| +
|
| + void test_getChildren_exists() {
|
| + provider.newFile('/foo/bar/a.txt', 'aaa');
|
| + provider.newFolder('/foo/bar/bFolder');
|
| + provider.newFile('/foo/bar/c.txt', 'ccc');
|
| + // prepare 3 children
|
| + List<Resource> children = folder.getChildren();
|
| + expect(children, hasLength(3));
|
| + children.sort((a, b) => a.shortName.compareTo(b.shortName));
|
| + // check that each child exists
|
| + children.forEach((child) {
|
| + expect(child.exists, true);
|
| });
|
| + // check names
|
| + expect(children[0].shortName, 'a.txt');
|
| + expect(children[1].shortName, 'bFolder');
|
| + expect(children[2].shortName, 'c.txt');
|
| + // check types
|
| + expect(children[0], _isFile);
|
| + expect(children[1], _isFolder);
|
| + expect(children[2], _isFile);
|
| + }
|
| +
|
| + void test_hashCode() {
|
| + Folder folder2 = provider.getResource(path);
|
| + expect(folder.hashCode, folder2.hashCode);
|
| + }
|
| +
|
| + void test_isOrContains() {
|
| + expect(folder.isOrContains('/foo/bar'), isTrue);
|
| + expect(folder.isOrContains('/foo/bar/aaa.txt'), isTrue);
|
| + expect(folder.isOrContains('/foo/bar/aaa/bbb.txt'), isTrue);
|
| + expect(folder.isOrContains('/baz.txt'), isFalse);
|
| + }
|
| +
|
| + void test_parent() {
|
| + Resource parent1 = folder.parent;
|
| + expect(parent1, new isInstanceOf<Folder>());
|
| + expect(parent1.path, equals('/foo'));
|
| + Resource parent2 = parent1.parent;
|
| + expect(parent2, new isInstanceOf<Folder>());
|
| + expect(parent2.path, equals('/'));
|
| + expect(parent2.parent, isNull);
|
| + }
|
| +}
|
|
|
| - group('deleteFile', () {
|
| - test('nonexistent', () {
|
| - String path = '/my/file';
|
| - expect(() {
|
| - provider.deleteFile(path);
|
| - }, throwsA(new isInstanceOf<ArgumentError>()));
|
| - Resource file = provider.getResource(path);
|
| - expect(file, isNotNull);
|
| - expect(file.exists, isFalse);
|
| - });
|
| +@reflectiveTest
|
| +class MemoryFileSourceExistingTest {
|
| + MemoryResourceProvider provider = new MemoryResourceProvider();
|
| + Source source;
|
| +
|
| + setUp() {
|
| + File file = provider.newFile('/foo/test.dart', 'library test;');
|
| + source = file.createSource();
|
| + }
|
| +
|
| + void test_contents() {
|
| + TimestampedData<String> contents = source.contents;
|
| + expect(contents.data, 'library test;');
|
| + }
|
| +
|
| + void test_encoding() {
|
| + expect(source.encoding, 'file:///foo/test.dart');
|
| + }
|
| +
|
| + void test_equals_false_differentFile() {
|
| + File fileA = provider.newFile('/foo/a.dart', '');
|
| + File fileB = provider.newFile('/foo/b.dart', '');
|
| + Source sourceA = fileA.createSource();
|
| + Source sourceB = fileB.createSource();
|
| + expect(sourceA == sourceB, isFalse);
|
| + }
|
| +
|
| + void test_equals_false_notMemorySource() {
|
| + File file = provider.newFile('/foo/test.dart', '');
|
| + Source source = file.createSource();
|
| + expect(source == new Object(), isFalse);
|
| + }
|
| +
|
| + void test_equals_true_sameFile() {
|
| + File file = provider.newFile('/foo/test.dart', '');
|
| + Source sourceA = file.createSource();
|
| + Source sourceB = file.createSource();
|
| + expect(sourceA == sourceB, isTrue);
|
| + }
|
| +
|
| + void test_equals_true_self() {
|
| + File file = provider.newFile('/foo/test.dart', '');
|
| + Source source = file.createSource();
|
| + expect(source == source, isTrue);
|
| + }
|
| +
|
| + void test_exists() {
|
| + expect(source.exists(), isTrue);
|
| + }
|
| +
|
| + void test_fullName() {
|
| + expect(source.fullName, '/foo/test.dart');
|
| + }
|
| +
|
| + void test_hashCode() {
|
| + source.hashCode;
|
| + }
|
| +
|
| + void test_resolveRelative() {
|
| + Uri relative = source.resolveRelativeUri(new Uri.file('bar/baz.dart'));
|
| + expect(relative.path, '/foo/bar/baz.dart');
|
| + }
|
| +
|
| + void test_shortName() {
|
| + expect(source.shortName, 'test.dart');
|
| + }
|
| +}
|
|
|
| - test('is folder', () {
|
| - String path = '/my/file';
|
| - provider.newFolder(path);
|
| - expect(() {
|
| - provider.deleteFile(path);
|
| - }, throwsA(new isInstanceOf<ArgumentError>()));
|
| - expect(provider.getResource(path), new isInstanceOf<Folder>());
|
| - });
|
| +@reflectiveTest
|
| +class MemoryFileSourceNotExistingTest {
|
| + MemoryResourceProvider provider = new MemoryResourceProvider();
|
| + Source source;
|
| +
|
| + setUp() {
|
| + File file = provider.getResource('/foo/test.dart');
|
| + source = file.createSource();
|
| + }
|
| +
|
| + void test_contents() {
|
| + expect(() {
|
| + source.contents;
|
| + }, throwsA(_isFileSystemException));
|
| + }
|
| +
|
| + void test_encoding() {
|
| + expect(source.encoding, 'file:///foo/test.dart');
|
| + }
|
| +
|
| + void test_exists() {
|
| + expect(source.exists(), isFalse);
|
| + }
|
| +
|
| + void test_fullName() {
|
| + expect(source.fullName, '/foo/test.dart');
|
| + }
|
| +
|
| + void test_modificationStamp() {
|
| + expect(source.modificationStamp, -1);
|
| + }
|
| +
|
| + void test_resolveRelative() {
|
| + Uri relative = source.resolveRelativeUri(new Uri.file('bar/baz.dart'));
|
| + expect(relative.path, '/foo/bar/baz.dart');
|
| + }
|
| +
|
| + void test_shortName() {
|
| + expect(source.shortName, 'test.dart');
|
| + }
|
| +}
|
|
|
| - test('successful', () {
|
| - String path = '/my/file';
|
| - provider.newFile(path, 'contents');
|
| - Resource file = provider.getResource(path);
|
| - expect(file, new isInstanceOf<File>());
|
| - expect(file.exists, isTrue);
|
| - provider.deleteFile(path);
|
| - expect(file.exists, isFalse);
|
| +@reflectiveTest
|
| +class MemoryResourceProviderTest {
|
| + MemoryResourceProvider provider = new MemoryResourceProvider();
|
| +
|
| + void test_deleteFile_folder() {
|
| + String path = '/my/file';
|
| + provider.newFolder(path);
|
| + expect(() {
|
| + provider.deleteFile(path);
|
| + }, throwsA(new isInstanceOf<ArgumentError>()));
|
| + expect(provider.getResource(path), new isInstanceOf<Folder>());
|
| + }
|
| +
|
| + void test_deleteFile_notExistent() {
|
| + String path = '/my/file';
|
| + expect(() {
|
| + provider.deleteFile(path);
|
| + }, throwsA(new isInstanceOf<ArgumentError>()));
|
| + Resource file = provider.getResource(path);
|
| + expect(file, isNotNull);
|
| + expect(file.exists, isFalse);
|
| + }
|
| +
|
| + void test_deleteFile_success() {
|
| + String path = '/my/file';
|
| + provider.newFile(path, 'contents');
|
| + Resource file = provider.getResource(path);
|
| + expect(file, new isInstanceOf<File>());
|
| + expect(file.exists, isTrue);
|
| + provider.deleteFile(path);
|
| + expect(file.exists, isFalse);
|
| + }
|
| +
|
| + void test_getStateLocation_uniqueness() {
|
| + String idOne = 'one';
|
| + Folder folderOne = provider.getStateLocation(idOne);
|
| + expect(folderOne, isNotNull);
|
| + String idTwo = 'two';
|
| + Folder folderTwo = provider.getStateLocation(idTwo);
|
| + expect(folderTwo, isNotNull);
|
| + expect(folderTwo, isNot(equals(folderOne)));
|
| + expect(provider.getStateLocation(idOne), equals(folderOne));
|
| + }
|
| +
|
| + void test_modifyFile_isFolder() {
|
| + String path = '/my/file';
|
| + provider.newFolder(path);
|
| + expect(() {
|
| + provider.modifyFile(path, 'contents');
|
| + }, throwsA(new isInstanceOf<ArgumentError>()));
|
| + expect(provider.getResource(path), new isInstanceOf<Folder>());
|
| + }
|
| +
|
| + void test_modifyFile_notExistent() {
|
| + String path = '/my/file';
|
| + expect(() {
|
| + provider.modifyFile(path, 'contents');
|
| + }, throwsA(new isInstanceOf<ArgumentError>()));
|
| + Resource file = provider.getResource(path);
|
| + expect(file, isNotNull);
|
| + expect(file.exists, isFalse);
|
| + }
|
| +
|
| + void test_modifyFile_success() {
|
| + String path = '/my/file';
|
| + provider.newFile(path, 'contents 1');
|
| + Resource file = provider.getResource(path);
|
| + expect(file, new isInstanceOf<File>());
|
| + Source source = (file as File).createSource();
|
| + expect(source.contents.data, equals('contents 1'));
|
| + provider.modifyFile(path, 'contents 2');
|
| + expect(source.contents.data, equals('contents 2'));
|
| + }
|
| +
|
| + void test_newFolder_aleadyExists_asFile() {
|
| + provider.newFile('/my/file', 'qwerty');
|
| + expect(() {
|
| + provider.newFolder('/my/file');
|
| + }, throwsA(new isInstanceOf<ArgumentError>()));
|
| + }
|
| +
|
| + void test_newFolder_aleadyExists_asFolder() {
|
| + Folder folder = provider.newFolder('/my/folder');
|
| + Folder newFolder = provider.newFolder('/my/folder');
|
| + expect(newFolder, folder);
|
| + }
|
| +
|
| + void test_newFolder_emptyPath() {
|
| + expect(() {
|
| + provider.newFolder('');
|
| + }, throwsA(new isInstanceOf<ArgumentError>()));
|
| + }
|
| +
|
| + void test_newFolder_notAbsolute() {
|
| + expect(() {
|
| + provider.newFolder('not/absolute');
|
| + }, throwsA(new isInstanceOf<ArgumentError>()));
|
| + }
|
| +
|
| + test_watch_createFile() {
|
| + String rootPath = '/my/path';
|
| + provider.newFolder(rootPath);
|
| + return _watchingFolder(rootPath, (changesReceived) {
|
| + expect(changesReceived, hasLength(0));
|
| + String path = posix.join(rootPath, 'foo');
|
| + provider.newFile(path, 'contents');
|
| + return _delayed(() {
|
| + expect(changesReceived, hasLength(1));
|
| + expect(changesReceived[0].type, equals(ChangeType.ADD));
|
| + expect(changesReceived[0].path, equals(path));
|
| });
|
| });
|
| -
|
| - group('File', () {
|
| - group('==', () {
|
| - test('false', () {
|
| - File fileA = provider.getResource('/fileA.txt');
|
| - File fileB = provider.getResource('/fileB.txt');
|
| - expect(fileA == new Object(), isFalse);
|
| - expect(fileA == fileB, isFalse);
|
| - });
|
| -
|
| - test('true', () {
|
| - File file = provider.getResource('/file.txt');
|
| - expect(file == file, isTrue);
|
| - });
|
| -
|
| - test('before and after creation', () {
|
| - String path = '/file.txt';
|
| - File file1 = provider.getResource(path);
|
| - provider.newFile(path, 'contents');
|
| - File file2 = provider.getResource(path);
|
| - expect(file1 == file2, isTrue);
|
| - });
|
| - });
|
| -
|
| - group('exists', () {
|
| - test('false', () {
|
| - File file = provider.getResource('/file.txt');
|
| - expect(file, isNotNull);
|
| - expect(file.exists, isFalse);
|
| - });
|
| -
|
| - test('true', () {
|
| - provider.newFile('/foo/file.txt', 'qwerty');
|
| - File file = provider.getResource('/foo/file.txt');
|
| - expect(file, isNotNull);
|
| - expect(file.exists, isTrue);
|
| - });
|
| - });
|
| -
|
| - test('fullName', () {
|
| - File file = provider.getResource('/foo/bar/file.txt');
|
| - expect(file.path, '/foo/bar/file.txt');
|
| - });
|
| -
|
| - test('hashCode', () {
|
| - String path = '/foo/bar/file.txt';
|
| - File file1 = provider.getResource(path);
|
| - provider.newFile(path, 'contents');
|
| - File file2 = provider.getResource(path);
|
| - expect(file1.hashCode, equals(file2.hashCode));
|
| - });
|
| -
|
| - test('isOrContains', () {
|
| - String path = '/foo/bar/file.txt';
|
| - File file = provider.getResource(path);
|
| - expect(file.isOrContains(path), isTrue);
|
| - expect(file.isOrContains('/foo/bar'), isFalse);
|
| - });
|
| -
|
| - group('modificationStamp', () {
|
| - test('exists', () {
|
| - String path = '/foo/bar/file.txt';
|
| - File file = provider.newFile(path, 'qwerty');
|
| - expect(file.modificationStamp, isNonNegative);
|
| - });
|
| -
|
| - test('does not exist', () {
|
| - String path = '/foo/bar/file.txt';
|
| - File file = provider.newFile(path, 'qwerty');
|
| - provider.deleteFile(path);
|
| - expect(() {
|
| - file.modificationStamp;
|
| - }, throwsA(_isFileSystemException));
|
| - });
|
| - });
|
| -
|
| - test('shortName', () {
|
| - File file = provider.getResource('/foo/bar/file.txt');
|
| - expect(file.shortName, 'file.txt');
|
| - });
|
| -
|
| - test('toString', () {
|
| - File file = provider.getResource('/foo/bar/file.txt');
|
| - expect(file.toString(), '/foo/bar/file.txt');
|
| - });
|
| -
|
| - test('parent', () {
|
| - provider.newFile('/foo/bar/file.txt', 'content');
|
| - File file = provider.getResource('/foo/bar/file.txt');
|
| - Resource parent = file.parent;
|
| - expect(parent, new isInstanceOf<Folder>());
|
| - expect(parent.path, equals('/foo/bar'));
|
| + }
|
| +
|
| + test_watch_deleteFile() {
|
| + String rootPath = '/my/path';
|
| + provider.newFolder(rootPath);
|
| + String path = posix.join(rootPath, 'foo');
|
| + provider.newFile(path, 'contents 1');
|
| + return _watchingFolder(rootPath, (changesReceived) {
|
| + expect(changesReceived, hasLength(0));
|
| + provider.deleteFile(path);
|
| + return _delayed(() {
|
| + expect(changesReceived, hasLength(1));
|
| + expect(changesReceived[0].type, equals(ChangeType.REMOVE));
|
| + expect(changesReceived[0].path, equals(path));
|
| });
|
| });
|
| -
|
| - group('Folder', () {
|
| - Folder folder;
|
| - const String path = '/foo/bar';
|
| -
|
| - setUp(() {
|
| - folder = provider.newFolder(path);
|
| - });
|
| -
|
| - test('hashCode', () {
|
| - Folder folder2 = provider.getResource(path);
|
| - expect(folder.hashCode, equals(folder2.hashCode));
|
| - });
|
| -
|
| - test('equality: same path', () {
|
| - Folder folder2 = provider.getResource(path);
|
| - expect(folder == folder2, isTrue);
|
| - });
|
| -
|
| - test('equality: different paths', () {
|
| - String path2 = '/foo/baz';
|
| - Folder folder2 = provider.newFolder(path2);
|
| - expect(folder == folder2, isFalse);
|
| - });
|
| -
|
| - test('contains', () {
|
| - expect(folder.contains('/foo/bar/aaa.txt'), isTrue);
|
| - expect(folder.contains('/foo/bar/aaa/bbb.txt'), isTrue);
|
| - expect(folder.contains('/baz.txt'), isFalse);
|
| - expect(folder.contains('/foo/bar'), isFalse);
|
| - });
|
| -
|
| - test('isOrContains', () {
|
| - expect(folder.isOrContains('/foo/bar'), isTrue);
|
| - expect(folder.isOrContains('/foo/bar/aaa.txt'), isTrue);
|
| - expect(folder.isOrContains('/foo/bar/aaa/bbb.txt'), isTrue);
|
| - expect(folder.isOrContains('/baz.txt'), isFalse);
|
| - });
|
| -
|
| - group('getChild', () {
|
| - test('does not exist', () {
|
| - File file = folder.getChild('file.txt');
|
| - expect(file, isNotNull);
|
| - expect(file.exists, isFalse);
|
| - });
|
| -
|
| - test('file', () {
|
| - provider.newFile('/foo/bar/file.txt', 'content');
|
| - File child = folder.getChild('file.txt');
|
| - expect(child, isNotNull);
|
| - expect(child.exists, isTrue);
|
| - });
|
| -
|
| - test('folder', () {
|
| - provider.newFolder('/foo/bar/baz');
|
| - Folder child = folder.getChild('baz');
|
| - expect(child, isNotNull);
|
| - expect(child.exists, isTrue);
|
| - });
|
| - });
|
| -
|
| - group('getChildAssumingFolder', () {
|
| - test('does not exist', () {
|
| - Folder child = folder.getChildAssumingFolder('foldername');
|
| - expect(child, isNotNull);
|
| - expect(child.exists, isFalse);
|
| - });
|
| -
|
| - test('file', () {
|
| - provider.newFile('/foo/bar/foldername', 'content');
|
| - Folder child = folder.getChildAssumingFolder('foldername');
|
| - expect(child, isNotNull);
|
| - expect(child.exists, isFalse);
|
| - });
|
| -
|
| - test('folder', () {
|
| - provider.newFolder('/foo/bar/foldername');
|
| - Folder child = folder.getChildAssumingFolder('foldername');
|
| - expect(child, isNotNull);
|
| - expect(child.exists, isTrue);
|
| - });
|
| - });
|
| -
|
| - group('getChildren', () {
|
| - test('exists', () {
|
| - provider.newFile('/foo/bar/a.txt', 'aaa');
|
| - provider.newFolder('/foo/bar/bFolder');
|
| - provider.newFile('/foo/bar/c.txt', 'ccc');
|
| - // prepare 3 children
|
| - List<Resource> children = folder.getChildren();
|
| - expect(children, hasLength(3));
|
| - children.sort((a, b) => a.shortName.compareTo(b.shortName));
|
| - // check that each child exists
|
| - children.forEach((child) {
|
| - expect(child.exists, true);
|
| - });
|
| - // check names
|
| - expect(children[0].shortName, 'a.txt');
|
| - expect(children[1].shortName, 'bFolder');
|
| - expect(children[2].shortName, 'c.txt');
|
| - // check types
|
| - expect(children[0], _isFile);
|
| - expect(children[1], _isFolder);
|
| - expect(children[2], _isFile);
|
| - });
|
| -
|
| - test('does not exist', () {
|
| - folder = folder.getChildAssumingFolder('no-such-folder');
|
| - expect(() {
|
| - folder.getChildren();
|
| - }, throwsA(_isFileSystemException));
|
| - });
|
| - });
|
| -
|
| - test('parent', () {
|
| - Resource parent1 = folder.parent;
|
| - expect(parent1, new isInstanceOf<Folder>());
|
| - expect(parent1.path, equals('/foo'));
|
| - Resource parent2 = parent1.parent;
|
| - expect(parent2, new isInstanceOf<Folder>());
|
| - expect(parent2.path, equals('/'));
|
| - expect(parent2.parent, isNull);
|
| - });
|
| -
|
| - test('canonicalizePath', () {
|
| - expect(folder.canonicalizePath('baz'), equals('/foo/bar/baz'));
|
| - expect(folder.canonicalizePath('/baz'), equals('/baz'));
|
| - expect(folder.canonicalizePath('../baz'), equals('/foo/baz'));
|
| - expect(folder.canonicalizePath('/a/b/../c'), equals('/a/c'));
|
| - expect(folder.canonicalizePath('./baz'), equals('/foo/bar/baz'));
|
| - expect(folder.canonicalizePath('/a/b/./c'), equals('/a/b/c'));
|
| + }
|
| +
|
| + test_watch_modifyFile() {
|
| + String rootPath = '/my/path';
|
| + provider.newFolder(rootPath);
|
| + String path = posix.join(rootPath, 'foo');
|
| + provider.newFile(path, 'contents 1');
|
| + return _watchingFolder(rootPath, (changesReceived) {
|
| + expect(changesReceived, hasLength(0));
|
| + provider.modifyFile(path, 'contents 2');
|
| + return _delayed(() {
|
| + expect(changesReceived, hasLength(1));
|
| + expect(changesReceived[0].type, equals(ChangeType.MODIFY));
|
| + expect(changesReceived[0].path, equals(path));
|
| });
|
| });
|
| -
|
| - group('_MemoryFileSource', () {
|
| - Source source;
|
| -
|
| - group('existent', () {
|
| - setUp(() {
|
| - File file = provider.newFile('/foo/test.dart', 'library test;');
|
| - source = file.createSource();
|
| - });
|
| -
|
| - group('==', () {
|
| - group('true', () {
|
| - test('self', () {
|
| - File file = provider.newFile('/foo/test.dart', '');
|
| - Source source = file.createSource();
|
| - expect(source == source, isTrue);
|
| - });
|
| -
|
| - test('same file', () {
|
| - File file = provider.newFile('/foo/test.dart', '');
|
| - Source sourceA = file.createSource();
|
| - Source sourceB = file.createSource();
|
| - expect(sourceA == sourceB, isTrue);
|
| - });
|
| - });
|
| -
|
| - group('false', () {
|
| - test('not a memory Source', () {
|
| - File file = provider.newFile('/foo/test.dart', '');
|
| - Source source = file.createSource();
|
| - expect(source == new Object(), isFalse);
|
| - });
|
| -
|
| - test('different file', () {
|
| - File fileA = provider.newFile('/foo/a.dart', '');
|
| - File fileB = provider.newFile('/foo/b.dart', '');
|
| - Source sourceA = fileA.createSource();
|
| - Source sourceB = fileB.createSource();
|
| - expect(sourceA == sourceB, isFalse);
|
| - });
|
| - });
|
| - });
|
| -
|
| - test('contents', () {
|
| - TimestampedData<String> contents = source.contents;
|
| - expect(contents.data, 'library test;');
|
| - });
|
| -
|
| - test('encoding', () {
|
| - expect(source.encoding, 'file:///foo/test.dart');
|
| - });
|
| -
|
| - test('exists', () {
|
| - expect(source.exists(), isTrue);
|
| - });
|
| -
|
| - test('fullName', () {
|
| - expect(source.fullName, '/foo/test.dart');
|
| - });
|
| -
|
| - test('hashCode', () {
|
| - source.hashCode;
|
| - });
|
| -
|
| - test('shortName', () {
|
| - expect(source.shortName, 'test.dart');
|
| - });
|
| -
|
| - test('resolveRelative', () {
|
| - Uri relative =
|
| - source.resolveRelativeUri(new Uri.file('bar/baz.dart'));
|
| - expect(relative.path, '/foo/bar/baz.dart');
|
| - });
|
| - });
|
| -
|
| - group('non-existent', () {
|
| - setUp(() {
|
| - File file = provider.getResource('/foo/test.dart');
|
| - source = file.createSource();
|
| - });
|
| -
|
| - test('contents', () {
|
| - expect(() {
|
| - source.contents;
|
| - }, throwsA(_isFileSystemException));
|
| - });
|
| -
|
| - test('encoding', () {
|
| - expect(source.encoding, 'file:///foo/test.dart');
|
| - });
|
| -
|
| - test('exists', () {
|
| - expect(source.exists(), isFalse);
|
| - });
|
| -
|
| - test('fullName', () {
|
| - expect(source.fullName, '/foo/test.dart');
|
| - });
|
| -
|
| - test('modificationStamp', () {
|
| - expect(source.modificationStamp, -1);
|
| - });
|
| -
|
| - test('shortName', () {
|
| - expect(source.shortName, 'test.dart');
|
| - });
|
| -
|
| - test('resolveRelative', () {
|
| - Uri relative =
|
| - source.resolveRelativeUri(new Uri.file('bar/baz.dart'));
|
| - expect(relative.path, '/foo/bar/baz.dart');
|
| - });
|
| + }
|
| +
|
| + test_watch_modifyFile_inSubDir() {
|
| + String rootPath = '/my/path';
|
| + provider.newFolder(rootPath);
|
| + String subdirPath = posix.join(rootPath, 'foo');
|
| + provider.newFolder(subdirPath);
|
| + String path = posix.join(rootPath, 'bar');
|
| + provider.newFile(path, 'contents 1');
|
| + return _watchingFolder(rootPath, (changesReceived) {
|
| + expect(changesReceived, hasLength(0));
|
| + provider.modifyFile(path, 'contents 2');
|
| + return _delayed(() {
|
| + expect(changesReceived, hasLength(1));
|
| + expect(changesReceived[0].type, equals(ChangeType.MODIFY));
|
| + expect(changesReceived[0].path, equals(path));
|
| });
|
| });
|
| - });
|
| + }
|
| +
|
| + Future _delayed(computation()) {
|
| + return new Future.delayed(Duration.ZERO, computation);
|
| + }
|
| +
|
| + _watchingFolder(String path, test(List<WatchEvent> changesReceived)) {
|
| + Folder folder = provider.getResource(path);
|
| + var changesReceived = <WatchEvent>[];
|
| + folder.changes.listen(changesReceived.add);
|
| + return test(changesReceived);
|
| + }
|
| }
|
|
|