| 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 test.context.directory.manager; | 5 library test.context.directory.manager; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/context_directory_manager.dart'; | 7 import 'package:analysis_server/src/context_directory_manager.dart'; |
| 8 import 'package:analysis_server/src/resource.dart'; | 8 import 'package:analysis_server/src/resource.dart'; |
| 9 import 'package:path/path.dart'; |
| 9 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart'; |
| 10 | 13 |
| 11 class TestContextDirectoryManager extends ContextDirectoryManager { | 14 class TestContextDirectoryManager extends ContextDirectoryManager { |
| 12 TestContextDirectoryManager(MemoryResourceProvider provider) : super(provider)
; | 15 TestContextDirectoryManager(MemoryResourceProvider provider) : super(provider)
; |
| 13 | 16 |
| 14 final Set<String> currentContextPaths = new Set<String>(); | 17 final Set<String> currentContextPaths = new Set<String>(); |
| 18 final Map<String, String> currentContextPubspecPaths = <String, String>{}; |
| 19 final Map<String, Set<String>> currentContextFilePaths = <String, Set<String>>
{}; |
| 15 | 20 |
| 16 @override | 21 @override |
| 17 void addContext(Folder folder) { | 22 void addContext(Folder folder, File pubspecFile) { |
| 18 currentContextPaths.add(folder.fullName); | 23 currentContextPaths.add(folder.fullName); |
| 24 currentContextPubspecPaths[folder.fullName] = pubspecFile != null ? pubspecF
ile.fullName : null; |
| 25 currentContextFilePaths[folder.fullName] = new Set<String>(); |
| 26 } |
| 27 |
| 28 @override |
| 29 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
| 30 Set<String> filePaths = currentContextFilePaths[contextFolder.fullName]; |
| 31 for (Source source in changeSet.addedSources) { |
| 32 filePaths.add(source.fullName); |
| 33 } |
| 34 // TODO(paulberry): handle source.changedSources and source.removedSources. |
| 19 } | 35 } |
| 20 } | 36 } |
| 21 | 37 |
| 22 main() { | 38 main() { |
| 23 groupSep = ' | '; | 39 groupSep = ' | '; |
| 24 | 40 |
| 25 group('ContextDirectoryManager', () { | 41 group('ContextDirectoryManager', () { |
| 26 TestContextDirectoryManager manager; | 42 TestContextDirectoryManager manager; |
| 27 MemoryResourceProvider provider; | 43 MemoryResourceProvider provider; |
| 28 | 44 |
| 29 setUp(() { | 45 setUp(() { |
| 30 provider = new MemoryResourceProvider(); | 46 provider = new MemoryResourceProvider(); |
| 31 manager = new TestContextDirectoryManager(provider); | 47 manager = new TestContextDirectoryManager(provider); |
| 32 }); | 48 }); |
| 33 | 49 |
| 34 test('add folder with pubspec', () { | 50 test('add folder with pubspec', () { |
| 35 provider.newFile('/my/proj/pubspec.yaml', 'pubspec'); | 51 String projPath = '/my/proj'; |
| 36 manager.setRoots(<String>['/my/proj'], <String>[]); | 52 String pubspecPath = posix.join(projPath, 'pubspec.yaml'); |
| 53 provider.newFolder(projPath); |
| 54 provider.newFile(pubspecPath, 'pubspec'); |
| 55 manager.setRoots(<String>[projPath], <String>[]); |
| 37 expect(manager.currentContextPaths, hasLength(1)); | 56 expect(manager.currentContextPaths, hasLength(1)); |
| 38 expect(manager.currentContextPaths, contains('/my/proj')); | 57 expect(manager.currentContextPaths, contains(projPath)); |
| 58 expect(manager.currentContextPubspecPaths[projPath], equals(pubspecPath)); |
| 59 expect(manager.currentContextFilePaths[projPath], hasLength(0)); |
| 60 }); |
| 61 |
| 62 test('add folder without pubspec', () { |
| 63 String projPath = '/my/proj'; |
| 64 provider.newFolder(projPath); |
| 65 manager.setRoots(<String>[projPath], <String>[]); |
| 66 expect(manager.currentContextPaths, hasLength(1)); |
| 67 expect(manager.currentContextPaths, contains(projPath)); |
| 68 expect(manager.currentContextPubspecPaths[projPath], isNull); |
| 69 expect(manager.currentContextFilePaths[projPath], hasLength(0)); |
| 70 }); |
| 71 |
| 72 test('add folder with dart file', () { |
| 73 String projPath = '/my/proj'; |
| 74 provider.newFolder(projPath); |
| 75 String filePath = posix.join(projPath, 'foo.dart'); |
| 76 provider.newFile(filePath, 'contents'); |
| 77 manager.setRoots(<String>[projPath], <String>[]); |
| 78 var filePaths = manager.currentContextFilePaths[projPath]; |
| 79 expect(filePaths, hasLength(1)); |
| 80 expect(filePaths, contains(filePath)); |
| 81 }); |
| 82 |
| 83 test('add folder with dart file in subdir', () { |
| 84 String projPath = '/my/proj'; |
| 85 provider.newFolder(projPath); |
| 86 String filePath = posix.join(projPath, 'foo', 'bar.dart'); |
| 87 provider.newFile(filePath, 'contents'); |
| 88 manager.setRoots(<String>[projPath], <String>[]); |
| 89 var filePaths = manager.currentContextFilePaths[projPath]; |
| 90 expect(filePaths, hasLength(1)); |
| 91 expect(filePaths, contains(filePath)); |
| 39 }); | 92 }); |
| 40 }); | 93 }); |
| 41 } | 94 } |
| OLD | NEW |