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

Unified Diff: pkg/analysis_server/test/services/completion/imported_computer_test.dart

Issue 752833002: refactor import caching to exclude suggestions for inherited members (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cleanup unused imports Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/test/services/completion/completion_test_util.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analysis_server/test/services/completion/imported_computer_test.dart
diff --git a/pkg/analysis_server/test/services/completion/imported_computer_test.dart b/pkg/analysis_server/test/services/completion/imported_computer_test.dart
index 6c5e95444c77a6df95a8c2b32c64aa8e95975729..0f1ae4d52ff0b81f6d671f7e6df399e915f7c542 100644
--- a/pkg/analysis_server/test/services/completion/imported_computer_test.dart
+++ b/pkg/analysis_server/test/services/completion/imported_computer_test.dart
@@ -4,32 +4,39 @@
library test.services.completion.toplevel;
+import 'package:analysis_server/src/protocol.dart';
+import 'package:analysis_server/src/services/completion/dart_completion_cache.dart';
+import 'package:analysis_server/src/services/completion/dart_completion_manager.dart';
import 'package:analysis_server/src/services/completion/imported_computer.dart';
+import 'package:analyzer/src/generated/engine.dart';
import 'package:unittest/unittest.dart';
import '../../reflective_tests.dart';
import 'completion_test_util.dart';
-import 'package:analysis_server/src/protocol.dart';
-import 'package:analyzer/src/generated/engine.dart';
-import 'package:analysis_server/src/services/completion/dart_completion_manager.dart';
main() {
groupSep = ' | ';
- runReflectiveTests(ImportedTypeComputerTest);
+ runReflectiveTests(ImportedComputerTest);
}
@ReflectiveTestCase()
-class ImportedTypeComputerTest extends AbstractSelectorSuggestionTest {
+class ImportedComputerTest extends AbstractSelectorSuggestionTest {
- @override
- void setUpComputer() {
- computer = new ImportedComputer();
+ void assertCached(String completion) {
+ DartCompletionCache cache = request.cache;
+ if (!isCached(cache.importedTypeSuggestions, completion) &&
+ !isCached(cache.importedVoidReturnSuggestions, completion) &&
+ !isCached(cache.libraryPrefixSuggestions, completion) &&
+ !isCached(cache.otherImportedSuggestions, completion)) {
+ fail('expected $completion to be cached');
+ }
}
/**
* Assert that the ImportedComputer uses cached results to produce identical
* suggestions to the original set of suggestions.
*/
+ @override
void assertCachedCompute(_) {
expect(request.unit.element, isNotNull);
List<CompletionSuggestion> oldSuggestions = request.suggestions;
@@ -52,10 +59,45 @@ class ImportedTypeComputerTest extends AbstractSelectorSuggestionTest {
expect(computeFast(), isTrue);
expect(request.unit.element, isNull);
List<CompletionSuggestion> newSuggestions = request.suggestions;
- expect(newSuggestions.length, oldSuggestions.length);
- oldSuggestions.forEach((CompletionSuggestion s) {
- expect(newSuggestions.contains(s), isTrue);
- });
+ if (newSuggestions.length == oldSuggestions.length) {
+ if (!oldSuggestions.any(
+ (CompletionSuggestion s) => !newSuggestions.contains(s))) {
+ return;
+ }
+ }
+ StringBuffer sb = new StringBuffer(
+ 'suggestions based upon cached results do not match expectations');
+ sb.write('\n Expected:');
+ oldSuggestions.toList()
+ ..sort(suggestionComparator)
+ ..forEach((CompletionSuggestion suggestion) {
+ sb.write('\n ${suggestion.completion} -> $suggestion');
+ });
+ sb.write('\n Actual:');
+ newSuggestions.toList()
+ ..sort(suggestionComparator)
+ ..forEach((CompletionSuggestion suggestion) {
+ sb.write('\n ${suggestion.completion} -> $suggestion');
+ });
+ fail(sb.toString());
+ }
+
+ void assertNotCached(String completion) {
+ DartCompletionCache cache = request.cache;
+ if (isCached(cache.importedTypeSuggestions, completion) ||
+ isCached(cache.importedVoidReturnSuggestions, completion) ||
+ isCached(cache.libraryPrefixSuggestions, completion) ||
+ isCached(cache.otherImportedSuggestions, completion)) {
+ fail('expected $completion NOT to be cached');
+ }
+ }
+
+ bool isCached(List<CompletionSuggestion> suggestions, String completion) =>
+ suggestions.any((CompletionSuggestion s) => s.completion == completion);
+
+ @override
+ void setUpComputer() {
+ computer = new ImportedComputer();
}
@override
@@ -82,7 +124,22 @@ class ImportedTypeComputerTest extends AbstractSelectorSuggestionTest {
@override
test_Block() {
return super.test_Block().then((_) {
- expect(request.cache.importKey, 'import "/testAB.dart";import "/testCD.dart" hide D;import "/testEEF.dart" show EE;import "/testG.dart" as g;');
+ expect(
+ request.cache.importKey,
+ 'import "/testAB.dart";import "/testCD.dart" hide D;import "/testEEF.dart" show EE;import "/testG.dart" as g;');
+ assertCached('A');
+ assertCached('T3');
+ });
+ }
+
+ @override
+ test_Block_inherited_imported() {
+ return super.test_Block_inherited_imported().then((_) {
+ assertCached('E');
+ assertCached('F');
+ assertNotCached('e1');
+ assertNotCached('i2');
+ assertNotCached('m1');
});
}
}
« no previous file with comments | « pkg/analysis_server/test/services/completion/completion_test_util.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698