mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:59:47 +00:00
Remove the DartCompletionManagerTest and replace it with CompletionRelevanceTest, making all of the completion relevance tests consistent.
Change-Id: I24d042b420a3c1d6f38b063913cb702c34858076 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151343 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Jaime Wren <jwren@google.com>
This commit is contained in:
parent
b65c90a07a
commit
047f1721a1
|
@ -68,35 +68,6 @@ abstract class DartCompletionContributorTest
|
|||
}
|
||||
}
|
||||
|
||||
/// Base class for tests that validate [DartCompletionManager] suggestions.
|
||||
class DartCompletionManagerTest extends _BaseDartCompletionContributorTest {
|
||||
DartCompletionManager completionManager;
|
||||
|
||||
@nonVirtual
|
||||
@override
|
||||
Future<List<CompletionSuggestion>> computeContributedSuggestions(
|
||||
DartCompletionRequest request) async {
|
||||
final baseRequest = CompletionRequestImpl(request.result, completionOffset,
|
||||
useNewRelevance, CompletionPerformance());
|
||||
return completionManager.computeSuggestions(baseRequest);
|
||||
}
|
||||
|
||||
/// Display sorted suggestions.
|
||||
void printSuggestions() {
|
||||
suggestions.sort(completionComparator);
|
||||
for (var s in suggestions) {
|
||||
print(
|
||||
'[${s.relevance}] ${s.completion} • ${s.element?.kind?.name ?? ""} ${s.kind.name} ${s.element?.location?.file ?? ""}');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void setUp() {
|
||||
super.setUp();
|
||||
completionManager = DartCompletionManager();
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _BaseDartCompletionContributorTest extends AbstractContextTest {
|
||||
static const String _UNCHECKED = '__UNCHECKED__';
|
||||
String testFile;
|
||||
|
|
|
@ -6,7 +6,7 @@ import 'package:analyzer_plugin/protocol/protocol_common.dart';
|
|||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../completion_contributor_util.dart';
|
||||
import 'completion_relevance.dart';
|
||||
|
||||
void main() {
|
||||
defineReflectiveSuite(() {
|
||||
|
@ -15,16 +15,14 @@ void main() {
|
|||
}
|
||||
|
||||
@reflectiveTest
|
||||
class BoolAssignmentRelevanceTest extends DartCompletionManagerTest {
|
||||
@failingTest
|
||||
class BoolAssignmentRelevanceTest extends CompletionRelevanceTest {
|
||||
Future<void> test_boolLiterals_imported() async {
|
||||
addTestSource('''
|
||||
await addTestFile('''
|
||||
foo() {
|
||||
bool b;
|
||||
b = ^
|
||||
}
|
||||
''');
|
||||
await computeSuggestions();
|
||||
|
||||
var trueSuggestion = suggestionWith(
|
||||
completion: 'true', kind: CompletionSuggestionKind.KEYWORD);
|
||||
|
@ -43,17 +41,13 @@ foo() {
|
|||
falseSuggestion.relevance, greaterThan(boolFromEnvironment.relevance));
|
||||
}
|
||||
|
||||
/// These are 2 failing tests for http://dartbug.com/37907:
|
||||
/// "Suggest `false` above other results when autocompleting a bool setter"
|
||||
@failingTest
|
||||
Future<void> test_boolLiterals_local() async {
|
||||
addTestSource('''
|
||||
await addTestFile('''
|
||||
foo() {
|
||||
bool b;
|
||||
b = ^
|
||||
}
|
||||
''');
|
||||
await computeSuggestions();
|
||||
|
||||
var trueSuggestion = suggestionWith(
|
||||
completion: 'true', kind: CompletionSuggestionKind.KEYWORD);
|
||||
|
|
|
@ -25,23 +25,28 @@ class CompletionRelevanceTest extends AbstractCompletionDriverTest {
|
|||
var length = suggestions.length;
|
||||
expect(length, greaterThan(1),
|
||||
reason: 'Test must specify more than one suggestion');
|
||||
var inOrder = true;
|
||||
var previous = suggestions[0];
|
||||
for (var i = 1; i < length; i++) {
|
||||
var current = suggestions[i];
|
||||
if (current.relevance >= previous.relevance) {
|
||||
suggestions.sort(
|
||||
(first, second) => second.relevance.compareTo(first.relevance));
|
||||
var buffer = StringBuffer();
|
||||
buffer.write('Suggestions are not in the expected order. ');
|
||||
buffer.writeln('To accept the current state, use');
|
||||
buffer.writeln();
|
||||
for (var suggestion in suggestions) {
|
||||
var completion = suggestion.completion;
|
||||
buffer.writeln(" suggestionWith(completion: '$completion'),");
|
||||
}
|
||||
fail(buffer.toString());
|
||||
inOrder = false;
|
||||
}
|
||||
previous = current;
|
||||
}
|
||||
if (!inOrder) {
|
||||
suggestions.sort((first, second) => second.relevance - first.relevance);
|
||||
var buffer = StringBuffer();
|
||||
buffer.writeln('Actual sort order does not match expected order.');
|
||||
buffer.writeln('To accept the actual sort order, use:');
|
||||
buffer.writeln();
|
||||
buffer.writeln(' assertOrder([');
|
||||
for (var suggestion in suggestions) {
|
||||
var completion = suggestion.completion;
|
||||
buffer.writeln(" suggestionWith(completion: '$completion'),");
|
||||
}
|
||||
buffer.writeln(' ]);');
|
||||
fail(buffer.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,9 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../completion_contributor_util.dart';
|
||||
import 'completion_relevance.dart';
|
||||
|
||||
void main() {
|
||||
defineReflectiveSuite(() {
|
||||
|
@ -15,9 +14,9 @@ void main() {
|
|||
}
|
||||
|
||||
@reflectiveTest
|
||||
class DeprecatedMemberRelevanceTest extends DartCompletionManagerTest {
|
||||
class DeprecatedMemberRelevanceTest extends CompletionRelevanceTest {
|
||||
Future<void> test_deprecated() async {
|
||||
addTestSource('''
|
||||
await addTestFile('''
|
||||
class A {
|
||||
void a1() { }
|
||||
@deprecated
|
||||
|
@ -29,18 +28,16 @@ void main() {
|
|||
a.^
|
||||
}
|
||||
''');
|
||||
await computeSuggestions();
|
||||
|
||||
expect(
|
||||
suggestionWith(
|
||||
completion: 'a2',
|
||||
element: ElementKind.METHOD,
|
||||
kind: CompletionSuggestionKind.INVOCATION)
|
||||
.relevance,
|
||||
lessThan(suggestionWith(
|
||||
completion: 'a1',
|
||||
element: ElementKind.METHOD,
|
||||
kind: CompletionSuggestionKind.INVOCATION)
|
||||
.relevance));
|
||||
assertOrder([
|
||||
suggestionWith(
|
||||
completion: 'a1',
|
||||
element: ElementKind.METHOD,
|
||||
kind: CompletionSuggestionKind.INVOCATION),
|
||||
suggestionWith(
|
||||
completion: 'a2',
|
||||
element: ElementKind.METHOD,
|
||||
kind: CompletionSuggestionKind.INVOCATION),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,9 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'package:analysis_server/src/analysis_server.dart';
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../../../../client/completion_driver_test.dart';
|
||||
import 'completion_relevance.dart';
|
||||
|
||||
void main() {
|
||||
defineReflectiveSuite(() {
|
||||
|
@ -16,7 +14,7 @@ void main() {
|
|||
}
|
||||
|
||||
@reflectiveTest
|
||||
class InstanceMemberRelevanceTest extends AbstractCompletionDriverTest {
|
||||
class InstanceMemberRelevanceTest extends CompletionRelevanceTest {
|
||||
@override
|
||||
AnalysisServerOptions get serverOptions =>
|
||||
AnalysisServerOptions()..useNewRelevance = true;
|
||||
|
@ -24,37 +22,6 @@ class InstanceMemberRelevanceTest extends AbstractCompletionDriverTest {
|
|||
@override
|
||||
bool get supportsAvailableSuggestions => true;
|
||||
|
||||
/// Assert that all of the given completions were produced and that the
|
||||
/// suggestions are ordered in decreasing order based on relevance scores.
|
||||
void assertOrder(List<CompletionSuggestion> suggestions) {
|
||||
var length = suggestions.length;
|
||||
expect(length, greaterThan(1),
|
||||
reason: 'Test must specify more than one suggestion');
|
||||
var inOrder = true;
|
||||
var previous = suggestions[0];
|
||||
for (var i = 1; i < length; i++) {
|
||||
var current = suggestions[i];
|
||||
if (current.relevance >= previous.relevance) {
|
||||
inOrder = false;
|
||||
}
|
||||
previous = current;
|
||||
}
|
||||
if (!inOrder) {
|
||||
suggestions.sort((first, second) => second.relevance - first.relevance);
|
||||
var buffer = StringBuffer();
|
||||
buffer.writeln('Actual sort order does not match expected order.');
|
||||
buffer.writeln('To accept the actual sort order, use:');
|
||||
buffer.writeln();
|
||||
buffer.writeln(' assertOrder([');
|
||||
for (var suggestion in suggestions) {
|
||||
var completion = suggestion.completion;
|
||||
buffer.writeln(" suggestionWith(completion: '$completion'),");
|
||||
}
|
||||
buffer.writeln(' ]);');
|
||||
fail(buffer.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> test_contextType() async {
|
||||
await addTestFile(r'''
|
||||
class A {}
|
||||
|
|
Loading…
Reference in a new issue