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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 import '../../generated/test_support.dart'; | 42 import '../../generated/test_support.dart'; |
43 import '../../reflective_tests.dart'; | 43 import '../../reflective_tests.dart'; |
44 import 'abstract_context.dart'; | 44 import 'abstract_context.dart'; |
45 | 45 |
46 main() { | 46 main() { |
47 groupSep = ' | '; | 47 groupSep = ' | '; |
48 runReflectiveTests(AnalysisContextImplTest); | 48 runReflectiveTests(AnalysisContextImplTest); |
49 } | 49 } |
50 | 50 |
51 @reflectiveTest | 51 @reflectiveTest |
52 class AnalysisContextImplTest extends AbstractContextTest { | 52 class AnalysisContextImplTest extends AbstractContextTest { |
Brian Wilkerson
2015/05/11 13:59:20
I wish you hadn't sorted this file. There's no rea
| |
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 test_applyChanges_overriddenSource() { | |
63 // Note: addSource adds the source to the contentCache. | |
64 Source source = addSource("/test.dart", "library test;"); | |
65 context.computeErrors(source); | |
66 while (!context.sourcesNeedingProcessing.isEmpty) { | |
67 context.performAnalysisTask(); | |
68 } | |
69 // Adding the source as a changedSource should have no effect since | |
70 // it is already overridden in the content cache. | |
71 ChangeSet changeSet = new ChangeSet(); | |
72 changeSet.changedSource(source); | |
73 context.applyChanges(changeSet); | |
74 expect(context.sourcesNeedingProcessing, hasLength(0)); | |
75 } | |
76 | |
77 Future fail_applyChanges_remove() { | 62 Future fail_applyChanges_remove() { |
78 SourcesChangedListener listener = new SourcesChangedListener(); | 63 SourcesChangedListener listener = new SourcesChangedListener(); |
79 context.onSourcesChanged.listen(listener.onData); | 64 context.onSourcesChanged.listen(listener.onData); |
80 String libAContents = r''' | 65 String libAContents = r''' |
81 library libA; | 66 library libA; |
82 import 'libB.dart';'''; | 67 import 'libB.dart';'''; |
83 Source libA = addSource("/libA.dart", libAContents); | 68 Source libA = addSource("/libA.dart", libAContents); |
84 String libBContents = "library libB;"; | 69 String libBContents = "library libB;"; |
85 Source libB = addSource("/libB.dart", libBContents); | 70 Source libB = addSource("/libB.dart", libBContents); |
86 LibraryElement libAElement = context.computeLibraryElement(libA); | 71 LibraryElement libAElement = context.computeLibraryElement(libA); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 return pumpEventQueue().then((_) { | 118 return pumpEventQueue().then((_) { |
134 listener.assertEvent(wereSourcesAdded: true); | 119 listener.assertEvent(wereSourcesAdded: true); |
135 listener.assertEvent(changedSources: [libA]); | 120 listener.assertEvent(changedSources: [libA]); |
136 listener.assertEvent(wereSourcesAdded: true); | 121 listener.assertEvent(wereSourcesAdded: true); |
137 listener.assertEvent(changedSources: [libB]); | 122 listener.assertEvent(changedSources: [libB]); |
138 listener.assertEvent(wereSourcesRemovedOrDeleted: true); | 123 listener.assertEvent(wereSourcesRemovedOrDeleted: true); |
139 listener.assertNoMoreEvents(); | 124 listener.assertNoMoreEvents(); |
140 }); | 125 }); |
141 } | 126 } |
142 | 127 |
143 void test_computeErrors_dart_none() { | |
144 Source source = addSource("/lib.dart", "library lib;"); | |
145 List<AnalysisError> errors = context.computeErrors(source); | |
146 expect(errors, hasLength(0)); | |
147 } | |
148 | |
149 void test_computeErrors_dart_part() { | |
150 Source librarySource = | |
151 addSource("/lib.dart", "library lib; part 'part.dart';"); | |
152 Source partSource = addSource("/part.dart", "part of 'lib';"); | |
153 context.parseCompilationUnit(librarySource); | |
154 List<AnalysisError> errors = context.computeErrors(partSource); | |
155 expect(errors, isNotNull); | |
156 expect(errors.length > 0, isTrue); | |
157 } | |
158 | |
159 void test_computeErrors_dart_some() { | |
160 Source source = addSource("/lib.dart", "library 'lib';"); | |
161 List<AnalysisError> errors = context.computeErrors(source); | |
162 expect(errors, isNotNull); | |
163 expect(errors.length > 0, isTrue); | |
164 } | |
165 | |
166 void fail_computeErrors_html_none() { | 128 void fail_computeErrors_html_none() { |
167 Source source = addSource("/test.html", "<html></html>"); | 129 Source source = addSource("/test.html", "<html></html>"); |
168 List<AnalysisError> errors = context.computeErrors(source); | 130 List<AnalysisError> errors = context.computeErrors(source); |
169 expect(errors, hasLength(0)); | 131 expect(errors, hasLength(0)); |
170 } | 132 } |
171 | 133 |
172 void fail_computeHtmlElement_valid() { | 134 void fail_computeHtmlElement_valid() { |
173 Source source = addSource("/test.html", "<html></html>"); | 135 Source source = addSource("/test.html", "<html></html>"); |
174 HtmlElement element = context.computeHtmlElement(source); | 136 HtmlElement element = context.computeHtmlElement(source); |
175 expect(element, isNotNull); | 137 expect(element, isNotNull); |
176 expect(context.computeHtmlElement(source), same(element)); | 138 expect(context.computeHtmlElement(source), same(element)); |
177 } | 139 } |
178 | 140 |
179 void test_computeImportedLibraries_none() { | |
180 Source source = addSource("/test.dart", "library test;"); | |
181 expect(context.computeImportedLibraries(source), hasLength(0)); | |
182 } | |
183 | |
184 void test_computeImportedLibraries_some() { | |
185 Source source = addSource( | |
186 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); | |
187 expect(context.computeImportedLibraries(source), hasLength(2)); | |
188 } | |
189 | |
190 void fail_computeResolvableCompilationUnit_dart_exception() { | 141 void fail_computeResolvableCompilationUnit_dart_exception() { |
191 TestSource source = _addSourceWithException("/test.dart"); | 142 TestSource source = _addSourceWithException("/test.dart"); |
192 try { | 143 try { |
193 context.computeResolvableCompilationUnit(source); | 144 context.computeResolvableCompilationUnit(source); |
194 fail("Expected AnalysisException"); | 145 fail("Expected AnalysisException"); |
195 } on AnalysisException { | 146 } on AnalysisException { |
196 // Expected | 147 // Expected |
197 } | 148 } |
198 } | 149 } |
199 | 150 |
(...skipping 10 matching lines...) Expand all Loading... | |
210 void fail_computeResolvableCompilationUnit_valid() { | 161 void fail_computeResolvableCompilationUnit_valid() { |
211 Source source = addSource("/lib.dart", "library lib;"); | 162 Source source = addSource("/lib.dart", "library lib;"); |
212 CompilationUnit parsedUnit = context.parseCompilationUnit(source); | 163 CompilationUnit parsedUnit = context.parseCompilationUnit(source); |
213 expect(parsedUnit, isNotNull); | 164 expect(parsedUnit, isNotNull); |
214 CompilationUnit resolvedUnit = | 165 CompilationUnit resolvedUnit = |
215 context.computeResolvableCompilationUnit(source); | 166 context.computeResolvableCompilationUnit(source); |
216 expect(resolvedUnit, isNotNull); | 167 expect(resolvedUnit, isNotNull); |
217 expect(resolvedUnit, same(parsedUnit)); | 168 expect(resolvedUnit, same(parsedUnit)); |
218 } | 169 } |
219 | 170 |
171 Future fail_computeResolvedCompilationUnitAsync_afterDispose() { | |
172 Source source = addSource("/lib.dart", "library lib;"); | |
173 // Complete all pending analysis tasks and flush the AST so that it won't | |
174 // be available immediately. | |
175 _performPendingAnalysisTasks(); | |
176 _flushAst(source); | |
177 // Dispose of the context. | |
178 context.dispose(); | |
179 // Any attempt to start an asynchronous computation should return a future | |
180 // which completes with error. | |
181 CancelableFuture<CompilationUnit> future = | |
182 context.computeResolvedCompilationUnitAsync(source, source); | |
183 bool completed = false; | |
184 future.then((CompilationUnit unit) { | |
185 fail('Future should have completed with error'); | |
186 }, onError: (error) { | |
187 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); | |
188 completed = true; | |
189 }); | |
190 return pumpEventQueue().then((_) { | |
191 expect(completed, isTrue); | |
192 }); | |
193 } | |
194 | |
220 Future fail_computeResolvedCompilationUnitAsync_dispose() { | 195 Future fail_computeResolvedCompilationUnitAsync_dispose() { |
221 Source source = addSource("/lib.dart", "library lib;"); | 196 Source source = addSource("/lib.dart", "library lib;"); |
222 // Complete all pending analysis tasks and flush the AST so that it won't | 197 // Complete all pending analysis tasks and flush the AST so that it won't |
223 // be available immediately. | 198 // be available immediately. |
224 _performPendingAnalysisTasks(); | 199 _performPendingAnalysisTasks(); |
225 _flushAst(source); | 200 _flushAst(source); |
226 CancelableFuture<CompilationUnit> future = | 201 CancelableFuture<CompilationUnit> future = |
227 context.computeResolvedCompilationUnitAsync(source, source); | 202 context.computeResolvedCompilationUnitAsync(source, source); |
228 bool completed = false; | 203 bool completed = false; |
229 future.then((CompilationUnit unit) { | 204 future.then((CompilationUnit unit) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 _performPendingAnalysisTasks(); | 236 _performPendingAnalysisTasks(); |
262 }).then((_) => pumpEventQueue()).then((_) { | 237 }).then((_) => pumpEventQueue()).then((_) { |
263 expect(completed, isTrue); | 238 expect(completed, isTrue); |
264 }); | 239 }); |
265 } | 240 } |
266 | 241 |
267 void fail_extractContext() { | 242 void fail_extractContext() { |
268 fail("Implement this"); | 243 fail("Implement this"); |
269 } | 244 } |
270 | 245 |
271 void test_getElement_constructor_named() { | |
272 Source source = addSource("/lib.dart", r''' | |
273 class A { | |
274 A.named() {} | |
275 }'''); | |
276 _analyzeAll_assertFinished(); | |
277 LibraryElement library = context.computeLibraryElement(source); | |
278 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); | |
279 ConstructorElement constructor = classA.constructors[0]; | |
280 ElementLocation location = constructor.location; | |
281 Element element = context.getElement(location); | |
282 expect(element, same(constructor)); | |
283 } | |
284 | |
285 void test_getElement_constructor_unnamed() { | |
286 Source source = addSource("/lib.dart", r''' | |
287 class A { | |
288 A() {} | |
289 }'''); | |
290 _analyzeAll_assertFinished(); | |
291 LibraryElement library = context.computeLibraryElement(source); | |
292 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); | |
293 ConstructorElement constructor = classA.constructors[0]; | |
294 ElementLocation location = constructor.location; | |
295 Element element = context.getElement(location); | |
296 expect(element, same(constructor)); | |
297 } | |
298 | |
299 void test_getElement_enum() { | |
300 Source source = addSource('/test.dart', 'enum MyEnum {A, B, C}'); | |
301 _analyzeAll_assertFinished(); | |
302 LibraryElement library = context.computeLibraryElement(source); | |
303 ClassElement myEnum = library.definingCompilationUnit.getEnum('MyEnum'); | |
304 ElementLocation location = myEnum.location; | |
305 Element element = context.getElement(location); | |
306 expect(element, same(myEnum)); | |
307 } | |
308 | |
309 void test_getErrors_dart_none() { | |
310 Source source = addSource("/lib.dart", "library lib;"); | |
311 var errorInfo = context.getErrors(source); | |
312 expect(errorInfo, isNotNull); | |
313 List<AnalysisError> errors = errorInfo.errors; | |
314 expect(errors, hasLength(0)); | |
315 context.computeErrors(source); | |
316 errors = errorInfo.errors; | |
317 expect(errors, hasLength(0)); | |
318 } | |
319 | |
320 void test_getErrors_dart_some() { | |
321 Source source = addSource("/lib.dart", "library 'lib';"); | |
322 var errorInfo = context.getErrors(source); | |
323 expect(errorInfo, isNotNull); | |
324 List<AnalysisError> errors = errorInfo.errors; | |
325 expect(errors, hasLength(0)); | |
326 errors = context.computeErrors(source); | |
327 expect(errors, hasLength(1)); | |
328 } | |
329 | |
330 void test_getErrors_html_none() { | |
331 Source source = addSource("/test.html", "<html></html>"); | |
332 AnalysisErrorInfo errorInfo = context.getErrors(source); | |
333 expect(errorInfo, isNotNull); | |
334 List<AnalysisError> errors = errorInfo.errors; | |
335 expect(errors, hasLength(0)); | |
336 context.computeErrors(source); | |
337 errors = errorInfo.errors; | |
338 expect(errors, hasLength(0)); | |
339 } | |
340 | |
341 void fail_getErrors_html_some() { | 246 void fail_getErrors_html_some() { |
342 Source source = addSource("/test.html", r''' | 247 Source source = addSource("/test.html", r''' |
343 <html><head> | 248 <html><head> |
344 <script type='application/dart' src='test.dart'/> | 249 <script type='application/dart' src='test.dart'/> |
345 </head></html>'''); | 250 </head></html>'''); |
346 AnalysisErrorInfo errorInfo = context.getErrors(source); | 251 AnalysisErrorInfo errorInfo = context.getErrors(source); |
347 expect(errorInfo, isNotNull); | 252 expect(errorInfo, isNotNull); |
348 List<AnalysisError> errors = errorInfo.errors; | 253 List<AnalysisError> errors = errorInfo.errors; |
349 expect(errors, hasLength(0)); | 254 expect(errors, hasLength(0)); |
350 context.computeErrors(source); | 255 context.computeErrors(source); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 <script type='application/dart' src='test.js'/> | 316 <script type='application/dart' src='test.js'/> |
412 </head></html>'''); | 317 </head></html>'''); |
413 Source librarySource = addSource("/test.dart", "library lib;"); | 318 Source librarySource = addSource("/test.dart", "library lib;"); |
414 context.computeLibraryElement(librarySource); | 319 context.computeLibraryElement(librarySource); |
415 context.parseHtmlUnit(htmlSource); | 320 context.parseHtmlUnit(htmlSource); |
416 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource); | 321 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource); |
417 expect(result, hasLength(1)); | 322 expect(result, hasLength(1)); |
418 expect(result[0], librarySource); | 323 expect(result[0], librarySource); |
419 } | 324 } |
420 | 325 |
421 void test_getResolvedCompilationUnit_library() { | |
422 Source source = addSource("/lib.dart", "library libb;"); | |
423 LibraryElement library = context.computeLibraryElement(source); | |
424 context.computeErrors(source); // Force the resolved unit to be built. | |
425 expect(context.getResolvedCompilationUnit(source, library), isNotNull); | |
426 context.setContents(source, "library lib;"); | |
427 expect(context.getResolvedCompilationUnit(source, library), isNull); | |
428 } | |
429 | |
430 void fail_getResolvedHtmlUnit() { | 326 void fail_getResolvedHtmlUnit() { |
431 Source source = addSource("/test.html", "<html></html>"); | 327 Source source = addSource("/test.html", "<html></html>"); |
432 expect(context.getResolvedHtmlUnit(source), isNull); | 328 expect(context.getResolvedHtmlUnit(source), isNull); |
433 context.resolveHtmlUnit(source); | 329 context.resolveHtmlUnit(source); |
434 expect(context.getResolvedHtmlUnit(source), isNotNull); | 330 expect(context.getResolvedHtmlUnit(source), isNotNull); |
435 } | 331 } |
436 | 332 |
437 void fail_mergeContext() { | 333 void fail_mergeContext() { |
438 fail("Implement this"); | 334 fail("Implement this"); |
439 } | 335 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 // add part and run all tasks | 376 // add part and run all tasks |
481 Source partSource = addSource("/part.dart", r''' | 377 Source partSource = addSource("/part.dart", r''' |
482 part of lib; | 378 part of lib; |
483 '''); | 379 '''); |
484 _analyzeAll_assertFinished(); | 380 _analyzeAll_assertFinished(); |
485 // "libSource" should be here | 381 // "libSource" should be here |
486 List<Source> librariesWithPart = context.getLibrariesContaining(partSource); | 382 List<Source> librariesWithPart = context.getLibrariesContaining(partSource); |
487 expect(librariesWithPart, unorderedEquals([libSource])); | 383 expect(librariesWithPart, unorderedEquals([libSource])); |
488 } | 384 } |
489 | 385 |
490 void fail_performAnalysisTask_changeLibraryContents() { | |
491 Source libSource = | |
492 addSource("/test.dart", "library lib; part 'test-part.dart';"); | |
493 Source partSource = addSource("/test-part.dart", "part of lib;"); | |
494 _analyzeAll_assertFinished(); | |
495 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
496 reason: "library resolved 1"); | |
497 expect( | |
498 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
499 reason: "part resolved 1"); | |
500 // update and analyze #1 | |
501 context.setContents(libSource, "library lib;"); | |
502 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
503 reason: "library changed 2"); | |
504 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
505 reason: "part changed 2"); | |
506 _analyzeAll_assertFinished(); | |
507 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
508 reason: "library resolved 2"); | |
509 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
510 reason: "part resolved 2"); | |
511 // update and analyze #2 | |
512 context.setContents(libSource, "library lib; part 'test-part.dart';"); | |
513 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
514 reason: "library changed 3"); | |
515 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
516 reason: "part changed 3"); | |
517 _analyzeAll_assertFinished(); | |
518 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
519 reason: "library resolved 2"); | |
520 expect( | |
521 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
522 reason: "part resolved 3"); | |
523 } | |
524 | |
525 void fail_performAnalysisTask_changeLibraryThenPartContents() { | |
526 Source libSource = | |
527 addSource("/test.dart", "library lib; part 'test-part.dart';"); | |
528 Source partSource = addSource("/test-part.dart", "part of lib;"); | |
529 _analyzeAll_assertFinished(); | |
530 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
531 reason: "library resolved 1"); | |
532 expect( | |
533 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
534 reason: "part resolved 1"); | |
535 // update and analyze #1 | |
536 context.setContents(libSource, "library lib;"); | |
537 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
538 reason: "library changed 2"); | |
539 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
540 reason: "part changed 2"); | |
541 _analyzeAll_assertFinished(); | |
542 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
543 reason: "library resolved 2"); | |
544 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
545 reason: "part resolved 2"); | |
546 // update and analyze #2 | |
547 context.setContents(partSource, "part of lib; // 1"); | |
548 // Assert that changing the part's content does not effect the library | |
549 // now that it is no longer part of that library | |
550 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
551 reason: "library changed 3"); | |
552 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
553 reason: "part changed 3"); | |
554 _analyzeAll_assertFinished(); | |
555 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
556 reason: "library resolved 3"); | |
557 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
558 reason: "part resolved 3"); | |
559 } | |
560 | |
561 void test_performAnalysisTask_changePartContents_makeItAPart() { | |
562 Source libSource = addSource("/lib.dart", r''' | |
563 library lib; | |
564 part 'part.dart'; | |
565 void f(x) {}'''); | |
566 Source partSource = addSource("/part.dart", "void g() { f(null); }"); | |
567 _analyzeAll_assertFinished(); | |
568 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
569 reason: "library resolved 1"); | |
570 expect( | |
571 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
572 reason: "part resolved 1"); | |
573 // update and analyze | |
574 context.setContents(partSource, r''' | |
575 part of lib; | |
576 void g() { f(null); }'''); | |
577 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
578 reason: "library changed 2"); | |
579 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
580 reason: "part changed 2"); | |
581 _analyzeAll_assertFinished(); | |
582 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
583 reason: "library resolved 2"); | |
584 expect( | |
585 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
586 reason: "part resolved 2"); | |
587 expect(context.getErrors(libSource).errors, hasLength(0)); | |
588 expect(context.getErrors(partSource).errors, hasLength(0)); | |
589 } | |
590 | |
591 /** | |
592 * https://code.google.com/p/dart/issues/detail?id=12424 | |
593 */ | |
594 void test_performAnalysisTask_changePartContents_makeItNotPart() { | |
595 Source libSource = addSource("/lib.dart", r''' | |
596 library lib; | |
597 part 'part.dart'; | |
598 void f(x) {}'''); | |
599 Source partSource = addSource("/part.dart", r''' | |
600 part of lib; | |
601 void g() { f(null); }'''); | |
602 _analyzeAll_assertFinished(); | |
603 expect(context.getErrors(libSource).errors, hasLength(0)); | |
604 expect(context.getErrors(partSource).errors, hasLength(0)); | |
605 // Remove 'part' directive, which should make "f(null)" an error. | |
606 context.setContents(partSource, r''' | |
607 //part of lib; | |
608 void g() { f(null); }'''); | |
609 _analyzeAll_assertFinished(); | |
610 expect(context.getErrors(libSource).errors.length != 0, isTrue); | |
611 } | |
612 | |
613 void test_performAnalysisTask_changePartContents_noSemanticChanges() { | |
614 Source libSource = | |
615 addSource("/test.dart", "library lib; part 'test-part.dart';"); | |
616 Source partSource = addSource("/test-part.dart", "part of lib;"); | |
617 _analyzeAll_assertFinished(); | |
618 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
619 reason: "library resolved 1"); | |
620 expect( | |
621 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
622 reason: "part resolved 1"); | |
623 // update and analyze #1 | |
624 context.setContents(partSource, "part of lib; // 1"); | |
625 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
626 reason: "library changed 2"); | |
627 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
628 reason: "part changed 2"); | |
629 _analyzeAll_assertFinished(); | |
630 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
631 reason: "library resolved 2"); | |
632 expect( | |
633 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
634 reason: "part resolved 2"); | |
635 // update and analyze #2 | |
636 context.setContents(partSource, "part of lib; // 12"); | |
637 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
638 reason: "library changed 3"); | |
639 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
640 reason: "part changed 3"); | |
641 _analyzeAll_assertFinished(); | |
642 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
643 reason: "library resolved 3"); | |
644 expect( | |
645 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
646 reason: "part resolved 3"); | |
647 } | |
648 | |
649 void fail_performAnalysisTask_getContentException_dart() { | 386 void fail_performAnalysisTask_getContentException_dart() { |
650 // add source that throw an exception on "get content" | 387 // add source that throw an exception on "get content" |
651 Source source = new _Source_getContent_throwException('test.dart'); | 388 Source source = new _Source_getContent_throwException('test.dart'); |
652 { | 389 { |
653 ChangeSet changeSet = new ChangeSet(); | 390 ChangeSet changeSet = new ChangeSet(); |
654 changeSet.addedSource(source); | 391 changeSet.addedSource(source); |
655 context.applyChanges(changeSet); | 392 context.applyChanges(changeSet); |
656 } | 393 } |
657 // prepare errors | 394 // prepare errors |
658 _analyzeAll_assertFinished(); | 395 _analyzeAll_assertFinished(); |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1082 changeSet2.addedSource(source2); | 819 changeSet2.addedSource(source2); |
1083 changeSet2.changedRange(source, 'library test;', 0, 0, 13); | 820 changeSet2.changedRange(source, 'library test;', 0, 0, 13); |
1084 context.applyChanges(changeSet2); | 821 context.applyChanges(changeSet2); |
1085 return pumpEventQueue().then((_) { | 822 return pumpEventQueue().then((_) { |
1086 listener.assertEvent(wereSourcesAdded: true); | 823 listener.assertEvent(wereSourcesAdded: true); |
1087 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); | 824 listener.assertEvent(wereSourcesAdded: true, changedSources: [source]); |
1088 listener.assertNoMoreEvents(); | 825 listener.assertNoMoreEvents(); |
1089 }); | 826 }); |
1090 } | 827 } |
1091 | 828 |
829 void test_applyChanges_overriddenSource() { | |
830 // Note: addSource adds the source to the contentCache. | |
831 Source source = addSource("/test.dart", "library test;"); | |
832 context.computeErrors(source); | |
833 while (!context.sourcesNeedingProcessing.isEmpty) { | |
834 context.performAnalysisTask(); | |
835 } | |
836 // Adding the source as a changedSource should have no effect since | |
837 // it is already overridden in the content cache. | |
838 ChangeSet changeSet = new ChangeSet(); | |
839 changeSet.changedSource(source); | |
840 context.applyChanges(changeSet); | |
841 expect(context.sourcesNeedingProcessing, hasLength(0)); | |
842 } | |
843 | |
1092 void test_computeDocumentationComment_block() { | 844 void test_computeDocumentationComment_block() { |
1093 String comment = "/** Comment */"; | 845 String comment = "/** Comment */"; |
1094 Source source = addSource("/test.dart", """ | 846 Source source = addSource("/test.dart", """ |
1095 $comment | 847 $comment |
1096 class A {}"""); | 848 class A {}"""); |
1097 LibraryElement libraryElement = context.computeLibraryElement(source); | 849 LibraryElement libraryElement = context.computeLibraryElement(source); |
1098 expect(libraryElement, isNotNull); | 850 expect(libraryElement, isNotNull); |
1099 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; | 851 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; |
1100 expect(libraryElement, isNotNull); | 852 expect(libraryElement, isNotNull); |
1101 expect(context.computeDocumentationComment(classElement), comment); | 853 expect(context.computeDocumentationComment(classElement), comment); |
(...skipping 27 matching lines...) Expand all Loading... | |
1129 String comment = "/// line 1\r\n/// line 2\r\n/// line 3\r\n"; | 881 String comment = "/// line 1\r\n/// line 2\r\n/// line 3\r\n"; |
1130 Source source = addSource("/test.dart", "${comment}class A {}"); | 882 Source source = addSource("/test.dart", "${comment}class A {}"); |
1131 LibraryElement libraryElement = context.computeLibraryElement(source); | 883 LibraryElement libraryElement = context.computeLibraryElement(source); |
1132 expect(libraryElement, isNotNull); | 884 expect(libraryElement, isNotNull); |
1133 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; | 885 ClassElement classElement = libraryElement.definingCompilationUnit.types[0]; |
1134 expect(libraryElement, isNotNull); | 886 expect(libraryElement, isNotNull); |
1135 String actual = context.computeDocumentationComment(classElement); | 887 String actual = context.computeDocumentationComment(classElement); |
1136 expect(actual, "/// line 1\n/// line 2\n/// line 3"); | 888 expect(actual, "/// line 1\n/// line 2\n/// line 3"); |
1137 } | 889 } |
1138 | 890 |
891 void test_computeErrors_dart_none() { | |
892 Source source = addSource("/lib.dart", "library lib;"); | |
893 List<AnalysisError> errors = context.computeErrors(source); | |
894 expect(errors, hasLength(0)); | |
895 } | |
896 | |
897 void test_computeErrors_dart_part() { | |
898 Source librarySource = | |
899 addSource("/lib.dart", "library lib; part 'part.dart';"); | |
900 Source partSource = addSource("/part.dart", "part of 'lib';"); | |
901 context.parseCompilationUnit(librarySource); | |
902 List<AnalysisError> errors = context.computeErrors(partSource); | |
903 expect(errors, isNotNull); | |
904 expect(errors.length > 0, isTrue); | |
905 } | |
906 | |
907 void test_computeErrors_dart_some() { | |
908 Source source = addSource("/lib.dart", "library 'lib';"); | |
909 List<AnalysisError> errors = context.computeErrors(source); | |
910 expect(errors, isNotNull); | |
911 expect(errors.length > 0, isTrue); | |
912 } | |
913 | |
1139 void test_computeExportedLibraries_none() { | 914 void test_computeExportedLibraries_none() { |
1140 Source source = addSource("/test.dart", "library test;"); | 915 Source source = addSource("/test.dart", "library test;"); |
1141 expect(context.computeExportedLibraries(source), hasLength(0)); | 916 expect(context.computeExportedLibraries(source), hasLength(0)); |
1142 } | 917 } |
1143 | 918 |
1144 void test_computeExportedLibraries_some() { | 919 void test_computeExportedLibraries_some() { |
1145 // addSource("/lib1.dart", "library lib1;"); | 920 // addSource("/lib1.dart", "library lib1;"); |
1146 // addSource("/lib2.dart", "library lib2;"); | 921 // addSource("/lib2.dart", "library lib2;"); |
1147 Source source = addSource( | 922 Source source = addSource( |
1148 "/test.dart", "library test; export 'lib1.dart'; export 'lib2.dart';"); | 923 "/test.dart", "library test; export 'lib1.dart'; export 'lib2.dart';"); |
1149 expect(context.computeExportedLibraries(source), hasLength(2)); | 924 expect(context.computeExportedLibraries(source), hasLength(2)); |
1150 } | 925 } |
1151 | 926 |
1152 void test_computeHtmlElement_nonHtml() { | 927 void test_computeHtmlElement_nonHtml() { |
1153 Source source = addSource("/test.dart", "library test;"); | 928 Source source = addSource("/test.dart", "library test;"); |
1154 expect(context.computeHtmlElement(source), isNull); | 929 expect(context.computeHtmlElement(source), isNull); |
1155 } | 930 } |
1156 | 931 |
932 void test_computeImportedLibraries_none() { | |
933 Source source = addSource("/test.dart", "library test;"); | |
934 expect(context.computeImportedLibraries(source), hasLength(0)); | |
935 } | |
936 | |
937 void test_computeImportedLibraries_some() { | |
938 Source source = addSource( | |
939 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); | |
940 expect(context.computeImportedLibraries(source), hasLength(2)); | |
941 } | |
942 | |
1157 void test_computeKindOf_html() { | 943 void test_computeKindOf_html() { |
1158 Source source = addSource("/test.html", ""); | 944 Source source = addSource("/test.html", ""); |
1159 expect(context.computeKindOf(source), same(SourceKind.HTML)); | 945 expect(context.computeKindOf(source), same(SourceKind.HTML)); |
1160 } | 946 } |
1161 | 947 |
1162 void test_computeKindOf_library() { | 948 void test_computeKindOf_library() { |
1163 Source source = addSource("/test.dart", "library lib;"); | 949 Source source = addSource("/test.dart", "library lib;"); |
1164 expect(context.computeKindOf(source), same(SourceKind.LIBRARY)); | 950 expect(context.computeKindOf(source), same(SourceKind.LIBRARY)); |
1165 } | 951 } |
1166 | 952 |
(...skipping 26 matching lines...) Expand all Loading... | |
1193 Source source = addSource("/test.html", r''' | 979 Source source = addSource("/test.html", r''' |
1194 <html> | 980 <html> |
1195 <body> | 981 <body> |
1196 <h1>A</h1> | 982 <h1>A</h1> |
1197 </body> | 983 </body> |
1198 </html>'''); | 984 </html>'''); |
1199 LineInfo info = context.computeLineInfo(source); | 985 LineInfo info = context.computeLineInfo(source); |
1200 expect(info, isNotNull); | 986 expect(info, isNotNull); |
1201 } | 987 } |
1202 | 988 |
1203 Future fail_computeResolvedCompilationUnitAsync_afterDispose() { | |
1204 Source source = addSource("/lib.dart", "library lib;"); | |
1205 // Complete all pending analysis tasks and flush the AST so that it won't | |
1206 // be available immediately. | |
1207 _performPendingAnalysisTasks(); | |
1208 _flushAst(source); | |
1209 // Dispose of the context. | |
1210 context.dispose(); | |
1211 // Any attempt to start an asynchronous computation should return a future | |
1212 // which completes with error. | |
1213 CancelableFuture<CompilationUnit> future = | |
1214 context.computeResolvedCompilationUnitAsync(source, source); | |
1215 bool completed = false; | |
1216 future.then((CompilationUnit unit) { | |
1217 fail('Future should have completed with error'); | |
1218 }, onError: (error) { | |
1219 expect(error, new isInstanceOf<AnalysisNotScheduledError>()); | |
1220 completed = true; | |
1221 }); | |
1222 return pumpEventQueue().then((_) { | |
1223 expect(completed, isTrue); | |
1224 }); | |
1225 } | |
1226 | |
1227 void test_dispose() { | 989 void test_dispose() { |
1228 expect(context.isDisposed, isFalse); | 990 expect(context.isDisposed, isFalse); |
1229 context.dispose(); | 991 context.dispose(); |
1230 expect(context.isDisposed, isTrue); | 992 expect(context.isDisposed, isTrue); |
1231 } | 993 } |
1232 | 994 |
1233 void test_exists_false() { | 995 void test_exists_false() { |
1234 TestSource source = new TestSource(); | 996 TestSource source = new TestSource(); |
1235 source.exists2 = false; | 997 source.exists2 = false; |
1236 expect(context.exists(source), isFalse); | 998 expect(context.exists(source), isFalse); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1288 context.computeLibraryElement(sourceFactory.forUri("dart:core")); | 1050 context.computeLibraryElement(sourceFactory.forUri("dart:core")); |
1289 expect(core, isNotNull); | 1051 expect(core, isNotNull); |
1290 ClassElement classObject = | 1052 ClassElement classObject = |
1291 _findClass(core.definingCompilationUnit, "Object"); | 1053 _findClass(core.definingCompilationUnit, "Object"); |
1292 expect(classObject, isNotNull); | 1054 expect(classObject, isNotNull); |
1293 ElementLocation location = classObject.location; | 1055 ElementLocation location = classObject.location; |
1294 Element element = context.getElement(location); | 1056 Element element = context.getElement(location); |
1295 expect(element, same(classObject)); | 1057 expect(element, same(classObject)); |
1296 } | 1058 } |
1297 | 1059 |
1060 void test_getElement_constructor_named() { | |
1061 Source source = addSource("/lib.dart", r''' | |
1062 class A { | |
1063 A.named() {} | |
1064 }'''); | |
1065 _analyzeAll_assertFinished(); | |
1066 LibraryElement library = context.computeLibraryElement(source); | |
1067 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); | |
1068 ConstructorElement constructor = classA.constructors[0]; | |
1069 ElementLocation location = constructor.location; | |
1070 Element element = context.getElement(location); | |
1071 expect(element, same(constructor)); | |
1072 } | |
1073 | |
1074 void test_getElement_constructor_unnamed() { | |
1075 Source source = addSource("/lib.dart", r''' | |
1076 class A { | |
1077 A() {} | |
1078 }'''); | |
1079 _analyzeAll_assertFinished(); | |
1080 LibraryElement library = context.computeLibraryElement(source); | |
1081 ClassElement classA = _findClass(library.definingCompilationUnit, "A"); | |
1082 ConstructorElement constructor = classA.constructors[0]; | |
1083 ElementLocation location = constructor.location; | |
1084 Element element = context.getElement(location); | |
1085 expect(element, same(constructor)); | |
1086 } | |
1087 | |
1088 void test_getElement_enum() { | |
1089 Source source = addSource('/test.dart', 'enum MyEnum {A, B, C}'); | |
1090 _analyzeAll_assertFinished(); | |
1091 LibraryElement library = context.computeLibraryElement(source); | |
1092 ClassElement myEnum = library.definingCompilationUnit.getEnum('MyEnum'); | |
1093 ElementLocation location = myEnum.location; | |
1094 Element element = context.getElement(location); | |
1095 expect(element, same(myEnum)); | |
1096 } | |
1097 | |
1098 void test_getErrors_dart_none() { | |
1099 Source source = addSource("/lib.dart", "library lib;"); | |
1100 var errorInfo = context.getErrors(source); | |
1101 expect(errorInfo, isNotNull); | |
1102 List<AnalysisError> errors = errorInfo.errors; | |
1103 expect(errors, hasLength(0)); | |
1104 context.computeErrors(source); | |
1105 errors = errorInfo.errors; | |
1106 expect(errors, hasLength(0)); | |
1107 } | |
1108 | |
1109 void test_getErrors_dart_some() { | |
1110 Source source = addSource("/lib.dart", "library 'lib';"); | |
1111 var errorInfo = context.getErrors(source); | |
1112 expect(errorInfo, isNotNull); | |
1113 List<AnalysisError> errors = errorInfo.errors; | |
1114 expect(errors, hasLength(0)); | |
1115 errors = context.computeErrors(source); | |
1116 expect(errors, hasLength(1)); | |
1117 } | |
1118 | |
1119 void test_getErrors_html_none() { | |
1120 Source source = addSource("/test.html", "<html></html>"); | |
1121 AnalysisErrorInfo errorInfo = context.getErrors(source); | |
1122 expect(errorInfo, isNotNull); | |
1123 List<AnalysisError> errors = errorInfo.errors; | |
1124 expect(errors, hasLength(0)); | |
1125 context.computeErrors(source); | |
1126 errors = errorInfo.errors; | |
1127 expect(errors, hasLength(0)); | |
1128 } | |
1129 | |
1298 void test_getHtmlElement_dart() { | 1130 void test_getHtmlElement_dart() { |
1299 Source source = addSource("/test.dart", ""); | 1131 Source source = addSource("/test.dart", ""); |
1300 expect(context.getHtmlElement(source), isNull); | 1132 expect(context.getHtmlElement(source), isNull); |
1301 expect(context.computeHtmlElement(source), isNull); | 1133 expect(context.computeHtmlElement(source), isNull); |
1302 expect(context.getHtmlElement(source), isNull); | 1134 expect(context.getHtmlElement(source), isNull); |
1303 } | 1135 } |
1304 | 1136 |
1305 void test_getHtmlFilesReferencing_html() { | 1137 void test_getHtmlFilesReferencing_html() { |
1306 Source htmlSource = addSource("/test.html", r''' | 1138 Source htmlSource = addSource("/test.html", r''' |
1307 <html><head> | 1139 <html><head> |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1519 void test_getPublicNamespace_element() { | 1351 void test_getPublicNamespace_element() { |
1520 Source source = addSource("/test.dart", "class A {}"); | 1352 Source source = addSource("/test.dart", "class A {}"); |
1521 LibraryElement library = context.computeLibraryElement(source); | 1353 LibraryElement library = context.computeLibraryElement(source); |
1522 expect(library, isNotNull); | 1354 expect(library, isNotNull); |
1523 Namespace namespace = context.getPublicNamespace(library); | 1355 Namespace namespace = context.getPublicNamespace(library); |
1524 expect(namespace, isNotNull); | 1356 expect(namespace, isNotNull); |
1525 EngineTestCase.assertInstanceOf( | 1357 EngineTestCase.assertInstanceOf( |
1526 (obj) => obj is ClassElement, ClassElement, namespace.get("A")); | 1358 (obj) => obj is ClassElement, ClassElement, namespace.get("A")); |
1527 } | 1359 } |
1528 | 1360 |
1361 void test_getResolvedCompilationUnit_library() { | |
1362 Source source = addSource("/lib.dart", "library libb;"); | |
1363 LibraryElement library = context.computeLibraryElement(source); | |
1364 context.computeErrors(source); // Force the resolved unit to be built. | |
1365 expect(context.getResolvedCompilationUnit(source, library), isNotNull); | |
1366 context.setContents(source, "library lib;"); | |
1367 expect(context.getResolvedCompilationUnit(source, library), isNull); | |
1368 } | |
1369 | |
1529 void test_getResolvedCompilationUnit_library_null() { | 1370 void test_getResolvedCompilationUnit_library_null() { |
1530 Source source = addSource("/lib.dart", "library lib;"); | 1371 Source source = addSource("/lib.dart", "library lib;"); |
1531 expect(context.getResolvedCompilationUnit(source, null), isNull); | 1372 expect(context.getResolvedCompilationUnit(source, null), isNull); |
1532 } | 1373 } |
1533 | 1374 |
1534 void test_getResolvedCompilationUnit_source_dart() { | 1375 void test_getResolvedCompilationUnit_source_dart() { |
1535 Source source = addSource("/lib.dart", "library lib;"); | 1376 Source source = addSource("/lib.dart", "library lib;"); |
1536 expect(context.getResolvedCompilationUnit2(source, source), isNull); | 1377 expect(context.getResolvedCompilationUnit2(source, source), isNull); |
1537 context.resolveCompilationUnit2(source, source); | 1378 context.resolveCompilationUnit2(source, source); |
1538 expect(context.getResolvedCompilationUnit2(source, source), isNotNull); | 1379 expect(context.getResolvedCompilationUnit2(source, source), isNotNull); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1651 Source source = newSource('/test.dart'); | 1492 Source source = newSource('/test.dart'); |
1652 resourceProvider.deleteFile('/test.dart'); | 1493 resourceProvider.deleteFile('/test.dart'); |
1653 try { | 1494 try { |
1654 context.parseCompilationUnit(source); | 1495 context.parseCompilationUnit(source); |
1655 fail("Expected AnalysisException because file does not exist"); | 1496 fail("Expected AnalysisException because file does not exist"); |
1656 } on AnalysisException { | 1497 } on AnalysisException { |
1657 // Expected result | 1498 // Expected result |
1658 } | 1499 } |
1659 } | 1500 } |
1660 | 1501 |
1502 void test_performAnalysisTask_changeLibraryContents() { | |
1503 Source libSource = | |
1504 addSource("/test.dart", "library lib; part 'test-part.dart';"); | |
1505 Source partSource = addSource("/test-part.dart", "part of lib;"); | |
1506 _analyzeAll_assertFinished(); | |
1507 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1508 reason: "library resolved 1"); | |
1509 expect( | |
1510 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
1511 reason: "part resolved 1"); | |
1512 // update and analyze #1 | |
1513 context.setContents(libSource, "library lib;"); | |
1514 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
1515 reason: "library changed 2"); | |
1516 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
1517 reason: "part changed 2"); | |
1518 _analyzeAll_assertFinished(); | |
1519 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1520 reason: "library resolved 2"); | |
1521 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
1522 reason: "part resolved 2"); | |
1523 // update and analyze #2 | |
1524 context.setContents(libSource, "library lib; part 'test-part.dart';"); | |
1525 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
1526 reason: "library changed 3"); | |
1527 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
1528 reason: "part changed 3"); | |
1529 _analyzeAll_assertFinished(); | |
1530 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1531 reason: "library resolved 2"); | |
1532 expect( | |
1533 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
1534 reason: "part resolved 3"); | |
1535 } | |
1536 | |
1537 void test_performAnalysisTask_changeLibraryThenPartContents() { | |
1538 Source libSource = | |
1539 addSource("/test.dart", "library lib; part 'test-part.dart';"); | |
1540 Source partSource = addSource("/test-part.dart", "part of lib;"); | |
1541 _analyzeAll_assertFinished(); | |
1542 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1543 reason: "library resolved 1"); | |
1544 expect( | |
1545 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
1546 reason: "part resolved 1"); | |
1547 // update and analyze #1 | |
1548 context.setContents(libSource, "library lib;"); | |
1549 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
1550 reason: "library changed 2"); | |
1551 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
1552 reason: "part changed 2"); | |
1553 _analyzeAll_assertFinished(); | |
1554 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1555 reason: "library resolved 2"); | |
1556 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
1557 reason: "part resolved 2"); | |
1558 // update and analyze #2 | |
1559 context.setContents(partSource, "part of lib; // 1"); | |
1560 // Assert that changing the part's content does not effect the library | |
1561 // now that it is no longer part of that library | |
1562 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1563 reason: "library changed 3"); | |
1564 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
1565 reason: "part changed 3"); | |
1566 _analyzeAll_assertFinished(); | |
1567 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1568 reason: "library resolved 3"); | |
1569 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
1570 reason: "part resolved 3"); | |
1571 } | |
1572 | |
1573 void test_performAnalysisTask_changePartContents_makeItAPart() { | |
1574 Source libSource = addSource("/lib.dart", r''' | |
1575 library lib; | |
1576 part 'part.dart'; | |
1577 void f(x) {}'''); | |
1578 Source partSource = addSource("/part.dart", "void g() { f(null); }"); | |
1579 _analyzeAll_assertFinished(); | |
1580 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1581 reason: "library resolved 1"); | |
1582 expect( | |
1583 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
1584 reason: "part resolved 1"); | |
1585 // update and analyze | |
1586 context.setContents(partSource, r''' | |
1587 part of lib; | |
1588 void g() { f(null); }'''); | |
1589 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
1590 reason: "library changed 2"); | |
1591 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
1592 reason: "part changed 2"); | |
1593 _analyzeAll_assertFinished(); | |
1594 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1595 reason: "library resolved 2"); | |
1596 expect( | |
1597 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
1598 reason: "part resolved 2"); | |
1599 expect(context.getErrors(libSource).errors, hasLength(0)); | |
1600 expect(context.getErrors(partSource).errors, hasLength(0)); | |
1601 } | |
1602 | |
1603 /** | |
1604 * https://code.google.com/p/dart/issues/detail?id=12424 | |
1605 */ | |
1606 void test_performAnalysisTask_changePartContents_makeItNotPart() { | |
1607 Source libSource = addSource("/lib.dart", r''' | |
1608 library lib; | |
1609 part 'part.dart'; | |
1610 void f(x) {}'''); | |
1611 Source partSource = addSource("/part.dart", r''' | |
1612 part of lib; | |
1613 void g() { f(null); }'''); | |
1614 _analyzeAll_assertFinished(); | |
1615 expect(context.getErrors(libSource).errors, hasLength(0)); | |
1616 expect(context.getErrors(partSource).errors, hasLength(0)); | |
1617 // Remove 'part' directive, which should make "f(null)" an error. | |
1618 context.setContents(partSource, r''' | |
1619 //part of lib; | |
1620 void g() { f(null); }'''); | |
1621 _analyzeAll_assertFinished(); | |
1622 expect(context.getErrors(libSource).errors.length != 0, isTrue); | |
1623 } | |
1624 | |
1625 void test_performAnalysisTask_changePartContents_noSemanticChanges() { | |
1626 Source libSource = | |
1627 addSource("/test.dart", "library lib; part 'test-part.dart';"); | |
1628 Source partSource = addSource("/test-part.dart", "part of lib;"); | |
1629 _analyzeAll_assertFinished(); | |
1630 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1631 reason: "library resolved 1"); | |
1632 expect( | |
1633 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
1634 reason: "part resolved 1"); | |
1635 // update and analyze #1 | |
1636 context.setContents(partSource, "part of lib; // 1"); | |
1637 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
1638 reason: "library changed 2"); | |
1639 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
1640 reason: "part changed 2"); | |
1641 _analyzeAll_assertFinished(); | |
1642 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1643 reason: "library resolved 2"); | |
1644 expect( | |
1645 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
1646 reason: "part resolved 2"); | |
1647 // update and analyze #2 | |
1648 context.setContents(partSource, "part of lib; // 12"); | |
1649 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNull, | |
1650 reason: "library changed 3"); | |
1651 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | |
1652 reason: "part changed 3"); | |
1653 _analyzeAll_assertFinished(); | |
1654 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | |
1655 reason: "library resolved 3"); | |
1656 expect( | |
1657 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | |
1658 reason: "part resolved 3"); | |
1659 } | |
1660 | |
1661 // void test_resolveCompilationUnit_sourceChangeDuringResolution() { | 1661 // void test_resolveCompilationUnit_sourceChangeDuringResolution() { |
1662 // _context = new _AnalysisContext_sourceChangeDuringResolution(); | 1662 // _context = new _AnalysisContext_sourceChangeDuringResolution(); |
1663 // AnalysisContextFactory.initContextWithCore(_context); | 1663 // AnalysisContextFactory.initContextWithCore(_context); |
1664 // _sourceFactory = _context.sourceFactory; | 1664 // _sourceFactory = _context.sourceFactory; |
1665 // Source source = _addSource("/lib.dart", "library lib;"); | 1665 // Source source = _addSource("/lib.dart", "library lib;"); |
1666 // CompilationUnit compilationUnit = | 1666 // CompilationUnit compilationUnit = |
1667 // _context.resolveCompilationUnit2(source, source); | 1667 // _context.resolveCompilationUnit2(source, source); |
1668 // expect(compilationUnit, isNotNull); | 1668 // expect(compilationUnit, isNotNull); |
1669 // expect(_context.getLineInfo(source), isNotNull); | 1669 // expect(_context.getLineInfo(source), isNotNull); |
1670 // } | 1670 // } |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2034 : super(name, UriKind.FILE_URI); | 2034 : super(name, UriKind.FILE_URI); |
2035 | 2035 |
2036 @override | 2036 @override |
2037 TimestampedData<String> get contents { | 2037 TimestampedData<String> get contents { |
2038 throw 'Read error'; | 2038 throw 'Read error'; |
2039 } | 2039 } |
2040 | 2040 |
2041 @override | 2041 @override |
2042 bool exists() => true; | 2042 bool exists() => true; |
2043 } | 2043 } |
OLD | NEW |