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

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

Issue 1179283007: add for() keyword suggestion (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/keyword_contributor.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/keyword_contributor_test.dart
diff --git a/pkg/analysis_server/test/services/completion/keyword_contributor_test.dart b/pkg/analysis_server/test/services/completion/keyword_contributor_test.dart
index b38c461448539606a194a14c0faee7d28a057206..c9666b16e0451b28de1e8c6c6587d0e93224580b 100644
--- a/pkg/analysis_server/test/services/completion/keyword_contributor_test.dart
+++ b/pkg/analysis_server/test/services/completion/keyword_contributor_test.dart
@@ -172,20 +172,37 @@ class KeywordContributorTest extends AbstractCompletionTest {
Keyword.TRUE,
];
+ static final Map<String, List<String>> keywordTemplates =
+ <String, List<String>>{
+ Keyword.IMPORT.syntax: [
+ "import '^';",
+ "import '^' as ;",
+ "import '^' hide ;",
+ "import '^' show ;"
+ ],
+ Keyword.FOR.syntax: ['for (^)']
+ };
+
void assertSuggestKeywords(Iterable<Keyword> expectedKeywords,
{List<String> pseudoKeywords: NO_PSEUDO_KEYWORDS,
int relevance: DART_RELEVANCE_KEYWORD}) {
Set<String> expectedCompletions = new Set<String>();
+ Map<String, int> expectedOffsets = <String, int>{};
Set<String> actualCompletions = new Set<String>();
expectedCompletions.addAll(expectedKeywords.map((k) => k.syntax));
expectedCompletions.addAll(pseudoKeywords);
- if (expectedCompletions.contains(Keyword.IMPORT.syntax)) {
- expectedCompletions.remove(Keyword.IMPORT.syntax);
- expectedCompletions.add("import '';");
- expectedCompletions.add("import '' as ;");
- expectedCompletions.add("import '' hide ;");
- expectedCompletions.add("import '' show ;");
- }
+ keywordTemplates.forEach((String key, List<String> templates) {
+ if (expectedCompletions.remove(key)) {
+ for (String t in templates) {
+ int offset = t.indexOf('^');
+ if (offset != -1) {
+ t = '${t.substring(0, offset)}${t.substring(offset + 1)}';
+ expectedOffsets[t] = offset;
+ }
+ expectedCompletions.add(t);
+ }
+ }
+ });
for (CompletionSuggestion s in request.suggestions) {
if (s.kind == CompletionSuggestionKind.KEYWORD) {
Keyword k = Keyword.keywords[s.completion];
@@ -215,15 +232,18 @@ class KeywordContributorTest extends AbstractCompletionTest {
++importRelevance;
}
expect(s.relevance, equals(importRelevance), reason: s.completion);
- expect(s.selectionOffset, equals(Keyword.IMPORT.syntax.length + 2));
} else {
if (s.completion == Keyword.RETHROW.syntax) {
expect(s.relevance, equals(relevance - 1), reason: s.completion);
} else {
expect(s.relevance, equals(relevance), reason: s.completion);
}
- expect(s.selectionOffset, equals(s.completion.length));
}
+ int expectedOffset = expectedOffsets[s.completion];
+ if (expectedOffset == null) {
+ expectedOffset = s.completion.length;
+ }
+ expect(s.selectionOffset, equals(expectedOffset));
expect(s.selectionLength, equals(0));
expect(s.isDeprecated, equals(false));
expect(s.isPotential, equals(false));
« no previous file with comments | « pkg/analysis_server/lib/src/services/completion/keyword_contributor.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698