| 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 'mocks.dart'; |
| 7 import 'package:analysis_server/src/context_directory_manager.dart'; | 8 import 'package:analysis_server/src/context_directory_manager.dart'; |
| 8 import 'package:analysis_server/src/resource.dart'; | 9 import 'package:analysis_server/src/resource.dart'; |
| 9 import 'package:path/path.dart'; | 10 import 'package:path/path.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
| 13 | 14 |
| 14 class TestContextDirectoryManager extends ContextDirectoryManager { | 15 class TestContextDirectoryManager extends ContextDirectoryManager { |
| 15 TestContextDirectoryManager(MemoryResourceProvider provider) : super(provider)
; | 16 TestContextDirectoryManager(MemoryResourceProvider provider) : super(provider)
; |
| 16 | 17 |
| 17 final Set<String> currentContextPaths = new Set<String>(); | 18 final Set<String> currentContextPaths = new Set<String>(); |
| 18 final Map<String, String> currentContextPubspecPaths = <String, String>{}; | 19 final Map<String, String> currentContextPubspecPaths = <String, String>{}; |
| 19 final Map<String, Set<String>> currentContextFilePaths = <String, Set<String>>
{}; | 20 final Map<String, Set<String>> currentContextFilePaths = <String, Set<String>>
{}; |
| 20 | 21 |
| 21 @override | 22 @override |
| 22 void addContext(Folder folder, File pubspecFile) { | 23 void addContext(Folder folder, File pubspecFile) { |
| 23 currentContextPaths.add(folder.fullName); | 24 currentContextPaths.add(folder.path); |
| 24 currentContextPubspecPaths[folder.fullName] = pubspecFile != null ? pubspecF
ile.fullName : null; | 25 currentContextPubspecPaths[folder.path] = pubspecFile != null ? pubspecFile.
path : null; |
| 25 currentContextFilePaths[folder.fullName] = new Set<String>(); | 26 currentContextFilePaths[folder.path] = new Set<String>(); |
| 26 } | 27 } |
| 27 | 28 |
| 28 @override | 29 @override |
| 29 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { | 30 void applyChangesToContext(Folder contextFolder, ChangeSet changeSet) { |
| 30 Set<String> filePaths = currentContextFilePaths[contextFolder.fullName]; | 31 Set<String> filePaths = currentContextFilePaths[contextFolder.path]; |
| 31 for (Source source in changeSet.addedSources) { | 32 for (Source source in changeSet.addedSources) { |
| 33 expect(filePaths, isNot(contains(source.fullName))); |
| 32 filePaths.add(source.fullName); | 34 filePaths.add(source.fullName); |
| 33 } | 35 } |
| 34 // TODO(paulberry): handle source.changedSources and source.removedSources. | 36 for (Source source in changeSet.removedSources) { |
| 37 expect(filePaths, contains(source.fullName)); |
| 38 filePaths.remove(source.fullName); |
| 39 } |
| 40 // TODO(paulberry): handle source.changedSources. |
| 35 } | 41 } |
| 36 } | 42 } |
| 37 | 43 |
| 38 main() { | 44 main() { |
| 39 groupSep = ' | '; | 45 groupSep = ' | '; |
| 40 | 46 |
| 41 group('ContextDirectoryManager', () { | 47 group('ContextDirectoryManager', () { |
| 42 TestContextDirectoryManager manager; | 48 TestContextDirectoryManager manager; |
| 43 MemoryResourceProvider provider; | 49 MemoryResourceProvider provider; |
| 44 | 50 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 test('add folder with dart file in subdir', () { | 89 test('add folder with dart file in subdir', () { |
| 84 String projPath = '/my/proj'; | 90 String projPath = '/my/proj'; |
| 85 provider.newFolder(projPath); | 91 provider.newFolder(projPath); |
| 86 String filePath = posix.join(projPath, 'foo', 'bar.dart'); | 92 String filePath = posix.join(projPath, 'foo', 'bar.dart'); |
| 87 provider.newFile(filePath, 'contents'); | 93 provider.newFile(filePath, 'contents'); |
| 88 manager.setRoots(<String>[projPath], <String>[]); | 94 manager.setRoots(<String>[projPath], <String>[]); |
| 89 var filePaths = manager.currentContextFilePaths[projPath]; | 95 var filePaths = manager.currentContextFilePaths[projPath]; |
| 90 expect(filePaths, hasLength(1)); | 96 expect(filePaths, hasLength(1)); |
| 91 expect(filePaths, contains(filePath)); | 97 expect(filePaths, contains(filePath)); |
| 92 }); | 98 }); |
| 99 |
| 100 group('detect context modifications', () { |
| 101 String projPath; |
| 102 |
| 103 setUp(() { |
| 104 projPath = '/my/proj'; |
| 105 provider.newFolder(projPath); |
| 106 }); |
| 107 |
| 108 test('Add file', () { |
| 109 manager.setRoots(<String>[projPath], <String>[]); |
| 110 Set<String> filePaths = manager.currentContextFilePaths[projPath]; |
| 111 expect(filePaths, hasLength(0)); |
| 112 String filePath = posix.join(projPath, 'foo.dart'); |
| 113 provider.newFile(filePath, 'contents'); |
| 114 return pumpEventQueue().then((_) { |
| 115 expect(filePaths, hasLength(1)); |
| 116 expect(filePaths, contains(filePath)); |
| 117 }); |
| 118 }); |
| 119 |
| 120 test('Add file in subdirectory', () { |
| 121 manager.setRoots(<String>[projPath], <String>[]); |
| 122 Set<String> filePaths = manager.currentContextFilePaths[projPath]; |
| 123 expect(filePaths, hasLength(0)); |
| 124 String filePath = posix.join(projPath, 'foo', 'bar.dart'); |
| 125 provider.newFile(filePath, 'contents'); |
| 126 return pumpEventQueue().then((_) { |
| 127 expect(filePaths, hasLength(1)); |
| 128 expect(filePaths, contains(filePath)); |
| 129 }); |
| 130 }); |
| 131 |
| 132 test('Delete file', () { |
| 133 String filePath = posix.join(projPath, 'foo.dart'); |
| 134 provider.newFile(filePath, 'contents'); |
| 135 manager.setRoots(<String>[projPath], <String>[]); |
| 136 Set<String> filePaths = manager.currentContextFilePaths[projPath]; |
| 137 expect(filePaths, hasLength(1)); |
| 138 expect(filePaths, contains(filePath)); |
| 139 provider.deleteFile(filePath); |
| 140 return pumpEventQueue().then((_) => expect(filePaths, hasLength(0))); |
| 141 }); |
| 142 }); |
| 93 }); | 143 }); |
| 94 } | 144 } |
| OLD | NEW |