| 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.dart_test; |
| 6 |
| 7 import 'package:analyzer/src/generated/engine.dart' hide AnalysisTask, |
| 8 ParseDartTask, ScanDartTask; |
| 9 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:analyzer/src/task/dart.dart'; |
| 11 import 'package:analyzer/src/task/targets.dart'; |
| 12 import 'package:analyzer/task/dart.dart'; |
| 13 import 'package:analyzer/task/general.dart'; |
| 14 import 'package:analyzer/task/model.dart'; |
| 15 import 'package:unittest/unittest.dart'; |
| 16 |
| 17 import '../../generated/resolver_test.dart'; |
| 18 import '../../generated/test_support.dart'; |
| 19 import '../../reflective_tests.dart'; |
| 20 |
| 21 main() { |
| 22 groupSep = ' | '; |
| 23 runReflectiveTests(BuildCompilationUnitElementTaskTest); |
| 24 runReflectiveTests(ParseDartTaskTest); |
| 25 runReflectiveTests(ScanDartTaskTest); |
| 26 } |
| 27 |
| 28 @reflectiveTest |
| 29 class BuildCompilationUnitElementTaskTest extends EngineTestCase { |
| 30 test_buildInputs() { |
| 31 SourceTarget target = new SourceTarget(new TestSource()); |
| 32 Map<String, TaskInput> inputs = |
| 33 BuildCompilationUnitElementTask.buildInputs(target); |
| 34 expect(inputs, isNotNull); |
| 35 expect(inputs, hasLength(1)); |
| 36 expect( |
| 37 inputs[BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME], |
| 38 isNotNull); |
| 39 } |
| 40 |
| 41 test_constructor() { |
| 42 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 43 SourceTarget target = new SourceTarget(new TestSource()); |
| 44 BuildCompilationUnitElementTask task = |
| 45 new BuildCompilationUnitElementTask(context, target); |
| 46 expect(task, isNotNull); |
| 47 expect(task.context, context); |
| 48 expect(task.target, target); |
| 49 } |
| 50 |
| 51 test_createTask() { |
| 52 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 53 SourceTarget target = new SourceTarget(new TestSource()); |
| 54 BuildCompilationUnitElementTask task = |
| 55 BuildCompilationUnitElementTask.createTask(context, target); |
| 56 expect(task, isNotNull); |
| 57 expect(task.context, context); |
| 58 expect(task.target, target); |
| 59 } |
| 60 |
| 61 test_description() { |
| 62 SourceTarget target = new SourceTarget(new TestSource()); |
| 63 BuildCompilationUnitElementTask task = |
| 64 new BuildCompilationUnitElementTask(null, target); |
| 65 expect(task.description, isNotNull); |
| 66 } |
| 67 |
| 68 test_descriptor() { |
| 69 TaskDescriptor descriptor = BuildCompilationUnitElementTask.DESCRIPTOR; |
| 70 expect(descriptor, isNotNull); |
| 71 } |
| 72 |
| 73 test_perform_library() { |
| 74 BuildCompilationUnitElementTask task = _performBuildTask(r''' |
| 75 library lib; |
| 76 import 'lib2.dart'; |
| 77 export 'lib3.dart'; |
| 78 part 'part.dart'; |
| 79 class A {'''); |
| 80 |
| 81 expect(task.caughtException, isNull); |
| 82 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; |
| 83 expect(outputs, hasLength(2)); |
| 84 expect(outputs[COMPILATION_UNIT_ELEMENT], isNotNull); |
| 85 expect(outputs[BUILT_UNIT], isNotNull); |
| 86 } |
| 87 |
| 88 BuildCompilationUnitElementTask _performBuildTask(String content) { |
| 89 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 90 SourceTarget target = new SourceTarget(new TestSource()); |
| 91 |
| 92 ScanDartTask scanTask = new ScanDartTask(context, target); |
| 93 scanTask.inputs = { |
| 94 ScanDartTask.CONTENT_INPUT_NAME: content |
| 95 }; |
| 96 scanTask.perform(); |
| 97 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; |
| 98 |
| 99 ParseDartTask parseTask = new ParseDartTask(context, target); |
| 100 parseTask.inputs = { |
| 101 ParseDartTask.LINE_INFO_INPUT_NAME: scanOutputs[LINE_INFO], |
| 102 ParseDartTask.TOKEN_STREAM_INPUT_NAME: scanOutputs[TOKEN_STREAM] |
| 103 }; |
| 104 parseTask.perform(); |
| 105 Map<ResultDescriptor, dynamic> parseOutputs = parseTask.outputs; |
| 106 |
| 107 BuildCompilationUnitElementTask buildTask = |
| 108 new BuildCompilationUnitElementTask(context, target); |
| 109 buildTask.inputs = { |
| 110 BuildCompilationUnitElementTask.PARSED_UNIT_INPUT_NAME: |
| 111 parseOutputs[PARSED_UNIT] |
| 112 }; |
| 113 buildTask.perform(); |
| 114 |
| 115 return buildTask; |
| 116 } |
| 117 } |
| 118 |
| 119 @reflectiveTest |
| 120 class ParseDartTaskTest extends EngineTestCase { |
| 121 test_buildInputs() { |
| 122 SourceTarget target = new SourceTarget(new TestSource()); |
| 123 Map<String, TaskInput> inputs = ParseDartTask.buildInputs(target); |
| 124 expect(inputs, isNotNull); |
| 125 expect(inputs, hasLength(2)); |
| 126 expect(inputs[ParseDartTask.LINE_INFO_INPUT_NAME], isNotNull); |
| 127 expect(inputs[ParseDartTask.TOKEN_STREAM_INPUT_NAME], isNotNull); |
| 128 } |
| 129 |
| 130 test_constructor() { |
| 131 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 132 SourceTarget target = new SourceTarget(new TestSource()); |
| 133 ParseDartTask task = new ParseDartTask(context, target); |
| 134 expect(task, isNotNull); |
| 135 expect(task.context, context); |
| 136 expect(task.target, target); |
| 137 } |
| 138 |
| 139 test_createTask() { |
| 140 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 141 SourceTarget target = new SourceTarget(new TestSource()); |
| 142 ParseDartTask task = ParseDartTask.createTask(context, target); |
| 143 expect(task, isNotNull); |
| 144 expect(task.context, context); |
| 145 expect(task.target, target); |
| 146 } |
| 147 |
| 148 test_description() { |
| 149 SourceTarget target = new SourceTarget(new TestSource()); |
| 150 ParseDartTask task = new ParseDartTask(null, target); |
| 151 expect(task.description, isNotNull); |
| 152 } |
| 153 |
| 154 test_descriptor() { |
| 155 TaskDescriptor descriptor = ParseDartTask.DESCRIPTOR; |
| 156 expect(descriptor, isNotNull); |
| 157 } |
| 158 |
| 159 test_perform() { |
| 160 ParseDartTask task = _performParseTask(r''' |
| 161 part of lib; |
| 162 class B {}'''); |
| 163 |
| 164 expect(task.caughtException, isNull); |
| 165 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; |
| 166 expect(outputs, hasLength(6)); |
| 167 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 168 expect(outputs[IMPORTED_LIBRARIES], hasLength(0)); |
| 169 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 170 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 171 expect(outputs[PARSED_UNIT], isNotNull); |
| 172 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 173 } |
| 174 |
| 175 test_perform_invalidDirectives() { |
| 176 ParseDartTask task = _performParseTask(r''' |
| 177 library lib; |
| 178 import '/does/not/exist.dart'; |
| 179 import '://invaliduri.dart'; |
| 180 export '${a}lib3.dart'; |
| 181 part 'part.dart'; |
| 182 class A {}'''); |
| 183 |
| 184 expect(task.caughtException, isNull); |
| 185 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; |
| 186 expect(outputs, hasLength(6)); |
| 187 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 188 expect(outputs[IMPORTED_LIBRARIES], hasLength(1)); |
| 189 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 190 expect(outputs[PARSE_ERRORS], hasLength(2)); |
| 191 expect(outputs[PARSED_UNIT], isNotNull); |
| 192 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 193 } |
| 194 |
| 195 test_perform_library() { |
| 196 ParseDartTask task = _performParseTask(r''' |
| 197 library lib; |
| 198 import 'lib2.dart'; |
| 199 export 'lib3.dart'; |
| 200 part 'part.dart'; |
| 201 class A {'''); |
| 202 |
| 203 expect(task.caughtException, isNull); |
| 204 Map<ResultDescriptor<dynamic>, dynamic> outputs = task.outputs; |
| 205 expect(outputs, hasLength(6)); |
| 206 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); |
| 207 expect(outputs[IMPORTED_LIBRARIES], hasLength(1)); |
| 208 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 209 expect(outputs[PARSE_ERRORS], hasLength(1)); |
| 210 expect(outputs[PARSED_UNIT], isNotNull); |
| 211 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 212 } |
| 213 |
| 214 ParseDartTask _performParseTask(String content) { |
| 215 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 216 SourceTarget target = new SourceTarget(new TestSource()); |
| 217 |
| 218 ScanDartTask scanTask = new ScanDartTask(context, target); |
| 219 scanTask.inputs = { |
| 220 ScanDartTask.CONTENT_INPUT_NAME: content |
| 221 }; |
| 222 scanTask.perform(); |
| 223 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; |
| 224 |
| 225 ParseDartTask parseTask = new ParseDartTask(context, target); |
| 226 parseTask.inputs = { |
| 227 ParseDartTask.LINE_INFO_INPUT_NAME: scanOutputs[LINE_INFO], |
| 228 ParseDartTask.TOKEN_STREAM_INPUT_NAME: scanOutputs[TOKEN_STREAM] |
| 229 }; |
| 230 parseTask.perform(); |
| 231 return parseTask; |
| 232 } |
| 233 } |
| 234 |
| 235 @reflectiveTest |
| 236 class ScanDartTaskTest extends EngineTestCase { |
| 237 test_buildInputs() { |
| 238 SourceTarget target = new SourceTarget(new TestSource()); |
| 239 Map<String, TaskInput> inputs = ScanDartTask.buildInputs(target); |
| 240 expect(inputs, isNotNull); |
| 241 expect(inputs, hasLength(1)); |
| 242 expect(inputs[ScanDartTask.CONTENT_INPUT_NAME], isNotNull); |
| 243 } |
| 244 |
| 245 test_constructor() { |
| 246 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 247 SourceTarget target = new SourceTarget(new TestSource()); |
| 248 ScanDartTask task = new ScanDartTask(context, target); |
| 249 expect(task, isNotNull); |
| 250 expect(task.context, context); |
| 251 expect(task.target, target); |
| 252 } |
| 253 |
| 254 test_createTask() { |
| 255 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 256 SourceTarget target = new SourceTarget(new TestSource()); |
| 257 ScanDartTask task = ScanDartTask.createTask(context, target); |
| 258 expect(task, isNotNull); |
| 259 expect(task.context, context); |
| 260 expect(task.target, target); |
| 261 } |
| 262 |
| 263 test_description() { |
| 264 SourceTarget target = new SourceTarget(new TestSource()); |
| 265 ScanDartTask task = new ScanDartTask(null, target); |
| 266 expect(task.description, isNotNull); |
| 267 } |
| 268 |
| 269 test_descriptor() { |
| 270 TaskDescriptor descriptor = ScanDartTask.DESCRIPTOR; |
| 271 expect(descriptor, isNotNull); |
| 272 } |
| 273 |
| 274 test_perform_errors() { |
| 275 ScanDartTask scanTask = _performScanTask('import "'); |
| 276 |
| 277 expect(scanTask.caughtException, isNull); |
| 278 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; |
| 279 expect(scanOutputs, hasLength(3)); |
| 280 expect(scanOutputs[LINE_INFO], isNotNull); |
| 281 expect(scanOutputs[SCAN_ERRORS], hasLength(1)); |
| 282 expect(scanOutputs[TOKEN_STREAM], isNotNull); |
| 283 } |
| 284 |
| 285 test_perform_noErrors() { |
| 286 ScanDartTask scanTask = _performScanTask('class A {}'); |
| 287 |
| 288 expect(scanTask.caughtException, isNull); |
| 289 Map<ResultDescriptor, dynamic> scanOutputs = scanTask.outputs; |
| 290 expect(scanOutputs, hasLength(3)); |
| 291 expect(scanOutputs[LINE_INFO], isNotNull); |
| 292 expect(scanOutputs[SCAN_ERRORS], hasLength(0)); |
| 293 expect(scanOutputs[TOKEN_STREAM], isNotNull); |
| 294 } |
| 295 |
| 296 ScanDartTask _performScanTask(String content) { |
| 297 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 298 SourceTarget target = new SourceTarget(new TestSource()); |
| 299 |
| 300 ScanDartTask scanTask = new ScanDartTask(context, target); |
| 301 scanTask.inputs = { |
| 302 ScanDartTask.CONTENT_INPUT_NAME: content |
| 303 }; |
| 304 scanTask.perform(); |
| 305 return scanTask; |
| 306 } |
| 307 } |
| OLD | NEW |