Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 library test.src.task.abstract_context_test; | |
| 6 | |
| 7 import 'package:analyzer/file_system/file_system.dart'; | |
| 8 import 'package:analyzer/file_system/memory_file_system.dart'; | |
| 9 import 'package:analyzer/src/context/context.dart'; | |
| 10 import 'package:analyzer/src/generated/element.dart'; | |
| 11 import 'package:analyzer/src/generated/engine.dart' | |
| 12 hide AnalysisContextImpl, AnalysisTask; | |
| 13 import 'package:analyzer/src/generated/sdk.dart'; | |
| 14 import 'package:analyzer/src/generated/source.dart'; | |
| 15 import 'package:analyzer/src/plugin/engine_plugin.dart'; | |
| 16 import 'package:analyzer/src/task/driver.dart'; | |
| 17 import 'package:analyzer/src/task/manager.dart'; | |
| 18 import 'package:plugin/manager.dart'; | |
| 19 import 'package:unittest/unittest.dart'; | |
| 20 import 'mock_sdk.dart'; | |
| 21 | |
| 22 class AbstractContextTest { | |
| 23 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); | |
| 24 | |
| 25 ExtensionManager extensionManager = new ExtensionManager(); | |
| 26 | |
| 27 DartSdk sdk = new MockSdk(); | |
| 28 AnalysisContextImpl context; | |
| 29 | |
| 30 TaskManager taskManager = new TaskManager(); | |
| 31 AnalysisDriver analysisDriver; | |
| 32 | |
| 33 /** | |
| 34 * Assert that the given collection has the same number of elements as the num ber of specified | |
| 35 * names, and that for each specified name, a corresponding element can be fou nd in the given | |
| 36 * collection with that name. | |
| 37 * | |
| 38 * @param elements the elements | |
|
Brian Wilkerson
2015/05/03 15:35:32
Perhaps convert to a Dart-style comment while we'r
scheglov
2015/05/03 20:26:28
Done.
| |
| 39 * @param names the names | |
| 40 */ | |
| 41 void assertNamedElements(List<Element> elements, List<String> names) { | |
| 42 for (String elemName in names) { | |
| 43 bool found = false; | |
| 44 for (Element elem in elements) { | |
| 45 if (elem.name == elemName) { | |
| 46 found = true; | |
| 47 break; | |
| 48 } | |
| 49 } | |
| 50 if (!found) { | |
| 51 StringBuffer buffer = new StringBuffer(); | |
| 52 buffer.write("Expected element named: "); | |
| 53 buffer.write(elemName); | |
| 54 buffer.write("\n but found: "); | |
| 55 for (Element elem in elements) { | |
| 56 buffer.write(elem.name); | |
| 57 buffer.write(", "); | |
| 58 } | |
| 59 fail(buffer.toString()); | |
| 60 } | |
| 61 } | |
| 62 expect(elements, hasLength(names.length)); | |
| 63 } | |
| 64 | |
| 65 AnalysisContextImpl createAnalysisContext() { | |
| 66 return new AnalysisContextImpl(); | |
| 67 } | |
| 68 | |
| 69 Source newSource(String path, [String content = '']) { | |
| 70 File file = resourceProvider.newFile(path, content); | |
| 71 return file.createSource(); | |
| 72 } | |
| 73 | |
| 74 List<Source> newSources(Map<String, String> sourceMap) { | |
| 75 List<Source> sources = <Source>[]; | |
| 76 sourceMap.forEach((String path, String content) { | |
| 77 Source source = newSource(path, content); | |
| 78 sources.add(source); | |
| 79 }); | |
| 80 return sources; | |
| 81 } | |
| 82 | |
| 83 void setUp() { | |
| 84 // configure TaskManager | |
| 85 { | |
| 86 EnginePlugin plugin = AnalysisEngine.instance.enginePlugin; | |
| 87 extensionManager.processPlugins([plugin]); | |
| 88 taskManager.addTaskDescriptors(plugin.taskDescriptors); | |
| 89 } | |
| 90 // prepare AnalysisContext | |
| 91 context = createAnalysisContext(); | |
| 92 context.sourceFactory = new SourceFactory(<UriResolver>[ | |
| 93 new DartUriResolver(sdk), | |
| 94 new ResourceUriResolver(resourceProvider) | |
| 95 ]); | |
| 96 // prepare AnalysisDriver | |
| 97 analysisDriver = new AnalysisDriver(taskManager, context); | |
| 98 } | |
| 99 | |
| 100 void tearDown() {} | |
| 101 } | |
| OLD | NEW |