| 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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // listen |
| 791 context.onResultComputed(LIBRARY_ELEMENT).listen((event) { |
| 792 Source librarySource = event.target; |
| 793 libraryElementUris.add(librarySource.uri.toString()); |
| 794 }); |
| 795 context.onResultComputed(PARSED_UNIT).listen((event) { |
| 796 Source source = event.target; |
| 797 parsedUnitUris.add(source.uri.toString()); |
| 798 }); |
| 799 context.onResultComputed(RESOLVED_UNIT).listen((event) { |
| 800 LibrarySpecificUnit target = event.target; |
| 801 Source librarySource = target.library; |
| 802 resolvedUnitUris.add(librarySource.uri.toString()); |
| 803 }); |
| 804 // analyze |
| 805 addSource('/test.dart', 'main() {}'); |
| 806 _analyzeAll_assertFinished(); |
| 807 // verify |
| 808 expect(libraryElementUris, contains('dart:core')); |
| 809 expect(libraryElementUris, contains('file:///test.dart')); |
| 810 expect(parsedUnitUris, contains('dart:core')); |
| 811 expect(parsedUnitUris, contains('file:///test.dart')); |
| 812 // TODO(scheglov) uncomment after computing all RESOLVED_UNIT(s) |
| 813 // expect(resolvedUnitUris, contains('dart:core')); |
| 814 expect(resolvedUnitUris, contains('file:///test.dart')); |
| 815 } |
| 816 |
| 786 void fail_performAnalysisTask_IOException() { | 817 void fail_performAnalysisTask_IOException() { |
| 787 TestSource source = _addSourceWithException2("/test.dart", "library test;"); | 818 TestSource source = _addSourceWithException2("/test.dart", "library test;"); |
| 788 int oldTimestamp = context.getModificationStamp(source); | 819 int oldTimestamp = context.getModificationStamp(source); |
| 789 source.generateExceptionOnRead = false; | 820 source.generateExceptionOnRead = false; |
| 790 _analyzeAll_assertFinished(); | 821 _analyzeAll_assertFinished(); |
| 791 expect(source.readCount, 1); | 822 expect(source.readCount, 1); |
| 792 source.generateExceptionOnRead = true; | 823 source.generateExceptionOnRead = true; |
| 793 do { | 824 do { |
| 794 _changeSource(source, ""); | 825 _changeSource(source, ""); |
| 795 // Ensure that the timestamp differs, | 826 // Ensure that the timestamp differs, |
| (...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2141 : super(name, pathos.toUri(name), UriKind.FILE_URI); | 2172 : super(name, pathos.toUri(name), UriKind.FILE_URI); |
| 2142 | 2173 |
| 2143 @override | 2174 @override |
| 2144 TimestampedData<String> get contents { | 2175 TimestampedData<String> get contents { |
| 2145 throw 'Read error'; | 2176 throw 'Read error'; |
| 2146 } | 2177 } |
| 2147 | 2178 |
| 2148 @override | 2179 @override |
| 2149 bool exists() => true; | 2180 bool exists() => true; |
| 2150 } | 2181 } |
| OLD | NEW |