Skip to content

Commit

Permalink
Convert local library completion tests
Browse files Browse the repository at this point in the history
Change-Id: I565572911964a683d203d8a40ccfd8e96845ca0b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304288
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Brian Wilkerson <[email protected]>
  • Loading branch information
bwilkerson authored and Commit Queue committed May 20, 2023
1 parent 041a8ef commit 7419e25
Show file tree
Hide file tree
Showing 4 changed files with 366 additions and 323 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,364 @@
// Copyright (c) 2023, 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.

import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../../../../client/completion_driver_test.dart';

void main() {
defineReflectiveSuite(() {
defineReflectiveTests(LocalLibraryTest1);
defineReflectiveTests(LocalLibraryTest2);
});
}

@reflectiveTest
class LocalLibraryTest1 extends AbstractCompletionDriverTest
with LocalLibraryTestCases {
@override
TestingCompletionProtocol get protocol => TestingCompletionProtocol.version1;
}

@reflectiveTest
class LocalLibraryTest2 extends AbstractCompletionDriverTest
with LocalLibraryTestCases {
@override
TestingCompletionProtocol get protocol => TestingCompletionProtocol.version2;
}

mixin LocalLibraryTestCases on AbstractCompletionDriverTest {
@override
bool get includeKeywords => false;

Future<void> test_partFile_Constructor() async {
newFile('$testPackageLibPath/b.dart', '''
library B;
int T0 = 0;
F0() {}
class X {
X.c();
X._d0();
z0() {}
}
void f() {
X._d0();
}
''');
newFile('$testPackageLibPath/a.dart', '''
library libA;
import "b.dart";
part "test.dart";
class A0 {}
var m0 = T0;
''');
await computeSuggestions('''
part of libA;
class B {
B.bar(int x);
}
void f() {
new ^
}
''');
assertResponse(r'''
suggestions
A0
kind: constructorInvocation
''');
}

Future<void> test_partFile_Constructor2() async {
newFile('$testPackageLibPath/b.dart', '''
library B0;
int T0 = 0;
F0() {}
class X {
X.c();
X._d0();
z0() {}
}
void f() {
X._d0();
}
''');
newFile('$testPackageLibPath/a.dart', '''
part of libA;
class B0 {}
''');
await computeSuggestions('''
library libA;
import "b.dart";
part "a.dart";
class A0 {
A0({String boo: 'hoo'}) {}
}
void f() {
new ^
}
var m0 = T0;
''');
assertResponse(r'''
suggestions
A0
kind: constructorInvocation
B0
kind: constructorInvocation
''');
}

Future<void> test_partFile_extension() async {
newFile('$testPackageLibPath/a.dart', '''
part of libA;
extension E0 on int {}
''');
await computeSuggestions('''
library libA;
part "a.dart";
void f() {
^
}
''');
assertResponse(r'''
suggestions
E0
kind: extensionInvocation
''');
}

Future<void> test_partFile_extension_unnamed() async {
newFile('$testPackageLibPath/a.dart', '''
part of libA;
extension on int {}
''');
await computeSuggestions('''
library libA;
part "a.dart";
void f() {
^
}
''');
assertResponse(r'''
suggestions
''');
}

Future<void>
test_partFile_InstanceCreationExpression_assignment_filter() async {
newFile('$testPackageLibPath/b.dart', '''
library B0;
int T0 = 0;
F0() {}
class X {
X.c();
X._d0();
z0() {}
}
void f() {
X._d0();
}
''');
newFile('$testPackageLibPath/a.dart', '''
part of libA;
class A0 {}
class B0 extends A0 {}
class C0 implements A0 {}
class D0 {}
''');
await computeSuggestions('''
library libA;
import "b.dart";
part "a.dart";
class L0 {}
void f() {
A0 a;
// FAIL:
a = new ^
}
var m0 = T0;
''');
assertResponse(r'''
suggestions
A0
kind: constructorInvocation
B0
kind: constructorInvocation
C0
kind: constructorInvocation
D0
kind: constructorInvocation
L0
kind: constructorInvocation
''');
}

Future<void>
test_partFile_InstanceCreationExpression_variable_declaration_filter() async {
newFile('$testPackageLibPath/b.dart', '''
library B0;
int T0 = 0;
F0() {}
class X {
X.c();
X._d0();
z0() {}
}
void f() {
X._d0();
}
''');
newFile('$testPackageLibPath/a.dart', '''
part of libA;
class A0 {}
class B0 extends A0 {}
class C0 implements A0 {}
class D0 {}
''');
await computeSuggestions('''
library libA;
import "b.dart";
part "a.dart";
class L0 {}
void f() {
A0 a = new ^
}
var m0 = T0;
''');
assertResponse(r'''
suggestions
A0
kind: constructorInvocation
B0
kind: constructorInvocation
C0
kind: constructorInvocation
D0
kind: constructorInvocation
L0
kind: constructorInvocation
''');
}

Future<void> test_partFile_TypeName() async {
newFile('$testPackageLibPath/b.dart', '''
library B;
int T0 = 0;
F0() {}
class X {
X.c();
X._d0();
z0() {}
}
void f() {
X._d0();
}
''');
newFile('$testPackageLibPath/a.dart', '''
library libA;
import "b.dart";
part "test.dart";
class A0 {
var a1;
a2(){}
}
var m0 = T0;
typedef t0(int blue);
typedef t1 = void Function(int blue);
typedef t2 = List<int>;
int a0() {
return 0;
}
''');
await computeSuggestions('''
part of libA;
class B {
B.bar(int x);
}
void f() {
^
}
''');
assertResponse(r'''
suggestions
A0
kind: class
A0
kind: constructorInvocation
F0
kind: functionInvocation
T0
kind: topLevelVariable
a0
kind: functionInvocation
m0
kind: topLevelVariable
t0
kind: typeAlias
t1
kind: typeAlias
t2
kind: typeAlias
''');
}

Future<void> test_partFile_TypeName2() async {
newFile('$testPackageLibPath/b.dart', '''
library B0;
int T0 = 0;
F0() {}
class X {
X.c();
X._d0();
z0() {}
}
void f() {
X._d0();
}
''');
newFile('$testPackageLibPath/a.dart', '''
part of libA;
class B0 {
var b1;
b2(){}
}
int b0() => 0;
typedef t0(int blue);
var n0;
''');
await computeSuggestions('''
library libA;
import "b.dart";
part "a.dart";
class A0 {
A0({String boo: 'hoo'}) {}
}
void f() {
^
}
var m0 = T0;
''');
assertResponse(r'''
suggestions
A0
kind: class
A0
kind: constructorInvocation
B0
kind: class
B0
kind: constructorInvocation
F0
kind: functionInvocation
T0
kind: topLevelVariable
b0
kind: functionInvocation
m0
kind: topLevelVariable
n0
kind: topLevelVariable
t0
kind: typeAlias
''');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'label_test.dart' as label;
import 'library_member_test.dart' as library_member;
import 'library_prefix_test.dart' as library_prefix;
import 'library_test.dart' as library_;
import 'local_library_test.dart' as local_library;
import 'pattern_variable_test.dart' as pattern_variable;
import 'record_type_test.dart' as record_type;
import 'type_member_test.dart' as type_member;
Expand All @@ -33,6 +34,7 @@ void main() {
library_member.main();
library_prefix.main();
library_.main();
local_library.main();
pattern_variable.main();
record_type.main();
type_member.main();
Expand Down
Loading

0 comments on commit 7419e25

Please sign in to comment.