Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(407)

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 1181603004: Add AnalysisContext.onResultComputed(). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 // remove libB.dart content and analyze 776 // remove libB.dart content and analyze
777 context.setContents(libBSource, null); 777 context.setContents(libBSource, null);
778 _analyzeAll_assertFinished(); 778 _analyzeAll_assertFinished();
779 expect(context.getResolvedHtmlUnit(htmlSource), isNotNull, 779 expect(context.getResolvedHtmlUnit(htmlSource), isNotNull,
780 reason: "htmlUnit resolved 1"); 780 reason: "htmlUnit resolved 1");
781 AnalysisErrorInfo errors = context.getErrors(htmlSource); 781 AnalysisErrorInfo errors = context.getErrors(htmlSource);
782 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue, 782 expect(_hasAnalysisErrorWithErrorSeverity(errors), isTrue,
783 reason: "htmlSource has an error"); 783 reason: "htmlSource has an error");
784 } 784 }
785 785
786 void test_performAnalysisTask_onResultComputed() {
787 Set<String> libraryElementUris = new Set<String>();
788 Set<String> parsedUnitUris = new Set<String>();
789 Set<String> resolvedUnitUris = new Set<String>();
790 Set<String> resolvedUnitNoConstUris = new Set<String>();
791 // listen
792 context.onResultComputed(LIBRARY_ELEMENT).listen((event) {
793 Source librarySource = event.target;
794 libraryElementUris.add(librarySource.uri.toString());
795 });
796 context.onResultComputed(PARSED_UNIT).listen((event) {
797 Source source = event.target;
798 parsedUnitUris.add(source.uri.toString());
799 });
800 context.onResultComputed(RESOLVED_UNIT).listen((event) {
801 LibrarySpecificUnit target = event.target;
802 Source librarySource = target.library;
803 resolvedUnitUris.add(librarySource.uri.toString());
804 });
805 context.onResultComputed(RESOLVED_UNIT_NO_CONSTANTS).listen((event) {
806 LibrarySpecificUnit target = event.target;
807 Source librarySource = target.library;
808 resolvedUnitNoConstUris.add(librarySource.uri.toString());
809 });
810 // analyze
811 addSource('/test.dart', 'main() {}');
812 _analyzeAll_assertFinished();
813 // verify
814 expect(libraryElementUris, contains('dart:core'));
815 expect(libraryElementUris, contains('file:///test.dart'));
816 expect(parsedUnitUris, contains('dart:core'));
817 expect(parsedUnitUris, contains('file:///test.dart'));
818 expect(resolvedUnitUris, contains('file:///test.dart'));
819 expect(resolvedUnitNoConstUris, contains('dart:core'));
820 expect(resolvedUnitNoConstUris, contains('file:///test.dart'));
821 }
822
786 void fail_performAnalysisTask_IOException() { 823 void fail_performAnalysisTask_IOException() {
787 TestSource source = _addSourceWithException2("/test.dart", "library test;"); 824 TestSource source = _addSourceWithException2("/test.dart", "library test;");
788 int oldTimestamp = context.getModificationStamp(source); 825 int oldTimestamp = context.getModificationStamp(source);
789 source.generateExceptionOnRead = false; 826 source.generateExceptionOnRead = false;
790 _analyzeAll_assertFinished(); 827 _analyzeAll_assertFinished();
791 expect(source.readCount, 1); 828 expect(source.readCount, 1);
792 source.generateExceptionOnRead = true; 829 source.generateExceptionOnRead = true;
793 do { 830 do {
794 _changeSource(source, ""); 831 _changeSource(source, "");
795 // Ensure that the timestamp differs, 832 // Ensure that the timestamp differs,
(...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after
2141 : super(name, pathos.toUri(name), UriKind.FILE_URI); 2178 : super(name, pathos.toUri(name), UriKind.FILE_URI);
2142 2179
2143 @override 2180 @override
2144 TimestampedData<String> get contents { 2181 TimestampedData<String> get contents {
2145 throw 'Read error'; 2182 throw 'Read error';
2146 } 2183 }
2147 2184
2148 @override 2185 @override
2149 bool exists() => true; 2186 bool exists() => true;
2150 } 2187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698