| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.context.context_test; | 5 library test.src.context.context_test; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/cancelable_future.dart'; | 9 import 'package:analyzer/src/cancelable_future.dart'; |
| 10 import 'package:analyzer/src/context/cache.dart'; | 10 import 'package:analyzer/src/context/cache.dart'; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 class AnalysisContextImplTest extends AbstractContextTest { | 52 class AnalysisContextImplTest extends AbstractContextTest { |
| 53 void fail_applyChanges_empty() { | 53 void fail_applyChanges_empty() { |
| 54 context.applyChanges(new ChangeSet()); | 54 context.applyChanges(new ChangeSet()); |
| 55 expect(context.performAnalysisTask().changeNotices, isNull); | 55 expect(context.performAnalysisTask().changeNotices, isNull); |
| 56 // This test appears to be flaky. If it is named "test_" it fails, if it's | 56 // This test appears to be flaky. If it is named "test_" it fails, if it's |
| 57 // named "fail_" it doesn't fail. I'm guessing that it's dependent on | 57 // named "fail_" it doesn't fail. I'm guessing that it's dependent on |
| 58 // whether some other test is run. | 58 // whether some other test is run. |
| 59 fail('Should have failed'); | 59 fail('Should have failed'); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void fail_applyChanges_overriddenSource() { | 62 void test_applyChanges_overriddenSource() { |
| 63 // Note: addSource adds the source to the contentCache. | 63 // Note: addSource adds the source to the contentCache. |
| 64 Source source = addSource("/test.dart", "library test;"); | 64 Source source = addSource("/test.dart", "library test;"); |
| 65 context.computeErrors(source); | 65 context.computeErrors(source); |
| 66 while (!context.sourcesNeedingProcessing.isEmpty) { | 66 while (!context.sourcesNeedingProcessing.isEmpty) { |
| 67 context.performAnalysisTask(); | 67 context.performAnalysisTask(); |
| 68 } | 68 } |
| 69 // Adding the source as a changedSource should have no effect since | 69 // Adding the source as a changedSource should have no effect since |
| 70 // it is already overridden in the content cache. | 70 // it is already overridden in the content cache. |
| 71 ChangeSet changeSet = new ChangeSet(); | 71 ChangeSet changeSet = new ChangeSet(); |
| 72 changeSet.changedSource(source); | 72 changeSet.changedSource(source); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 return pumpEventQueue().then((_) { | 133 return pumpEventQueue().then((_) { |
| 134 listener.assertEvent(wereSourcesAdded: true); | 134 listener.assertEvent(wereSourcesAdded: true); |
| 135 listener.assertEvent(changedSources: [libA]); | 135 listener.assertEvent(changedSources: [libA]); |
| 136 listener.assertEvent(wereSourcesAdded: true); | 136 listener.assertEvent(wereSourcesAdded: true); |
| 137 listener.assertEvent(changedSources: [libB]); | 137 listener.assertEvent(changedSources: [libB]); |
| 138 listener.assertEvent(wereSourcesRemovedOrDeleted: true); | 138 listener.assertEvent(wereSourcesRemovedOrDeleted: true); |
| 139 listener.assertNoMoreEvents(); | 139 listener.assertNoMoreEvents(); |
| 140 }); | 140 }); |
| 141 } | 141 } |
| 142 | 142 |
| 143 void fail_computeErrors_dart_none() { | 143 void test_computeErrors_dart_none() { |
| 144 Source source = addSource("/lib.dart", "library lib;"); | 144 Source source = addSource("/lib.dart", "library lib;"); |
| 145 List<AnalysisError> errors = context.computeErrors(source); | 145 List<AnalysisError> errors = context.computeErrors(source); |
| 146 expect(errors, hasLength(0)); | 146 expect(errors, hasLength(0)); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void fail_computeErrors_dart_part() { | 149 void test_computeErrors_dart_part() { |
| 150 Source librarySource = | 150 Source librarySource = |
| 151 addSource("/lib.dart", "library lib; part 'part.dart';"); | 151 addSource("/lib.dart", "library lib; part 'part.dart';"); |
| 152 Source partSource = addSource("/part.dart", "part of 'lib';"); | 152 Source partSource = addSource("/part.dart", "part of 'lib';"); |
| 153 context.parseCompilationUnit(librarySource); | 153 context.parseCompilationUnit(librarySource); |
| 154 List<AnalysisError> errors = context.computeErrors(partSource); | 154 List<AnalysisError> errors = context.computeErrors(partSource); |
| 155 expect(errors, isNotNull); | 155 expect(errors, isNotNull); |
| 156 expect(errors.length > 0, isTrue); | 156 expect(errors.length > 0, isTrue); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void fail_computeErrors_dart_some() { | 159 void test_computeErrors_dart_some() { |
| 160 Source source = addSource("/lib.dart", "library 'lib';"); | 160 Source source = addSource("/lib.dart", "library 'lib';"); |
| 161 List<AnalysisError> errors = context.computeErrors(source); | 161 List<AnalysisError> errors = context.computeErrors(source); |
| 162 expect(errors, isNotNull); | 162 expect(errors, isNotNull); |
| 163 expect(errors.length > 0, isTrue); | 163 expect(errors.length > 0, isTrue); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void fail_computeErrors_html_none() { | 166 void fail_computeErrors_html_none() { |
| 167 Source source = addSource("/test.html", "<html></html>"); | 167 Source source = addSource("/test.html", "<html></html>"); |
| 168 List<AnalysisError> errors = context.computeErrors(source); | 168 List<AnalysisError> errors = context.computeErrors(source); |
| 169 expect(errors, hasLength(0)); | 169 expect(errors, hasLength(0)); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 void test_getElement_enum() { | 305 void test_getElement_enum() { |
| 306 Source source = addSource('/test.dart', 'enum MyEnum {A, B, C}'); | 306 Source source = addSource('/test.dart', 'enum MyEnum {A, B, C}'); |
| 307 _analyzeAll_assertFinished(); | 307 _analyzeAll_assertFinished(); |
| 308 LibraryElement library = context.computeLibraryElement(source); | 308 LibraryElement library = context.computeLibraryElement(source); |
| 309 ClassElement myEnum = library.definingCompilationUnit.getEnum('MyEnum'); | 309 ClassElement myEnum = library.definingCompilationUnit.getEnum('MyEnum'); |
| 310 ElementLocation location = myEnum.location; | 310 ElementLocation location = myEnum.location; |
| 311 Element element = context.getElement(location); | 311 Element element = context.getElement(location); |
| 312 expect(element, same(myEnum)); | 312 expect(element, same(myEnum)); |
| 313 } | 313 } |
| 314 | 314 |
| 315 void fail_getErrors_dart_none() { | 315 void test_getErrors_dart_none() { |
| 316 Source source = addSource("/lib.dart", "library lib;"); | 316 Source source = addSource("/lib.dart", "library lib;"); |
| 317 var errorInfo = context.getErrors(source); | 317 var errorInfo = context.getErrors(source); |
| 318 expect(errorInfo, isNotNull); | 318 expect(errorInfo, isNotNull); |
| 319 List<AnalysisError> errors = errorInfo.errors; | 319 List<AnalysisError> errors = errorInfo.errors; |
| 320 expect(errors, hasLength(0)); | 320 expect(errors, hasLength(0)); |
| 321 context.computeErrors(source); | 321 context.computeErrors(source); |
| 322 errors = errorInfo.errors; | 322 errors = errorInfo.errors; |
| 323 expect(errors, hasLength(0)); | 323 expect(errors, hasLength(0)); |
| 324 } | 324 } |
| 325 | 325 |
| 326 void fail_getErrors_dart_some() { | 326 void test_getErrors_dart_some() { |
| 327 Source source = addSource("/lib.dart", "library 'lib';"); | 327 Source source = addSource("/lib.dart", "library 'lib';"); |
| 328 var errorInfo = context.getErrors(source); | 328 var errorInfo = context.getErrors(source); |
| 329 expect(errorInfo, isNotNull); | 329 expect(errorInfo, isNotNull); |
| 330 List<AnalysisError> errors = errorInfo.errors; | 330 List<AnalysisError> errors = errorInfo.errors; |
| 331 expect(errors, hasLength(0)); | 331 expect(errors, hasLength(0)); |
| 332 context.computeErrors(source); | 332 errors = context.computeErrors(source); |
| 333 errors = errorInfo.errors; | |
| 334 expect(errors, hasLength(1)); | 333 expect(errors, hasLength(1)); |
| 335 } | 334 } |
| 336 | 335 |
| 337 void fail_getErrors_html_none() { | 336 void test_getErrors_html_none() { |
| 338 Source source = addSource("/test.html", "<html></html>"); | 337 Source source = addSource("/test.html", "<html></html>"); |
| 339 AnalysisErrorInfo errorInfo = context.getErrors(source); | 338 AnalysisErrorInfo errorInfo = context.getErrors(source); |
| 340 expect(errorInfo, isNotNull); | 339 expect(errorInfo, isNotNull); |
| 341 List<AnalysisError> errors = errorInfo.errors; | 340 List<AnalysisError> errors = errorInfo.errors; |
| 342 expect(errors, hasLength(0)); | 341 expect(errors, hasLength(0)); |
| 343 context.computeErrors(source); | 342 context.computeErrors(source); |
| 344 errors = errorInfo.errors; | 343 errors = errorInfo.errors; |
| 345 expect(errors, hasLength(0)); | 344 expect(errors, hasLength(0)); |
| 346 } | 345 } |
| 347 | 346 |
| (...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2040 : super(name, UriKind.FILE_URI); | 2039 : super(name, UriKind.FILE_URI); |
| 2041 | 2040 |
| 2042 @override | 2041 @override |
| 2043 TimestampedData<String> get contents { | 2042 TimestampedData<String> get contents { |
| 2044 throw 'Read error'; | 2043 throw 'Read error'; |
| 2045 } | 2044 } |
| 2046 | 2045 |
| 2047 @override | 2046 @override |
| 2048 bool exists() => true; | 2047 bool exists() => true; |
| 2049 } | 2048 } |
| OLD | NEW |