| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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.src.task.dart_test; | 5 library test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 // d.dart | 1174 // d.dart |
| 1175 { | 1175 { |
| 1176 _computeResult(sourceD, IMPORT_SOURCE_CLOSURE); | 1176 _computeResult(sourceD, IMPORT_SOURCE_CLOSURE); |
| 1177 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); | 1177 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1178 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE]; | 1178 List<Source> closure = outputs[IMPORT_SOURCE_CLOSURE]; |
| 1179 expect(closure, contains(sourceD)); | 1179 expect(closure, contains(sourceD)); |
| 1180 expect(closure, contains(coreSource)); | 1180 expect(closure, contains(coreSource)); |
| 1181 } | 1181 } |
| 1182 } | 1182 } |
| 1183 | 1183 |
| 1184 test_perform_importExportClosure() { |
| 1185 Source sourceA = newSource('/a.dart', ''' |
| 1186 library lib_a; |
| 1187 '''); |
| 1188 Source sourceB = newSource('/b.dart', ''' |
| 1189 library lib_b; |
| 1190 export 'a.dart'; |
| 1191 '''); |
| 1192 Source sourceC = newSource('/c.dart', ''' |
| 1193 library lib_c; |
| 1194 import 'b.dart'; |
| 1195 '''); |
| 1196 Source coreSource = context.sourceFactory.resolveUri(null, 'dart:core'); |
| 1197 // c.dart |
| 1198 { |
| 1199 _computeResult(sourceC, IMPORT_EXPORT_SOURCE_CLOSURE); |
| 1200 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1201 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE]; |
| 1202 expect(closure, contains(sourceA)); |
| 1203 expect(closure, contains(sourceB)); |
| 1204 expect(closure, contains(sourceC)); |
| 1205 expect(closure, contains(coreSource)); |
| 1206 } |
| 1207 // b.dart |
| 1208 { |
| 1209 _computeResult(sourceB, IMPORT_EXPORT_SOURCE_CLOSURE); |
| 1210 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| 1211 List<Source> closure = outputs[IMPORT_EXPORT_SOURCE_CLOSURE]; |
| 1212 expect(closure, contains(sourceA)); |
| 1213 expect(closure, contains(sourceB)); |
| 1214 expect(closure, contains(coreSource)); |
| 1215 } |
| 1216 } |
| 1217 |
| 1184 test_perform_isClient_false() { | 1218 test_perform_isClient_false() { |
| 1185 Source sourceA = newSource('/a.dart', ''' | 1219 Source sourceA = newSource('/a.dart', ''' |
| 1186 library lib_a; | 1220 library lib_a; |
| 1187 import 'b.dart'; | 1221 import 'b.dart'; |
| 1188 '''); | 1222 '''); |
| 1189 newSource('/b.dart', ''' | 1223 newSource('/b.dart', ''' |
| 1190 library lib_b; | 1224 library lib_b; |
| 1191 '''); | 1225 '''); |
| 1192 _computeResult(sourceA, IS_CLIENT); | 1226 _computeResult(sourceA, IS_CLIENT); |
| 1193 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); | 1227 expect(task, new isInstanceOf<BuildSourceClosuresTask>()); |
| (...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); | 2164 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); |
| 2131 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 2165 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 2132 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | 2166 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 2133 expect(outputs[INCLUDED_PARTS], hasLength(0)); | 2167 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 2134 expect(outputs[PARSE_ERRORS], hasLength(0)); | 2168 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 2135 expect(outputs[PARSED_UNIT], isNotNull); | 2169 expect(outputs[PARSED_UNIT], isNotNull); |
| 2136 expect(outputs[SOURCE_KIND], SourceKind.PART); | 2170 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 2137 expect(outputs[UNITS], hasLength(1)); | 2171 expect(outputs[UNITS], hasLength(1)); |
| 2138 } | 2172 } |
| 2139 | 2173 |
| 2140 test_perform_computeSourceKind_noDirectives_noContainingLibraries() { | |
| 2141 _performParseTask(''); | |
| 2142 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | |
| 2143 } | |
| 2144 | |
| 2145 test_perform_computeSourceKind_noDirectives_hasContainingLibraries() { | 2174 test_perform_computeSourceKind_noDirectives_hasContainingLibraries() { |
| 2146 // Parse "lib.dart" to let the context know that "test.dart" is a part. | 2175 // Parse "lib.dart" to let the context know that "test.dart" is a part. |
| 2147 _computeResult(newSource('/lib.dart', r''' | 2176 _computeResult(newSource('/lib.dart', r''' |
| 2148 library lib; | 2177 library lib; |
| 2149 part 'test.dart'; | 2178 part 'test.dart'; |
| 2150 '''), PARSED_UNIT); | 2179 '''), PARSED_UNIT); |
| 2151 // So, know "test.dat" is parsed as a part. | 2180 // So, know "test.dat" is parsed as a part. |
| 2152 _performParseTask(''); | 2181 _performParseTask(''); |
| 2153 expect(outputs[SOURCE_KIND], SourceKind.PART); | 2182 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 2154 } | 2183 } |
| 2155 | 2184 |
| 2185 test_perform_computeSourceKind_noDirectives_noContainingLibraries() { |
| 2186 _performParseTask(''); |
| 2187 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 2188 } |
| 2189 |
| 2156 test_perform_doesNotExist() { | 2190 test_perform_doesNotExist() { |
| 2157 _performParseTask(null); | 2191 _performParseTask(null); |
| 2158 expect(outputs, hasLength(8)); | 2192 expect(outputs, hasLength(8)); |
| 2159 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); | 2193 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); |
| 2160 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 2194 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 2161 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | 2195 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 2162 expect(outputs[INCLUDED_PARTS], hasLength(0)); | 2196 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 2163 expect(outputs[PARSE_ERRORS], hasLength(0)); | 2197 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 2164 expect(outputs[PARSED_UNIT], isNotNull); | 2198 expect(outputs[PARSED_UNIT], isNotNull); |
| 2165 expect(outputs[SOURCE_KIND], SourceKind.UNKNOWN); | 2199 expect(outputs[SOURCE_KIND], SourceKind.UNKNOWN); |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2319 } | 2353 } |
| 2320 '''); | 2354 '''); |
| 2321 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); | 2355 LibrarySpecificUnit target = new LibrarySpecificUnit(source, source); |
| 2322 _computeResult(target, RESOLVED_UNIT6); | 2356 _computeResult(target, RESOLVED_UNIT6); |
| 2323 expect(task, new isInstanceOf<ResolveReferencesTask>()); | 2357 expect(task, new isInstanceOf<ResolveReferencesTask>()); |
| 2324 // validate | 2358 // validate |
| 2325 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); | 2359 _fillErrorListener(RESOLVE_REFERENCES_ERRORS); |
| 2326 errorListener.assertErrorsWithCodes( | 2360 errorListener.assertErrorsWithCodes( |
| 2327 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); | 2361 <ErrorCode>[StaticTypeWarningCode.UNDEFINED_METHOD]); |
| 2328 } | 2362 } |
| 2363 |
| 2364 test_perform_importExport() { |
| 2365 newSource('/a.dart', ''' |
| 2366 library a; |
| 2367 class A<T> { |
| 2368 T m() {} |
| 2369 } |
| 2370 '''); |
| 2371 newSource('/b.dart', ''' |
| 2372 library b; |
| 2373 export 'a.dart'; |
| 2374 '''); |
| 2375 Source sourceC = newSource('/c.dart', ''' |
| 2376 library c; |
| 2377 import 'b.dart'; |
| 2378 main() { |
| 2379 new A<int>().m(); |
| 2380 } |
| 2381 '''); |
| 2382 _computeResult(new LibrarySpecificUnit(sourceC, sourceC), RESOLVED_UNIT6); |
| 2383 expect(task, new isInstanceOf<ResolveReferencesTask>()); |
| 2384 // validate |
| 2385 CompilationUnit unit = outputs[RESOLVED_UNIT6]; |
| 2386 expect(unit, isNotNull); |
| 2387 { |
| 2388 FunctionDeclaration functionDeclaration = unit.declarations[0]; |
| 2389 BlockFunctionBody body = functionDeclaration.functionExpression.body; |
| 2390 List<Statement> statements = body.block.statements; |
| 2391 ExpressionStatement statement = statements[0]; |
| 2392 MethodInvocation invocation = statement.expression; |
| 2393 MethodElement methodElement = invocation.methodName.staticElement; |
| 2394 expect(methodElement, isNotNull); |
| 2395 expect(methodElement.type, isNotNull); |
| 2396 expect(methodElement.returnType.toString(), 'int'); |
| 2397 } |
| 2398 } |
| 2329 } | 2399 } |
| 2330 | 2400 |
| 2331 @reflectiveTest | 2401 @reflectiveTest |
| 2332 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { | 2402 class ResolveUnitTypeNamesTaskTest extends _AbstractDartTaskTest { |
| 2333 test_perform() { | 2403 test_perform() { |
| 2334 Source source = newSource('/test.dart', ''' | 2404 Source source = newSource('/test.dart', ''' |
| 2335 class A {} | 2405 class A {} |
| 2336 class B extends A {} | 2406 class B extends A {} |
| 2337 int f(String p) => p.length; | 2407 int f(String p) => p.length; |
| 2338 '''); | 2408 '''); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2564 /** | 2634 /** |
| 2565 * Fill [errorListener] with [result] errors in the current [task]. | 2635 * Fill [errorListener] with [result] errors in the current [task]. |
| 2566 */ | 2636 */ |
| 2567 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 2637 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 2568 List<AnalysisError> errors = task.outputs[result]; | 2638 List<AnalysisError> errors = task.outputs[result]; |
| 2569 expect(errors, isNotNull, reason: result.name); | 2639 expect(errors, isNotNull, reason: result.name); |
| 2570 errorListener = new GatheringErrorListener(); | 2640 errorListener = new GatheringErrorListener(); |
| 2571 errorListener.addAll(errors); | 2641 errorListener.addAll(errors); |
| 2572 } | 2642 } |
| 2573 } | 2643 } |
| OLD | NEW |