| 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.services.completion.util; | 5 library test.services.completion.util; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_services/completion/completion_computer.dart'; | 9 import 'package:analysis_services/completion/completion_computer.dart'; |
| 10 import 'package:analysis_services/completion/completion_suggestion.dart'; | 10 import 'package:analysis_services/completion/completion_suggestion.dart'; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); | 39 expect(completionOffset, isNull, reason: 'Call addTestUnit exactly once'); |
| 40 completionOffset = content.indexOf('^'); | 40 completionOffset = content.indexOf('^'); |
| 41 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); | 41 expect(completionOffset, isNot(equals(-1)), reason: 'missing ^'); |
| 42 int nextOffset = content.indexOf('^', completionOffset + 1); | 42 int nextOffset = content.indexOf('^', completionOffset + 1); |
| 43 expect(nextOffset, equals(-1), reason: 'too many ^'); | 43 expect(nextOffset, equals(-1), reason: 'too many ^'); |
| 44 content = content.substring(0, completionOffset) + | 44 content = content.substring(0, completionOffset) + |
| 45 content.substring(completionOffset + 1); | 45 content.substring(completionOffset + 1); |
| 46 testSource = addSource(testFile, content); | 46 testSource = addSource(testFile, content); |
| 47 } | 47 } |
| 48 | 48 |
| 49 void assertSuggestClass(String className, [CompletionRelevance relevance = | 49 void assertNotSuggested(String completion) { |
| 50 CompletionRelevance.DEFAULT]) { | 50 if (suggestions.any((cs) => cs.completion == completion)) { |
| 51 assertSuggest(CompletionSuggestionKind.CLASS, className, relevance); | 51 fail('did not expect completion: $completion'); |
| 52 } | 52 } |
| 53 | |
| 54 void assertSuggestFunction(String completion, [CompletionRelevance relevance = | |
| 55 CompletionRelevance.DEFAULT]) { | |
| 56 assertSuggest(CompletionSuggestionKind.FUNCTION, completion, relevance); | |
| 57 } | 53 } |
| 58 | 54 |
| 59 void assertSuggest(CompletionSuggestionKind kind, String completion, | 55 void assertSuggest(CompletionSuggestionKind kind, String completion, |
| 60 [CompletionRelevance relevance = CompletionRelevance.DEFAULT, bool isDepre
cated | 56 [CompletionRelevance relevance = CompletionRelevance.DEFAULT, bool isDepre
cated |
| 61 = false, bool isPotential = false]) { | 57 = false, bool isPotential = false]) { |
| 62 var cs = | 58 var cs = |
| 63 suggestions.firstWhere((cs) => cs.completion == completion, orElse: () { | 59 suggestions.firstWhere((cs) => cs.completion == completion, orElse: () { |
| 64 var completions = suggestions.map((s) => s.completion).toList(); | 60 var completions = suggestions.map((s) => s.completion).toList(); |
| 65 fail('expected "$completion" but found\n $completions'); | 61 fail('expected "$completion" but found\n $completions'); |
| 66 }); | 62 }); |
| 67 expect(cs.kind, equals(kind)); | 63 expect(cs.kind, equals(kind)); |
| 68 expect(cs.relevance, equals(relevance)); | 64 expect(cs.relevance, equals(relevance)); |
| 69 expect(cs.selectionOffset, equals(completion.length)); | 65 expect(cs.selectionOffset, equals(completion.length)); |
| 70 expect(cs.selectionLength, equals(0)); | 66 expect(cs.selectionLength, equals(0)); |
| 71 expect(cs.isDeprecated, equals(isDeprecated)); | 67 expect(cs.isDeprecated, equals(isDeprecated)); |
| 72 expect(cs.isPotential, equals(isPotential)); | 68 expect(cs.isPotential, equals(isPotential)); |
| 73 } | 69 } |
| 74 | 70 |
| 75 void assertNotSuggested(String completion) { | 71 void assertSuggestClass(String className, [CompletionRelevance relevance = |
| 76 if (suggestions.any((cs) => cs.completion == completion)) { | 72 CompletionRelevance.DEFAULT]) { |
| 77 fail('did not expect completion: $completion'); | 73 assertSuggest(CompletionSuggestionKind.CLASS, className, relevance); |
| 78 } | |
| 79 } | 74 } |
| 80 | 75 |
| 81 void assertSuggestTopLevelVar(String varName, [CompletionRelevance relevance = | 76 void assertSuggestField(String completion, [CompletionRelevance relevance = |
| 82 CompletionRelevance.DEFAULT]) { | 77 CompletionRelevance.DEFAULT]) { |
| 78 assertSuggest(CompletionSuggestionKind.FIELD, completion, relevance); |
| 79 } |
| 80 |
| 81 void assertSuggestFunction(String completion, [CompletionRelevance relevance = |
| 82 CompletionRelevance.DEFAULT]) { |
| 83 assertSuggest(CompletionSuggestionKind.FUNCTION, completion, relevance); |
| 84 } |
| 85 |
| 86 void assertSuggestLibraryPrefix(String completion, |
| 87 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { |
| 88 assertSuggest( |
| 89 CompletionSuggestionKind.LIBRARY_PREFIX, |
| 90 completion, |
| 91 relevance); |
| 92 } |
| 93 |
| 94 void assertSuggestMethodName(String completion, [CompletionRelevance relevance |
| 95 = CompletionRelevance.DEFAULT]) { |
| 96 assertSuggest(CompletionSuggestionKind.METHOD_NAME, completion, relevance); |
| 97 } |
| 98 |
| 99 void assertSuggestParameter(String completion, [CompletionRelevance relevance |
| 100 = CompletionRelevance.DEFAULT]) { |
| 101 assertSuggest(CompletionSuggestionKind.PARAMETER, completion, relevance); |
| 102 } |
| 103 |
| 104 void assertSuggestTopLevelVar(String completion, |
| 105 [CompletionRelevance relevance = CompletionRelevance.DEFAULT]) { |
| 83 assertSuggest( | 106 assertSuggest( |
| 84 CompletionSuggestionKind.TOP_LEVEL_VARIABLE, | 107 CompletionSuggestionKind.TOP_LEVEL_VARIABLE, |
| 85 varName, | 108 completion, |
| 86 relevance); | 109 relevance); |
| 87 } | 110 } |
| 88 | 111 |
| 112 void assertSuggestVariable(String completion, [CompletionRelevance relevance = |
| 113 CompletionRelevance.DEFAULT]) { |
| 114 assertSuggest(CompletionSuggestionKind.VARIABLE, completion, relevance); |
| 115 } |
| 116 |
| 89 bool computeFast() { | 117 bool computeFast() { |
| 90 _computeFastCalled = true; | 118 _computeFastCalled = true; |
| 91 computer | 119 computer |
| 92 ..context = context | 120 ..context = context |
| 93 ..searchEngine = searchEngine | 121 ..searchEngine = searchEngine |
| 94 ..source = testSource | 122 ..source = testSource |
| 95 ..offset = completionOffset; | 123 ..offset = completionOffset; |
| 96 suggestions = []; | 124 suggestions = []; |
| 97 CompilationUnit unit = context.parseCompilationUnit(testSource); | 125 CompilationUnit unit = context.parseCompilationUnit(testSource); |
| 98 return computer.computeFast(unit, suggestions); | 126 return computer.computeFast(unit, suggestions); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 120 } | 148 } |
| 121 | 149 |
| 122 @override | 150 @override |
| 123 void setUp() { | 151 void setUp() { |
| 124 super.setUp(); | 152 super.setUp(); |
| 125 index = createLocalMemoryIndex(); | 153 index = createLocalMemoryIndex(); |
| 126 searchEngine = new SearchEngineImpl(index); | 154 searchEngine = new SearchEngineImpl(index); |
| 127 addResolvedUnit(MockSdk.LIB_CORE.path, MockSdk.LIB_CORE.content); | 155 addResolvedUnit(MockSdk.LIB_CORE.path, MockSdk.LIB_CORE.content); |
| 128 } | 156 } |
| 129 } | 157 } |
| OLD | NEW |