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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 expect(errors, hasLength(0)); | 169 expect(errors, hasLength(0)); |
170 } | 170 } |
171 | 171 |
172 void fail_computeHtmlElement_valid() { | 172 void fail_computeHtmlElement_valid() { |
173 Source source = addSource("/test.html", "<html></html>"); | 173 Source source = addSource("/test.html", "<html></html>"); |
174 HtmlElement element = context.computeHtmlElement(source); | 174 HtmlElement element = context.computeHtmlElement(source); |
175 expect(element, isNotNull); | 175 expect(element, isNotNull); |
176 expect(context.computeHtmlElement(source), same(element)); | 176 expect(context.computeHtmlElement(source), same(element)); |
177 } | 177 } |
178 | 178 |
179 void fail_computeImportedLibraries_none() { | 179 void test_computeImportedLibraries_none() { |
180 // This is failing because computeImportedLibraries now always includes | |
181 // dart:core, and we don't have any way of knowing whether it was explicit. | |
182 Source source = addSource("/test.dart", "library test;"); | 180 Source source = addSource("/test.dart", "library test;"); |
183 expect(context.computeImportedLibraries(source), hasLength(0)); | 181 expect(context.computeImportedLibraries(source), hasLength(0)); |
184 } | 182 } |
185 | 183 |
186 void fail_computeImportedLibraries_some() { | 184 void test_computeImportedLibraries_some() { |
187 // This is failing because computeImportedLibraries now always includes | |
188 // dart:core, and we don't have any way of knowing whether it was explicit. | |
189 // addSource("/lib1.dart", "library lib1;"); | |
190 // addSource("/lib2.dart", "library lib2;"); | |
191 Source source = addSource( | 185 Source source = addSource( |
192 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); | 186 "/test.dart", "library test; import 'lib1.dart'; import 'lib2.dart';"); |
193 expect(context.computeImportedLibraries(source), hasLength(2)); | 187 expect(context.computeImportedLibraries(source), hasLength(2)); |
194 } | 188 } |
195 | 189 |
196 void fail_computeResolvableCompilationUnit_dart_exception() { | 190 void fail_computeResolvableCompilationUnit_dart_exception() { |
197 TestSource source = _addSourceWithException("/test.dart"); | 191 TestSource source = _addSourceWithException("/test.dart"); |
198 try { | 192 try { |
199 context.computeResolvableCompilationUnit(source); | 193 context.computeResolvableCompilationUnit(source); |
200 fail("Expected AnalysisException"); | 194 fail("Expected AnalysisException"); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 <script type='application/dart' src='test.js'/> | 411 <script type='application/dart' src='test.js'/> |
418 </head></html>'''); | 412 </head></html>'''); |
419 Source librarySource = addSource("/test.dart", "library lib;"); | 413 Source librarySource = addSource("/test.dart", "library lib;"); |
420 context.computeLibraryElement(librarySource); | 414 context.computeLibraryElement(librarySource); |
421 context.parseHtmlUnit(htmlSource); | 415 context.parseHtmlUnit(htmlSource); |
422 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource); | 416 List<Source> result = context.getLibrariesReferencedFromHtml(htmlSource); |
423 expect(result, hasLength(1)); | 417 expect(result, hasLength(1)); |
424 expect(result[0], librarySource); | 418 expect(result[0], librarySource); |
425 } | 419 } |
426 | 420 |
427 void fail_getResolvedCompilationUnit_library() { | 421 void test_getResolvedCompilationUnit_library() { |
428 Source source = addSource("/lib.dart", "library libb;"); | 422 Source source = addSource("/lib.dart", "library libb;"); |
429 LibraryElement library = context.computeLibraryElement(source); | 423 LibraryElement library = context.computeLibraryElement(source); |
| 424 context.computeErrors(source); // Force the resolved unit to be built. |
430 expect(context.getResolvedCompilationUnit(source, library), isNotNull); | 425 expect(context.getResolvedCompilationUnit(source, library), isNotNull); |
431 context.setContents(source, "library lib;"); | 426 context.setContents(source, "library lib;"); |
432 expect(context.getResolvedCompilationUnit(source, library), isNull); | 427 expect(context.getResolvedCompilationUnit(source, library), isNull); |
433 } | 428 } |
434 | 429 |
435 void fail_getResolvedHtmlUnit() { | 430 void fail_getResolvedHtmlUnit() { |
436 Source source = addSource("/test.html", "<html></html>"); | 431 Source source = addSource("/test.html", "<html></html>"); |
437 expect(context.getResolvedHtmlUnit(source), isNull); | 432 expect(context.getResolvedHtmlUnit(source), isNull); |
438 context.resolveHtmlUnit(source); | 433 context.resolveHtmlUnit(source); |
439 expect(context.getResolvedHtmlUnit(source), isNotNull); | 434 expect(context.getResolvedHtmlUnit(source), isNotNull); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 reason: "library changed 3"); | 551 reason: "library changed 3"); |
557 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | 552 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
558 reason: "part changed 3"); | 553 reason: "part changed 3"); |
559 _analyzeAll_assertFinished(); | 554 _analyzeAll_assertFinished(); |
560 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | 555 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
561 reason: "library resolved 3"); | 556 reason: "library resolved 3"); |
562 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, | 557 expect(context.getResolvedCompilationUnit2(partSource, libSource), isNull, |
563 reason: "part resolved 3"); | 558 reason: "part resolved 3"); |
564 } | 559 } |
565 | 560 |
566 void fail_performAnalysisTask_changePartContents_makeItAPart() { | 561 void test_performAnalysisTask_changePartContents_makeItAPart() { |
567 Source libSource = addSource("/lib.dart", r''' | 562 Source libSource = addSource("/lib.dart", r''' |
568 library lib; | 563 library lib; |
569 part 'part.dart'; | 564 part 'part.dart'; |
570 void f(x) {}'''); | 565 void f(x) {}'''); |
571 Source partSource = addSource("/part.dart", "void g() { f(null); }"); | 566 Source partSource = addSource("/part.dart", "void g() { f(null); }"); |
572 _analyzeAll_assertFinished(); | 567 _analyzeAll_assertFinished(); |
573 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | 568 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
574 reason: "library resolved 1"); | 569 reason: "library resolved 1"); |
575 expect( | 570 expect( |
576 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | 571 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
(...skipping 12 matching lines...) Expand all Loading... |
589 expect( | 584 expect( |
590 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | 585 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
591 reason: "part resolved 2"); | 586 reason: "part resolved 2"); |
592 expect(context.getErrors(libSource).errors, hasLength(0)); | 587 expect(context.getErrors(libSource).errors, hasLength(0)); |
593 expect(context.getErrors(partSource).errors, hasLength(0)); | 588 expect(context.getErrors(partSource).errors, hasLength(0)); |
594 } | 589 } |
595 | 590 |
596 /** | 591 /** |
597 * https://code.google.com/p/dart/issues/detail?id=12424 | 592 * https://code.google.com/p/dart/issues/detail?id=12424 |
598 */ | 593 */ |
599 void fail_performAnalysisTask_changePartContents_makeItNotPart() { | 594 void test_performAnalysisTask_changePartContents_makeItNotPart() { |
600 Source libSource = addSource("/lib.dart", r''' | 595 Source libSource = addSource("/lib.dart", r''' |
601 library lib; | 596 library lib; |
602 part 'part.dart'; | 597 part 'part.dart'; |
603 void f(x) {}'''); | 598 void f(x) {}'''); |
604 Source partSource = addSource("/part.dart", r''' | 599 Source partSource = addSource("/part.dart", r''' |
605 part of lib; | 600 part of lib; |
606 void g() { f(null); }'''); | 601 void g() { f(null); }'''); |
607 _analyzeAll_assertFinished(); | 602 _analyzeAll_assertFinished(); |
608 expect(context.getErrors(libSource).errors, hasLength(0)); | 603 expect(context.getErrors(libSource).errors, hasLength(0)); |
609 expect(context.getErrors(partSource).errors, hasLength(0)); | 604 expect(context.getErrors(partSource).errors, hasLength(0)); |
610 // Remove 'part' directive, which should make "f(null)" an error. | 605 // Remove 'part' directive, which should make "f(null)" an error. |
611 context.setContents(partSource, r''' | 606 context.setContents(partSource, r''' |
612 //part of lib; | 607 //part of lib; |
613 void g() { f(null); }'''); | 608 void g() { f(null); }'''); |
614 _analyzeAll_assertFinished(); | 609 _analyzeAll_assertFinished(); |
615 expect(context.getErrors(libSource).errors.length != 0, isTrue); | 610 expect(context.getErrors(libSource).errors.length != 0, isTrue); |
616 } | 611 } |
617 | 612 |
618 void fail_performAnalysisTask_changePartContents_noSemanticChanges() { | 613 void test_performAnalysisTask_changePartContents_noSemanticChanges() { |
619 Source libSource = | 614 Source libSource = |
620 addSource("/test.dart", "library lib; part 'test-part.dart';"); | 615 addSource("/test.dart", "library lib; part 'test-part.dart';"); |
621 Source partSource = addSource("/test-part.dart", "part of lib;"); | 616 Source partSource = addSource("/test-part.dart", "part of lib;"); |
622 _analyzeAll_assertFinished(); | 617 _analyzeAll_assertFinished(); |
623 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, | 618 expect(context.getResolvedCompilationUnit2(libSource, libSource), isNotNull, |
624 reason: "library resolved 1"); | 619 reason: "library resolved 1"); |
625 expect( | 620 expect( |
626 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, | 621 context.getResolvedCompilationUnit2(partSource, libSource), isNotNull, |
627 reason: "part resolved 1"); | 622 reason: "part resolved 1"); |
628 // update and analyze #1 | 623 // update and analyze #1 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 return pumpEventQueue().then((_) { | 903 return pumpEventQueue().then((_) { |
909 listener.assertEvent(wereSourcesAdded: true); | 904 listener.assertEvent(wereSourcesAdded: true); |
910 listener.assertEvent(changedSources: [librarySource]); | 905 listener.assertEvent(changedSources: [librarySource]); |
911 listener.assertEvent(wereSourcesAdded: true); | 906 listener.assertEvent(wereSourcesAdded: true); |
912 listener.assertEvent(changedSources: [partSource]); | 907 listener.assertEvent(changedSources: [partSource]); |
913 listener.assertEvent(changedSources: [librarySource]); | 908 listener.assertEvent(changedSources: [librarySource]); |
914 listener.assertNoMoreEvents(); | 909 listener.assertNoMoreEvents(); |
915 }); | 910 }); |
916 } | 911 } |
917 | 912 |
918 void test_setContents_unchanged_consistentModificationTime() { | 913 void fail_setContents_unchanged_consistentModificationTime() { |
919 String contents = "// foo"; | 914 String contents = "// foo"; |
920 Source source = addSource("/test.dart", contents); | 915 Source source = addSource("/test.dart", contents); |
921 // do all, no tasks | 916 // do all, no tasks |
922 _analyzeAll_assertFinished(); | 917 _analyzeAll_assertFinished(); |
923 { | 918 { |
924 AnalysisResult result = context.performAnalysisTask(); | 919 AnalysisResult result = context.performAnalysisTask(); |
925 expect(result.changeNotices, isNull); | 920 expect(result.changeNotices, isNull); |
926 } | 921 } |
927 // set the same contents, still no tasks | 922 // set the same contents, still no tasks |
928 context.setContents(source, contents); | 923 context.setContents(source, contents); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1198 Source source = addSource("/test.html", r''' | 1193 Source source = addSource("/test.html", r''' |
1199 <html> | 1194 <html> |
1200 <body> | 1195 <body> |
1201 <h1>A</h1> | 1196 <h1>A</h1> |
1202 </body> | 1197 </body> |
1203 </html>'''); | 1198 </html>'''); |
1204 LineInfo info = context.computeLineInfo(source); | 1199 LineInfo info = context.computeLineInfo(source); |
1205 expect(info, isNotNull); | 1200 expect(info, isNotNull); |
1206 } | 1201 } |
1207 | 1202 |
1208 Future test_computeResolvedCompilationUnitAsync_afterDispose() { | 1203 Future fail_computeResolvedCompilationUnitAsync_afterDispose() { |
1209 Source source = addSource("/lib.dart", "library lib;"); | 1204 Source source = addSource("/lib.dart", "library lib;"); |
1210 // Complete all pending analysis tasks and flush the AST so that it won't | 1205 // Complete all pending analysis tasks and flush the AST so that it won't |
1211 // be available immediately. | 1206 // be available immediately. |
1212 _performPendingAnalysisTasks(); | 1207 _performPendingAnalysisTasks(); |
1213 _flushAst(source); | 1208 _flushAst(source); |
1214 // Dispose of the context. | 1209 // Dispose of the context. |
1215 context.dispose(); | 1210 context.dispose(); |
1216 // Any attempt to start an asynchronous computation should return a future | 1211 // Any attempt to start an asynchronous computation should return a future |
1217 // which completes with error. | 1212 // which completes with error. |
1218 CancelableFuture<CompilationUnit> future = | 1213 CancelableFuture<CompilationUnit> future = |
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 : super(name, UriKind.FILE_URI); | 2034 : super(name, UriKind.FILE_URI); |
2040 | 2035 |
2041 @override | 2036 @override |
2042 TimestampedData<String> get contents { | 2037 TimestampedData<String> get contents { |
2043 throw 'Read error'; | 2038 throw 'Read error'; |
2044 } | 2039 } |
2045 | 2040 |
2046 @override | 2041 @override |
2047 bool exists() => true; | 2042 bool exists() => true; |
2048 } | 2043 } |
OLD | NEW |