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

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

Issue 1525753003: extract LocalLibraryContributor from imported reference contributor (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: merge Created 5 years 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
Index: pkg/analysis_server/test/services/completion/dart/local_library_contributor_test.dart
diff --git a/pkg/analysis_server/test/services/completion/dart/local_library_contributor_test.dart b/pkg/analysis_server/test/services/completion/dart/local_library_contributor_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8b2459f8344302b1360ff56a68c4b0b8cfafa8b8
--- /dev/null
+++ b/pkg/analysis_server/test/services/completion/dart/local_library_contributor_test.dart
@@ -0,0 +1,194 @@
+// Copyright (c) 2015, 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.
+
+library test.services.completion.contributor.dart.local_lib;
+
+import 'package:analysis_server/src/provisional/completion/dart/completion_dart.dart';
+import 'package:analysis_server/src/services/completion/dart/local_library_contributor.dart';
+import 'package:test_reflective_loader/test_reflective_loader.dart';
+import 'package:unittest/unittest.dart';
+
+import '../../../utils.dart';
+import 'completion_contributor_util.dart';
+
+main() {
+ initializeTestEnvironment();
+ defineReflectiveTests(LocalLibraryContributorTest);
+}
+
+@reflectiveTest
+class LocalLibraryContributorTest extends DartCompletionContributorTest {
+ @override
+ DartCompletionContributor createContributor() {
+ return new LocalLibraryContributor();
+ }
+
+ test_partFile_Constructor() async {
+ // SimpleIdentifier TypeName ConstructorName
+ addSource(
+ '/testB.dart',
+ '''
+ lib B;
+ int T1;
+ F1() { }
+ class X {X.c(); X._d(); z() {}}''');
+ addSource(
+ '/testA.dart',
+ '''
+ library libA;
+ import "/testB.dart";
+ part "$testFile";
+ class A { }
+ var m;''');
+ addTestSource('''
+ part of libA;
+ class B { factory B.bar(int x) => null; }
+ main() {new ^}''');
+ await computeLibrariesContaining();
+ await computeSuggestions();
+ expect(replacementOffset, completionOffset);
+ expect(replacementLength, 0);
+ assertSuggestConstructor('A');
+ // Suggested by LocalConstructorContributor
+ assertNotSuggested('B.bar');
+ // Suggested by ImportedReferenceContributor
+ assertNotSuggested('Object');
+ assertNotSuggested('X.c');
+ assertNotSuggested('X._d');
+ assertNotSuggested('F1');
+ assertNotSuggested('T1');
+ assertNotSuggested('_d');
+ assertNotSuggested('z');
+ assertNotSuggested('m');
+ }
+
+ test_partFile_TypeName() async {
+ addSource(
+ '/testB.dart',
+ '''
+ lib B;
+ int T1;
+ F1() { }
+ class X {X.c(); X._d(); z() {}}''');
+ addSource(
+ '/testA.dart',
+ '''
+ library libA;
+ import "/testB.dart";
+ part "$testFile";
+ class A { var a1; a2(){}}
+ var m;
+ int af() {return 0;}''');
+ addTestSource('''
+ part of libA;
+ class B { factory B.bar(int x) => null; }
+ main() {^}''');
+ await computeLibrariesContaining();
+ await computeSuggestions();
+ expect(replacementOffset, completionOffset);
+ expect(replacementLength, 0);
+ assertSuggestClass('A');
+ assertSuggestFunction('af', 'int',
+ relevance: DART_RELEVANCE_LOCAL_FUNCTION);
+ assertSuggestTopLevelVar('m', null,
+ relevance: DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE);
+ assertNotSuggested('a1');
+ assertNotSuggested('a2');
+ // Suggested by LocalConstructorContributor
+ assertNotSuggested('B.bar');
+ // Suggested by ImportedReferenceContributor
+ assertNotSuggested('Object');
+ assertNotSuggested('X.c');
+ assertNotSuggested('X._d');
+ assertNotSuggested('F1');
+ assertNotSuggested('T1');
+ assertNotSuggested('_d');
+ assertNotSuggested('z');
+ }
+
+ test_partFile_Constructor2() async {
+ // SimpleIdentifier TypeName ConstructorName
+ addSource(
+ '/testB.dart',
+ '''
+ lib B;
+ int T1;
+ F1() { }
+ class X {X.c(); X._d(); z() {}}''');
+ addSource(
+ '/testA.dart',
+ '''
+ part of libA;
+ class B { }''');
+ addTestSource('''
+ library libA;
+ import "/testB.dart";
+ part "/testA.dart";
+ class A { A({String boo: 'hoo'}) { } }
+ main() {new ^}
+ var m;''');
+ await computeLibrariesContaining();
+ await computeSuggestions();
+ expect(replacementOffset, completionOffset);
+ expect(replacementLength, 0);
+ assertSuggestConstructor('B');
+ // Suggested by ConstructorContributor
+ assertNotSuggested('A');
+ // Suggested by ImportedReferenceContributor
+ assertNotSuggested('Object');
+ assertNotSuggested('X.c');
+ assertNotSuggested('X._d');
+ assertNotSuggested('F1');
+ assertNotSuggested('T1');
+ assertNotSuggested('_d');
+ assertNotSuggested('z');
+ assertNotSuggested('m');
+ }
+
+ test_partFile_TypeName2() async {
+ addSource(
+ '/testB.dart',
+ '''
+ lib B;
+ int T1;
+ F1() { }
+ class X {X.c(); X._d(); z() {}}''');
+ addSource(
+ '/testA.dart',
+ '''
+ part of libA;
+ class B { var b1; b2(){}}
+ int bf() => 0;
+ var n;''');
+ addTestSource('''
+ library libA;
+ import "/testB.dart";
+ part "/testA.dart";
+ class A { A({String boo: 'hoo'}) { } }
+ main() {^}
+ var m;''');
+ await computeLibrariesContaining();
+ await computeSuggestions();
+ expect(replacementOffset, completionOffset);
+ expect(replacementLength, 0);
+ assertSuggestClass('B');
+ assertSuggestFunction('bf', 'int',
+ relevance: DART_RELEVANCE_LOCAL_FUNCTION);
+ assertSuggestTopLevelVar('n', null,
+ relevance: DART_RELEVANCE_LOCAL_TOP_LEVEL_VARIABLE);
+ assertNotSuggested('b1');
+ assertNotSuggested('b2');
+ // Suggested by ConstructorContributor
+ assertNotSuggested('A');
+ // Suggested by ImportedReferenceContributor
+ assertNotSuggested('Object');
+ assertNotSuggested('X.c');
+ assertNotSuggested('X._d');
+ assertNotSuggested('F1');
+ assertNotSuggested('T1');
+ assertNotSuggested('_d');
+ assertNotSuggested('z');
+ assertNotSuggested('m');
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698