| Index: pkg/analysis_server/test/resource_test.dart
|
| diff --git a/pkg/analysis_server/test/resource_test.dart b/pkg/analysis_server/test/resource_test.dart
|
| index 2f4c996b3fa67ac748b210b7709dae95b8b947fe..8bc7cc4efabe9659656655205c620754ee5620f2 100644
|
| --- a/pkg/analysis_server/test/resource_test.dart
|
| +++ b/pkg/analysis_server/test/resource_test.dart
|
| @@ -7,6 +7,8 @@ library test.resource;
|
| import 'dart:async';
|
| import 'dart:io' as io;
|
|
|
| +import 'mocks.dart';
|
| +
|
| import 'package:analysis_server/src/resource.dart';
|
| import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
|
| import 'package:analyzer/src/generated/source_io.dart';
|
| @@ -32,6 +34,85 @@ main() {
|
| 'MemoryResourceException(path=/my/path; message=my message)');
|
| });
|
|
|
| + group('Watch', () {
|
| +
|
| + Future delayed(computation()) {
|
| + return pumpEventQueue().then((_) => computation());
|
| + }
|
| +
|
| + watchingFolder(String path, test(List<WatchEvent> changesReceived)) {
|
| + Folder folder = provider.getResource(path);
|
| + var changesReceived = <WatchEvent>[];
|
| + var subscription = folder.changes.listen(changesReceived.add);
|
| + return test(changesReceived);
|
| + }
|
| +
|
| + test('create file', () {
|
| + var rootPath = '/my/path';
|
| + provider.newFolder(rootPath);
|
| + watchingFolder(rootPath, (changesReceived) {
|
| + expect(changesReceived, hasLength(0));
|
| + var 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', () {
|
| + var rootPath = '/my/path';
|
| + provider.newFolder(rootPath);
|
| + var path = 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', () {
|
| + var rootPath = '/my/path';
|
| + provider.newFolder(rootPath);
|
| + var subdirPath = join(rootPath, 'foo');
|
| + provider.newFolder(subdirPath);
|
| + var path = 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', () {
|
| + var rootPath = '/my/path';
|
| + provider.newFolder(rootPath);
|
| + var path = 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('newFolder', () {
|
| test('empty path', () {
|
| expect(
|
| @@ -70,6 +151,65 @@ main() {
|
| });
|
| });
|
|
|
| + group('modifyFile', () {
|
| + test('nonexistent', () {
|
| + var path = '/my/file';
|
| + expect(() { provider.modifyFile(path, 'contents'); },
|
| + throwsA(new isInstanceOf<ArgumentError>()));
|
| + var file = provider.getResource(path);
|
| + expect(file, isNotNull);
|
| + expect(file.exists, isFalse);
|
| + });
|
| +
|
| + test('is folder', () {
|
| + var path = '/my/file';
|
| + provider.newFolder(path);
|
| + expect(() { provider.modifyFile(path, 'contents'); },
|
| + throwsA(new isInstanceOf<ArgumentError>()));
|
| + expect(provider.getResource(path), new isInstanceOf<Folder>());
|
| + });
|
| +
|
| + test('successful', () {
|
| + var path = '/my/file';
|
| + provider.newFile(path, 'contents 1');
|
| + var file = provider.getResource(path);
|
| + expect(file, new isInstanceOf<File>());
|
| + var source = file.createSource(UriKind.FILE_URI);
|
| + expect(source.contents.data, equals('contents 1'));
|
| + provider.modifyFile(path, 'contents 2');
|
| + expect(source.contents.data, equals('contents 2'));
|
| + });
|
| + });
|
| +
|
| + group('deleteFile', () {
|
| + test('nonexistent', () {
|
| + var path = '/my/file';
|
| + expect(() { provider.deleteFile(path); },
|
| + throwsA(new isInstanceOf<ArgumentError>()));
|
| + var file = provider.getResource(path);
|
| + expect(file, isNotNull);
|
| + expect(file.exists, isFalse);
|
| + });
|
| +
|
| + test('is folder', () {
|
| + var path = '/my/file';
|
| + provider.newFolder(path);
|
| + expect(() { provider.deleteFile(path); },
|
| + throwsA(new isInstanceOf<ArgumentError>()));
|
| + expect(provider.getResource(path), new isInstanceOf<Folder>());
|
| + });
|
| +
|
| + test('successful', () {
|
| + var path = '/my/file';
|
| + provider.newFile(path, 'contents');
|
| + var file = provider.getResource(path);
|
| + expect(file, new isInstanceOf<File>());
|
| + expect(file.exists, isTrue);
|
| + provider.deleteFile(path);
|
| + expect(file.exists, isFalse);
|
| + });
|
| + });
|
| +
|
| group('File', () {
|
| group('==', () {
|
| test('false', () {
|
|
|