| 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 |
| 21 import 'mock_sdk.dart'; |
| 22 |
| 23 class AbstractContextTest { |
| 24 MemoryResourceProvider resourceProvider = new MemoryResourceProvider(); |
| 25 |
| 26 ExtensionManager extensionManager = new ExtensionManager(); |
| 27 |
| 28 DartSdk sdk = new MockSdk(); |
| 29 AnalysisContextImpl context; |
| 30 |
| 31 TaskManager taskManager = new TaskManager(); |
| 32 AnalysisDriver analysisDriver; |
| 33 |
| 34 /** |
| 35 * Assert that the given [elements] has the same number of items as the number |
| 36 * of specified [names], and that for each specified name, a corresponding |
| 37 * element can be found in the given collection with that name. |
| 38 */ |
| 39 void assertNamedElements(List<Element> elements, List<String> names) { |
| 40 for (String elemName in names) { |
| 41 bool found = false; |
| 42 for (Element elem in elements) { |
| 43 if (elem.name == elemName) { |
| 44 found = true; |
| 45 break; |
| 46 } |
| 47 } |
| 48 if (!found) { |
| 49 StringBuffer buffer = new StringBuffer(); |
| 50 buffer.write("Expected element named: "); |
| 51 buffer.write(elemName); |
| 52 buffer.write("\n but found: "); |
| 53 for (Element elem in elements) { |
| 54 buffer.write(elem.name); |
| 55 buffer.write(", "); |
| 56 } |
| 57 fail(buffer.toString()); |
| 58 } |
| 59 } |
| 60 expect(elements, hasLength(names.length)); |
| 61 } |
| 62 |
| 63 AnalysisContextImpl createAnalysisContext() { |
| 64 return new AnalysisContextImpl(); |
| 65 } |
| 66 |
| 67 Source newSource(String path, [String content = '']) { |
| 68 File file = resourceProvider.newFile(path, content); |
| 69 return file.createSource(); |
| 70 } |
| 71 |
| 72 List<Source> newSources(Map<String, String> sourceMap) { |
| 73 List<Source> sources = <Source>[]; |
| 74 sourceMap.forEach((String path, String content) { |
| 75 Source source = newSource(path, content); |
| 76 sources.add(source); |
| 77 }); |
| 78 return sources; |
| 79 } |
| 80 |
| 81 void setUp() { |
| 82 // configure TaskManager |
| 83 { |
| 84 EnginePlugin plugin = AnalysisEngine.instance.enginePlugin; |
| 85 extensionManager.processPlugins([plugin]); |
| 86 taskManager.addTaskDescriptors(plugin.taskDescriptors); |
| 87 } |
| 88 // prepare AnalysisContext |
| 89 context = createAnalysisContext(); |
| 90 context.sourceFactory = new SourceFactory(<UriResolver>[ |
| 91 new DartUriResolver(sdk), |
| 92 new ResourceUriResolver(resourceProvider) |
| 93 ]); |
| 94 // prepare AnalysisDriver |
| 95 analysisDriver = new AnalysisDriver(taskManager, context); |
| 96 } |
| 97 |
| 98 void tearDown() {} |
| 99 } |
| OLD | NEW |