| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 // Disposing of the context should cause all pending futures to complete | 233 // Disposing of the context should cause all pending futures to complete |
| 234 // with AnalysisNotScheduled, so that no clients are left hanging. | 234 // with AnalysisNotScheduled, so that no clients are left hanging. |
| 235 context.dispose(); | 235 context.dispose(); |
| 236 expect(context.pendingFutureSources_forTesting, isEmpty); | 236 expect(context.pendingFutureSources_forTesting, isEmpty); |
| 237 return pumpEventQueue().then((_) { | 237 return pumpEventQueue().then((_) { |
| 238 expect(completed, isTrue); | 238 expect(completed, isTrue); |
| 239 expect(context.pendingFutureSources_forTesting, isEmpty); | 239 expect(context.pendingFutureSources_forTesting, isEmpty); |
| 240 }); | 240 }); |
| 241 } | 241 } |
| 242 | 242 |
| 243 Future fail_computeResolvedCompilationUnitAsync_unrelatedLibrary() { | 243 Future test_computeResolvedCompilationUnitAsync_noCacheEntry() { |
| 244 Source librarySource = addSource("/lib.dart", "library lib;"); | 244 Source librarySource = addSource("/lib.dart", "library lib;"); |
| 245 Source partSource = addSource("/part.dart", "part of foo;"); | 245 Source partSource = addSource("/part.dart", "part of foo;"); |
| 246 bool completed = false; | 246 bool completed = false; |
| 247 context | 247 context |
| 248 .computeResolvedCompilationUnitAsync(partSource, librarySource) | 248 .computeResolvedCompilationUnitAsync(partSource, librarySource) |
| 249 .then((_) { | 249 .then((CompilationUnit unit) { |
| 250 fail('Expected resolution to fail'); | 250 expect(unit, isNotNull); |
| 251 }, onError: (e) { | |
| 252 expect(e, new isInstanceOf<AnalysisNotScheduledError>()); | |
| 253 completed = true; | 251 completed = true; |
| 254 }); | 252 }); |
| 255 return pumpEventQueue().then((_) { | 253 return pumpEventQueue().then((_) { |
| 256 expect(completed, isFalse); | 254 expect(completed, isFalse); |
| 257 _performPendingAnalysisTasks(); | 255 _performPendingAnalysisTasks(); |
| 258 }).then((_) => pumpEventQueue()).then((_) { | 256 }).then((_) => pumpEventQueue()).then((_) { |
| 259 expect(completed, isTrue); | 257 expect(completed, isTrue); |
| 260 }); | 258 }); |
| 261 } | 259 } |
| 262 | 260 |
| (...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1950 AnalysisDelta delta = new AnalysisDelta(); | 1948 AnalysisDelta delta = new AnalysisDelta(); |
| 1951 delta.setAnalysisLevel(source, AnalysisLevel.ALL); | 1949 delta.setAnalysisLevel(source, AnalysisLevel.ALL); |
| 1952 context.applyAnalysisDelta(delta); | 1950 context.applyAnalysisDelta(delta); |
| 1953 expect(context.sourcesNeedingProcessing, contains(source)); | 1951 expect(context.sourcesNeedingProcessing, contains(source)); |
| 1954 delta = new AnalysisDelta(); | 1952 delta = new AnalysisDelta(); |
| 1955 delta.setAnalysisLevel(source, AnalysisLevel.NONE); | 1953 delta.setAnalysisLevel(source, AnalysisLevel.NONE); |
| 1956 context.applyAnalysisDelta(delta); | 1954 context.applyAnalysisDelta(delta); |
| 1957 expect(context.sourcesNeedingProcessing.contains(source), isFalse); | 1955 expect(context.sourcesNeedingProcessing.contains(source), isFalse); |
| 1958 } | 1956 } |
| 1959 | 1957 |
| 1960 Future xtest_computeResolvedCompilationUnitAsync() { | 1958 Future test_computeResolvedCompilationUnitAsync() { |
| 1961 Source source = addSource("/lib.dart", "library lib;"); | 1959 Source source = addSource("/lib.dart", "library lib;"); |
| 1962 // Complete all pending analysis tasks and flush the AST so that it won't | 1960 // Complete all pending analysis tasks and flush the AST so that it won't |
| 1963 // be available immediately. | 1961 // be available immediately. |
| 1964 _performPendingAnalysisTasks(); | 1962 _performPendingAnalysisTasks(); |
| 1965 _flushAst(source); | 1963 _flushAst(source); |
| 1966 bool completed = false; | 1964 bool completed = false; |
| 1967 context | 1965 context |
| 1968 .computeResolvedCompilationUnitAsync(source, source) | 1966 .computeResolvedCompilationUnitAsync(source, source) |
| 1969 .then((CompilationUnit unit) { | 1967 .then((CompilationUnit unit) { |
| 1970 expect(unit, isNotNull); | 1968 expect(unit, isNotNull); |
| 1971 completed = true; | 1969 completed = true; |
| 1972 }); | 1970 }); |
| 1973 return pumpEventQueue().then((_) { | 1971 return pumpEventQueue().then((_) { |
| 1974 expect(completed, isFalse); | 1972 expect(completed, isFalse); |
| 1975 _performPendingAnalysisTasks(); | 1973 _performPendingAnalysisTasks(); |
| 1976 }).then((_) => pumpEventQueue()).then((_) { | 1974 }).then((_) => pumpEventQueue()).then((_) { |
| 1977 expect(completed, isTrue); | 1975 expect(completed, isTrue); |
| 1978 }); | 1976 }); |
| 1979 } | 1977 } |
| 1980 | 1978 |
| 1981 Future xtest_computeResolvedCompilationUnitAsync_cancel() { | 1979 Future test_computeResolvedCompilationUnitAsync_cancel() { |
| 1982 Source source = addSource("/lib.dart", "library lib;"); | 1980 Source source = addSource("/lib.dart", "library lib;"); |
| 1983 // Complete all pending analysis tasks and flush the AST so that it won't | 1981 // Complete all pending analysis tasks and flush the AST so that it won't |
| 1984 // be available immediately. | 1982 // be available immediately. |
| 1985 _performPendingAnalysisTasks(); | 1983 _performPendingAnalysisTasks(); |
| 1986 _flushAst(source); | 1984 _flushAst(source); |
| 1987 CancelableFuture<CompilationUnit> future = | 1985 CancelableFuture<CompilationUnit> future = |
| 1988 context.computeResolvedCompilationUnitAsync(source, source); | 1986 context.computeResolvedCompilationUnitAsync(source, source); |
| 1989 bool completed = false; | 1987 bool completed = false; |
| 1990 future.then((CompilationUnit unit) { | 1988 future.then((CompilationUnit unit) { |
| 1991 fail('Future should have been canceled'); | 1989 fail('Future should have been canceled'); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2077 ClassElement _findClass(CompilationUnitElement unit, String className) { | 2075 ClassElement _findClass(CompilationUnitElement unit, String className) { |
| 2078 for (ClassElement classElement in unit.types) { | 2076 for (ClassElement classElement in unit.types) { |
| 2079 if (classElement.displayName == className) { | 2077 if (classElement.displayName == className) { |
| 2080 return classElement; | 2078 return classElement; |
| 2081 } | 2079 } |
| 2082 } | 2080 } |
| 2083 return null; | 2081 return null; |
| 2084 } | 2082 } |
| 2085 | 2083 |
| 2086 void _flushAst(Source source) { | 2084 void _flushAst(Source source) { |
| 2087 CacheEntry entry = context | 2085 CacheEntry entry = |
| 2088 .getReadableSourceEntryOrNull(new LibrarySpecificUnit(source, source)); | 2086 context.getCacheEntry(new LibrarySpecificUnit(source, source)); |
| 2089 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED); | 2087 entry.setState(RESOLVED_UNIT, CacheState.FLUSHED); |
| 2090 } | 2088 } |
| 2091 | 2089 |
| 2092 IncrementalAnalysisCache _getIncrementalAnalysisCache( | 2090 IncrementalAnalysisCache _getIncrementalAnalysisCache( |
| 2093 AnalysisContextImpl context2) { | 2091 AnalysisContextImpl context2) { |
| 2094 return context2.test_incrementalAnalysisCache; | 2092 return context2.test_incrementalAnalysisCache; |
| 2095 } | 2093 } |
| 2096 | 2094 |
| 2097 List<Source> _getPriorityOrder(AnalysisContextImpl context2) { | 2095 List<Source> _getPriorityOrder(AnalysisContextImpl context2) { |
| 2098 return context2.test_priorityOrder; | 2096 return context2.test_priorityOrder; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2171 : super(name, pathos.toUri(name), UriKind.FILE_URI); | 2169 : super(name, pathos.toUri(name), UriKind.FILE_URI); |
| 2172 | 2170 |
| 2173 @override | 2171 @override |
| 2174 TimestampedData<String> get contents { | 2172 TimestampedData<String> get contents { |
| 2175 throw 'Read error'; | 2173 throw 'Read error'; |
| 2176 } | 2174 } |
| 2177 | 2175 |
| 2178 @override | 2176 @override |
| 2179 bool exists() => true; | 2177 bool exists() => true; |
| 2180 } | 2178 } |
| OLD | NEW |