mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 16:00:45 +00:00
Convert the tests for the combinator contributor
Change-Id: Ic165bf7fed1f045f489998ecf9dec9edbd516274 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/298480 Commit-Queue: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
7a5061e71a
commit
03270f748b
|
@ -1,172 +0,0 @@
|
|||
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
/// This file contains tests written in a deprecated way. Please do not add any
|
||||
/// tests to this file. Instead, add tests to the files in `declaration`,
|
||||
/// `location`, or `relevance`.
|
||||
library;
|
||||
|
||||
import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/combinator_contributor.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/completion_manager.dart';
|
||||
import 'package:analysis_server/src/services/completion/dart/suggestion_builder.dart';
|
||||
import 'package:analyzer_plugin/protocol/protocol_common.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import 'completion_contributor_util.dart';
|
||||
|
||||
void main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(CombinatorContributorTest);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class CombinatorContributorTest extends DartCompletionContributorTest {
|
||||
@override
|
||||
DartCompletionContributor createContributor(
|
||||
DartCompletionRequest request,
|
||||
SuggestionBuilder builder,
|
||||
) {
|
||||
return CombinatorContributor(request, builder);
|
||||
}
|
||||
|
||||
Future<void> test_Block_inherited_local() async {
|
||||
// Block BlockFunctionBody MethodDeclaration ClassDeclaration
|
||||
addTestSource('''
|
||||
class F { var f1; f2() { } }
|
||||
class E extends F { var e1; e2() { } }
|
||||
class I { int i1; i2() { } }
|
||||
class M { var m1; int m2() { } }
|
||||
class A extends E implements I with M {a() {^}}''');
|
||||
await computeSuggestions();
|
||||
assertNoSuggestions();
|
||||
}
|
||||
|
||||
Future<void> test_Combinator_hide() async {
|
||||
// SimpleIdentifier HideCombinator ImportDirective
|
||||
newFile('$testPackageLibPath/ab.dart', '''
|
||||
library libAB;
|
||||
part "ab_part.dart";
|
||||
class A { }
|
||||
class B { }''');
|
||||
newFile('$testPackageLibPath/ab_part.dart', '''
|
||||
part of libAB;
|
||||
var T1;
|
||||
PB F1() => new PB();
|
||||
class PB { }''');
|
||||
newFile('$testPackageLibPath/cd.dart', '''
|
||||
class C { }
|
||||
class D { }''');
|
||||
addTestSource('''
|
||||
import "ab.dart" hide ^;
|
||||
import "cd.dart";
|
||||
class X {}''');
|
||||
|
||||
await computeSuggestions();
|
||||
assertSuggestClass('A', kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
assertSuggestClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
assertSuggestClass('PB', kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
assertSuggestTopLevelVar('T1', null);
|
||||
assertSuggestFunction('F1', 'PB',
|
||||
kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
assertNotSuggested('C');
|
||||
assertNotSuggested('D');
|
||||
assertNotSuggested('X');
|
||||
assertNotSuggested('Object');
|
||||
}
|
||||
|
||||
Future<void> test_Combinator_hide_duplicate() async {
|
||||
addTestSource('import "dart:math" hide PI, ^;');
|
||||
await computeSuggestions();
|
||||
assertNotSuggested('PI');
|
||||
}
|
||||
|
||||
Future<void> test_Combinator_show() async {
|
||||
// SimpleIdentifier HideCombinator ImportDirective
|
||||
newFile('$testPackageLibPath/ab.dart', '''
|
||||
library libAB;
|
||||
part "ab_part.dart";
|
||||
class A { }
|
||||
class B { }
|
||||
class _AB''');
|
||||
newFile('$testPackageLibPath/ab_part.dart', '''
|
||||
part of libAB;
|
||||
var T1;
|
||||
PB F1() => new PB();
|
||||
typedef PB2 F2(int blat);
|
||||
class Clz = Object with Object;
|
||||
class PB { }''');
|
||||
newFile('$testPackageLibPath/cd.dart', '''
|
||||
class C { }
|
||||
class D { }''');
|
||||
addTestSource('''
|
||||
import "ab.dart" show ^;
|
||||
import "cd.dart";
|
||||
class X {}''');
|
||||
|
||||
await computeSuggestions();
|
||||
assertSuggestClass('A', kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
assertSuggestClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
assertNotSuggested('_AB');
|
||||
assertSuggestClass('PB', kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
assertSuggestTopLevelVar('T1', null);
|
||||
assertSuggestFunction('F1', 'PB',
|
||||
kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
assertSuggestClass('Clz', kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
assertSuggestTypeAlias('F2',
|
||||
kind: CompletionSuggestionKind.IDENTIFIER,
|
||||
aliasedType: 'dynamic Function(int)',
|
||||
returnType: 'dynamic');
|
||||
assertNotSuggested('C');
|
||||
assertNotSuggested('D');
|
||||
assertNotSuggested('X');
|
||||
assertNotSuggested('Object');
|
||||
}
|
||||
|
||||
Future<void> test_Combinator_show_duplicate() async {
|
||||
addTestSource('import "dart:math" show PI, ^;');
|
||||
await computeSuggestions();
|
||||
assertNotSuggested('PI');
|
||||
}
|
||||
|
||||
Future<void> test_Combinator_show_export_withShow() async {
|
||||
newFile('$testPackageLibPath/a.dart', r'''
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
newFile('$testPackageLibPath/b.dart', r'''
|
||||
export 'a.dart' show A;
|
||||
''');
|
||||
addTestSource(r'''
|
||||
import 'b.dart' show ^;
|
||||
''');
|
||||
await computeSuggestions();
|
||||
assertSuggestClass('A', kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
assertNotSuggested('B');
|
||||
}
|
||||
|
||||
Future<void> test_Combinator_show_pi() async {
|
||||
addTestSource('import "dart:math" show ^;');
|
||||
await computeSuggestions();
|
||||
assertSuggestTopLevelVar('pi', 'double');
|
||||
}
|
||||
|
||||
Future<void> test_Combinator_show_recursive() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
class A {}
|
||||
''');
|
||||
newFile('$testPackageLibPath/b.dart', '''
|
||||
export 'a.dart';
|
||||
export 'b.dart';
|
||||
class B {}
|
||||
''');
|
||||
addTestSource('''
|
||||
import "b.dart" show ^;
|
||||
''');
|
||||
await computeSuggestions();
|
||||
assertSuggestClass('A', kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
assertSuggestClass('B', kind: CompletionSuggestionKind.IDENTIFIER);
|
||||
}
|
||||
}
|
|
@ -96,6 +96,8 @@ class CompletionResponsePrinter {
|
|||
return 'extension';
|
||||
} else if (elementKind == ElementKind.FIELD) {
|
||||
return 'field';
|
||||
} else if (elementKind == ElementKind.FUNCTION) {
|
||||
return 'function';
|
||||
} else if (elementKind == ElementKind.GETTER) {
|
||||
return 'getter';
|
||||
} else if (elementKind == ElementKind.LIBRARY) {
|
||||
|
|
|
@ -1114,10 +1114,36 @@ suggestions
|
|||
mixin MethodBodyTestCases on AbstractCompletionDriverTest {
|
||||
Future<void> test_afterLeftBrace_beforeRightBrace() async {
|
||||
await computeSuggestions('''
|
||||
class A { foo() {^}}
|
||||
class F0 { var f1; f2() {} }
|
||||
class E0 extends F0 { var e1; e2() {} }
|
||||
class I0 { int i1; i2() {} }
|
||||
class M0 { var m1; int m2() {} }
|
||||
class A0 extends E0 implements I0 with M0 {a() {^}}
|
||||
''');
|
||||
// Part of the purpose of this test is to ensure that none of the top-level
|
||||
// names are duplicated.
|
||||
assertResponse(r'''
|
||||
suggestions
|
||||
A0
|
||||
kind: class
|
||||
A0
|
||||
kind: constructorInvocation
|
||||
E0
|
||||
kind: class
|
||||
E0
|
||||
kind: constructorInvocation
|
||||
F0
|
||||
kind: class
|
||||
F0
|
||||
kind: constructorInvocation
|
||||
I0
|
||||
kind: class
|
||||
I0
|
||||
kind: constructorInvocation
|
||||
M0
|
||||
kind: class
|
||||
M0
|
||||
kind: constructorInvocation
|
||||
assert
|
||||
kind: keyword
|
||||
const
|
||||
|
@ -1126,14 +1152,30 @@ suggestions
|
|||
kind: keyword
|
||||
dynamic
|
||||
kind: keyword
|
||||
e1
|
||||
kind: field
|
||||
e2
|
||||
kind: methodInvocation
|
||||
f1
|
||||
kind: field
|
||||
f2
|
||||
kind: methodInvocation
|
||||
final
|
||||
kind: keyword
|
||||
for
|
||||
kind: keyword
|
||||
i1
|
||||
kind: field
|
||||
i2
|
||||
kind: methodInvocation
|
||||
if
|
||||
kind: keyword
|
||||
late
|
||||
kind: keyword
|
||||
m1
|
||||
kind: field
|
||||
m2
|
||||
kind: methodInvocation
|
||||
return
|
||||
kind: keyword
|
||||
super
|
||||
|
|
|
@ -13,16 +13,68 @@ void main() {
|
|||
});
|
||||
}
|
||||
|
||||
mixin HideClauseTestCases on AbstractCompletionDriverTest {
|
||||
Future<void> test_afterComma_beforeSemicolon() async {
|
||||
allowedIdentifiers = {'pi'};
|
||||
await computeSuggestions('''
|
||||
import "dart:math" hide pi, ^;
|
||||
''');
|
||||
// The purpose of this test is to ensure that `pi` is not suggested.
|
||||
assertResponse(r'''
|
||||
suggestions
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_afterHide_beforeSemicolon() async {
|
||||
newFile('$testPackageLibPath/ab.dart', '''
|
||||
library libAB;
|
||||
part "ab_part.dart";
|
||||
class A0 {}
|
||||
class B0 {}
|
||||
''');
|
||||
newFile('$testPackageLibPath/ab_part.dart', '''
|
||||
part of libAB;
|
||||
var T1;
|
||||
P0 F1() => new P0();
|
||||
class P0 {}
|
||||
''');
|
||||
newFile('$testPackageLibPath/cd.dart', '''
|
||||
class C0 {}
|
||||
class D0 {}
|
||||
''');
|
||||
await computeSuggestions('''
|
||||
import "ab.dart" hide ^;
|
||||
import "cd.dart";
|
||||
class F0 {}
|
||||
''');
|
||||
// Part of the purpose of this test is to ensure that we don't suggest names
|
||||
// from other imports ('C0' and 'D0') or locally defined names ('F0').
|
||||
assertResponse(r'''
|
||||
suggestions
|
||||
A0
|
||||
kind: class
|
||||
B0
|
||||
kind: class
|
||||
F1
|
||||
kind: function
|
||||
P0
|
||||
kind: class
|
||||
T1
|
||||
kind: topLevelVariable
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ImportDirectiveTest1 extends AbstractCompletionDriverTest
|
||||
with ImportDirectiveTestCases {
|
||||
with HideClauseTestCases, ImportDirectiveTestCases, ShowClauseTestCases {
|
||||
@override
|
||||
TestingCompletionProtocol get protocol => TestingCompletionProtocol.version1;
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ImportDirectiveTest2 extends AbstractCompletionDriverTest
|
||||
with ImportDirectiveTestCases {
|
||||
with HideClauseTestCases, ImportDirectiveTestCases, ShowClauseTestCases {
|
||||
@override
|
||||
TestingCompletionProtocol get protocol => TestingCompletionProtocol.version2;
|
||||
}
|
||||
|
@ -332,3 +384,115 @@ suggestions
|
|||
''');
|
||||
}
|
||||
}
|
||||
|
||||
mixin ShowClauseTestCases on AbstractCompletionDriverTest {
|
||||
Future<void> test_afterComma_beforeSemicolon() async {
|
||||
await computeSuggestions('''
|
||||
import "dart:math" show pi, ^;
|
||||
''');
|
||||
// The purpose of this test is to ensure that `pi` is not suggested.
|
||||
assertResponse(r'''
|
||||
suggestions
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_afterShow_beforeSemicolon() async {
|
||||
newFile('$testPackageLibPath/ab.dart', '''
|
||||
library libAB;
|
||||
part "ab_part.dart";
|
||||
class A0 {}
|
||||
class B0 {}
|
||||
class _A1 {}
|
||||
void f(_A1 a) {}
|
||||
''');
|
||||
newFile('$testPackageLibPath/ab_part.dart', '''
|
||||
part of libAB;
|
||||
var T1;
|
||||
P1 F1() => new P1();
|
||||
typedef P1 F2(int blat);
|
||||
class C1 = Object with M;
|
||||
class P1 {}
|
||||
mixin M {}
|
||||
''');
|
||||
newFile('$testPackageLibPath/cd.dart', '''
|
||||
class C0 {}
|
||||
class D0 {}
|
||||
''');
|
||||
await computeSuggestions('''
|
||||
import "ab.dart" show ^;
|
||||
import "cd.dart";
|
||||
class G0 {}
|
||||
''');
|
||||
// Part of the purpose of this test is to ensure that we don't suggest names
|
||||
// from other imports ('C0' and 'D0') or locally defined names ('G0').
|
||||
assertResponse(r'''
|
||||
suggestions
|
||||
A0
|
||||
kind: class
|
||||
B0
|
||||
kind: class
|
||||
C1
|
||||
kind: class
|
||||
F1
|
||||
kind: function
|
||||
F2
|
||||
kind: typeAlias
|
||||
P1
|
||||
kind: class
|
||||
T1
|
||||
kind: topLevelVariable
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_afterShow_beforeSemicolon_math() async {
|
||||
allowedIdentifiers = {'pi'};
|
||||
await computeSuggestions('''
|
||||
import "dart:math" show ^;
|
||||
''');
|
||||
assertResponse(r'''
|
||||
suggestions
|
||||
pi
|
||||
kind: topLevelVariable
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_afterShow_beforeSemicolon_recursiveExport() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
class A0 {}
|
||||
''');
|
||||
newFile('$testPackageLibPath/b.dart', '''
|
||||
export 'a.dart';
|
||||
export 'b.dart';
|
||||
class B0 {}
|
||||
''');
|
||||
await computeSuggestions('''
|
||||
import "b.dart" show ^;
|
||||
''');
|
||||
assertResponse(r'''
|
||||
suggestions
|
||||
A0
|
||||
kind: class
|
||||
B0
|
||||
kind: class
|
||||
''');
|
||||
}
|
||||
|
||||
Future<void> test_afterShow_beforeSemicolon_withRestrictedExport() async {
|
||||
newFile('$testPackageLibPath/a.dart', '''
|
||||
class A0 {}
|
||||
class B0 {}
|
||||
''');
|
||||
newFile('$testPackageLibPath/b.dart', '''
|
||||
export 'a.dart' show A0;
|
||||
''');
|
||||
await computeSuggestions('''
|
||||
import 'b.dart' show ^;
|
||||
''');
|
||||
// The purpose of this test is to ensure that `B0` is not suggested.
|
||||
assertResponse(r'''
|
||||
suggestions
|
||||
A0
|
||||
kind: class
|
||||
''');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import 'package:test_reflective_loader/test_reflective_loader.dart';
|
|||
|
||||
import 'arglist_contributor_test.dart' as arglist_test;
|
||||
import 'closure_contributor_test.dart' as closure_contributor;
|
||||
import 'combinator_contributor_test.dart' as combinator_test;
|
||||
import 'completion_manager_test.dart' as completion_manager;
|
||||
import 'declaration/test_all.dart' as declaration;
|
||||
import 'extension_member_contributor_test.dart' as extension_member_contributor;
|
||||
|
@ -29,7 +28,6 @@ void main() {
|
|||
defineReflectiveSuite(() {
|
||||
arglist_test.main();
|
||||
closure_contributor.main();
|
||||
combinator_test.main();
|
||||
completion_manager.main();
|
||||
declaration.main();
|
||||
extension_member_contributor.main();
|
||||
|
|
Loading…
Reference in a new issue