| 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 2153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2164 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); | 2164 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); |
| 2165 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 2165 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 2166 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | 2166 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 2167 expect(outputs[INCLUDED_PARTS], hasLength(0)); | 2167 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 2168 expect(outputs[PARSE_ERRORS], hasLength(0)); | 2168 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 2169 expect(outputs[PARSED_UNIT], isNotNull); | 2169 expect(outputs[PARSED_UNIT], isNotNull); |
| 2170 expect(outputs[SOURCE_KIND], SourceKind.PART); | 2170 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 2171 expect(outputs[UNITS], hasLength(1)); | 2171 expect(outputs[UNITS], hasLength(1)); |
| 2172 } | 2172 } |
| 2173 | 2173 |
| 2174 test_perform_computeSourceKind_noDirectives_hasContainingLibraries() { | 2174 test_perform_computeSourceKind_noDirectives_hasContainingLibrary() { |
| 2175 // 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 included. |
| 2176 _computeResult(newSource('/lib.dart', r''' | 2176 _computeResult(newSource('/lib.dart', r''' |
| 2177 library lib; | 2177 library lib; |
| 2178 part 'test.dart'; | 2178 part 'test.dart'; |
| 2179 '''), PARSED_UNIT); | 2179 '''), PARSED_UNIT); |
| 2180 // So, know "test.dat" is parsed as a part. | 2180 // If there are no the "part of" directive, then it is not a part. |
| 2181 _performParseTask(''); | |
| 2182 expect(outputs[SOURCE_KIND], SourceKind.PART); | |
| 2183 } | |
| 2184 | |
| 2185 test_perform_computeSourceKind_noDirectives_noContainingLibraries() { | |
| 2186 _performParseTask(''); | 2181 _performParseTask(''); |
| 2187 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 2182 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 2188 } | 2183 } |
| 2184 |
| 2185 test_perform_computeSourceKind_noDirectives_noContainingLibrary() { |
| 2186 _performParseTask(''); |
| 2187 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 2188 } |
| 2189 | 2189 |
| 2190 test_perform_doesNotExist() { | 2190 test_perform_doesNotExist() { |
| 2191 _performParseTask(null); | 2191 _performParseTask(null); |
| 2192 expect(outputs, hasLength(8)); | 2192 expect(outputs, hasLength(8)); |
| 2193 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); | 2193 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); |
| 2194 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 2194 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 2195 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | 2195 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 2196 expect(outputs[INCLUDED_PARTS], hasLength(0)); | 2196 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 2197 expect(outputs[PARSE_ERRORS], hasLength(0)); | 2197 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 2198 expect(outputs[PARSED_UNIT], isNotNull); | 2198 expect(outputs[PARSED_UNIT], isNotNull); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2230 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); | 2230 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); |
| 2231 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); | 2231 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); |
| 2232 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | 2232 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 2233 expect(outputs[INCLUDED_PARTS], hasLength(1)); | 2233 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 2234 expect(outputs[PARSE_ERRORS], hasLength(1)); | 2234 expect(outputs[PARSE_ERRORS], hasLength(1)); |
| 2235 expect(outputs[PARSED_UNIT], isNotNull); | 2235 expect(outputs[PARSED_UNIT], isNotNull); |
| 2236 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 2236 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 2237 expect(outputs[UNITS], hasLength(2)); | 2237 expect(outputs[UNITS], hasLength(2)); |
| 2238 } | 2238 } |
| 2239 | 2239 |
| 2240 test_perform_part() { |
| 2241 _performParseTask(r''' |
| 2242 part of lib; |
| 2243 class B {}'''); |
| 2244 expect(outputs, hasLength(8)); |
| 2245 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); |
| 2246 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 2247 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 2248 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 2249 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 2250 expect(outputs[PARSED_UNIT], isNotNull); |
| 2251 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 2252 expect(outputs[UNITS], hasLength(1)); |
| 2253 } |
| 2254 |
| 2240 void _performParseTask(String content) { | 2255 void _performParseTask(String content) { |
| 2241 AnalysisTarget target = newSource('/test.dart', content); | 2256 AnalysisTarget target = newSource('/test.dart', content); |
| 2242 _computeResult(target, PARSED_UNIT); | 2257 _computeResult(target, PARSED_UNIT); |
| 2243 expect(task, new isInstanceOf<ParseDartTask>()); | 2258 expect(task, new isInstanceOf<ParseDartTask>()); |
| 2244 } | 2259 } |
| 2245 | 2260 |
| 2246 static void _assertHasCore(List<Source> sources, int lenght) { | 2261 static void _assertHasCore(List<Source> sources, int lenght) { |
| 2247 expect(sources, hasLength(lenght)); | 2262 expect(sources, hasLength(lenght)); |
| 2248 expect(sources, contains(predicate((Source s) { | 2263 expect(sources, contains(predicate((Source s) { |
| 2249 return s.fullName.endsWith('core.dart'); | 2264 return s.fullName.endsWith('core.dart'); |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2634 /** | 2649 /** |
| 2635 * Fill [errorListener] with [result] errors in the current [task]. | 2650 * Fill [errorListener] with [result] errors in the current [task]. |
| 2636 */ | 2651 */ |
| 2637 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 2652 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 2638 List<AnalysisError> errors = task.outputs[result]; | 2653 List<AnalysisError> errors = task.outputs[result]; |
| 2639 expect(errors, isNotNull, reason: result.name); | 2654 expect(errors, isNotNull, reason: result.name); |
| 2640 errorListener = new GatheringErrorListener(); | 2655 errorListener = new GatheringErrorListener(); |
| 2641 errorListener.addAll(errors); | 2656 errorListener.addAll(errors); |
| 2642 } | 2657 } |
| 2643 } | 2658 } |
| OLD | NEW |