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

Side by Side Diff: pkg/analysis_server/test/services/completion/keyword_contributor_test.dart

Issue 1278033006: tests for keyword/identifier replacementOffset - asserts fixes #23906 and fixes #23947 (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: address comments Created 5 years, 4 months 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 unified diff | Download patch
« no previous file with comments | « pkg/analysis_server/test/domain_completion_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.dart.keyword; 5 library test.services.completion.dart.keyword;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart'; 8 import 'package:analysis_server/src/services/completion/dart_completion_manager. dart';
9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart '; 9 import 'package:analysis_server/src/services/completion/keyword_contributor.dart ';
10 import 'package:analyzer/src/generated/scanner.dart'; 10 import 'package:analyzer/src/generated/scanner.dart';
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 expectedOffset = s.completion.length; 222 expectedOffset = s.completion.length;
223 } 223 }
224 expect(s.selectionOffset, equals(expectedOffset)); 224 expect(s.selectionOffset, equals(expectedOffset));
225 expect(s.selectionLength, equals(0)); 225 expect(s.selectionLength, equals(0));
226 expect(s.isDeprecated, equals(false)); 226 expect(s.isDeprecated, equals(false));
227 expect(s.isPotential, equals(false)); 227 expect(s.isPotential, equals(false));
228 } 228 }
229 } 229 }
230 } 230 }
231 231
232 fail_import_partial() {
233 addTestSource('imp^ import "package:foo/foo.dart"; import "bar.dart";');
234 expect(computeFast(), isTrue);
235 // TODO(danrubel) should not suggest declaration keywords
236 assertNotSuggested('class');
237 }
238
239 fail_import_partial4() {
240 addTestSource('^ imp import "package:foo/foo.dart";');
241 expect(computeFast(), isTrue);
242 // TODO(danrubel) should not suggest declaration keywords
243 assertNotSuggested('class');
244 }
245
246 fail_import_partial5() {
247 addTestSource('library libA; imp^ import "package:foo/foo.dart";');
248 expect(computeFast(), isTrue);
249 // TODO(danrubel) should not suggest declaration keywords
250 assertNotSuggested('class');
251 }
252
253 fail_import_partial6() {
254 addTestSource(
255 'library bar; import "zoo.dart"; imp^ import "package:foo/foo.dart";');
256 expect(computeFast(), isTrue);
257 // TODO(danrubel) should not suggest declaration keywords
258 assertNotSuggested('class');
259 }
260
232 @override 261 @override
233 void setUpContributor() { 262 void setUpContributor() {
234 contributor = new KeywordContributor(); 263 contributor = new KeywordContributor();
235 } 264 }
236 265
237 test_after_class() { 266 test_after_class() {
238 addTestSource('class A {} ^'); 267 addTestSource('class A {} ^');
239 expect(computeFast(), isTrue); 268 expect(computeFast(), isTrue);
240 assertSuggestKeywords(DECLARATION_KEYWORDS, relevance: DART_RELEVANCE_HIGH); 269 assertSuggestKeywords(DECLARATION_KEYWORDS, relevance: DART_RELEVANCE_HIGH);
241 } 270 }
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 } 863 }
835 864
836 test_import_deferred_as4() { 865 test_import_deferred_as4() {
837 addTestSource('import "foo" d^'); 866 addTestSource('import "foo" d^');
838 expect(computeFast(), isTrue); 867 expect(computeFast(), isTrue);
839 assertSuggestKeywords([Keyword.AS], 868 assertSuggestKeywords([Keyword.AS],
840 pseudoKeywords: ['deferred as', 'show', 'hide'], 869 pseudoKeywords: ['deferred as', 'show', 'hide'],
841 relevance: DART_RELEVANCE_HIGH); 870 relevance: DART_RELEVANCE_HIGH);
842 } 871 }
843 872
873 test_import_deferred_as5() {
874 addTestSource('import "foo" sh^ import "bar"; import "baz";');
875 expect(computeFast(), isTrue);
876 assertSuggestKeywords([Keyword.AS],
877 pseudoKeywords: ['deferred as', 'show', 'hide'],
878 relevance: DART_RELEVANCE_HIGH);
879 }
880
844 test_import_deferred_not() { 881 test_import_deferred_not() {
845 addTestSource('import "foo" as foo ^;'); 882 addTestSource('import "foo" as foo ^;');
846 expect(computeFast(), isTrue); 883 expect(computeFast(), isTrue);
847 assertSuggestKeywords([], 884 assertSuggestKeywords([],
848 pseudoKeywords: ['show', 'hide'], relevance: DART_RELEVANCE_HIGH); 885 pseudoKeywords: ['show', 'hide'], relevance: DART_RELEVANCE_HIGH);
849 } 886 }
850 887
888 test_import_deferred_partial() {
889 addTestSource('import "package:foo/foo.dart" def^ as foo;');
890 expect(computeFast(), isTrue);
891 assertSuggestKeywords([Keyword.DEFERRED], relevance: DART_RELEVANCE_HIGH);
892 expect(request.replacementOffset, 30);
893 expect(request.replacementLength, 3);
894 }
895
851 test_import_incomplete() { 896 test_import_incomplete() {
852 addTestSource('import "^"'); 897 addTestSource('import "^"');
853 expect(computeFast(), isTrue); 898 expect(computeFast(), isTrue);
854 assertNoSuggestions(); 899 assertNoSuggestions();
855 assertSuggestKeywords([]); 900 }
901
902 test_import_partial() {
903 addTestSource('imp^ import "package:foo/foo.dart"; import "bar.dart";');
904 expect(computeFast(), isTrue);
905 // TODO(danrubel) should not suggest declaration keywords
906 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
907 relevance: DART_RELEVANCE_HIGH);
908 expect(request.replacementOffset, 0);
909 expect(request.replacementLength, 3);
910 }
911
912 test_import_partial2() {
913 addTestSource('^imp import "package:foo/foo.dart";');
914 expect(computeFast(), isTrue);
915 // TODO(danrubel) should not suggest declaration keywords
916 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
917 relevance: DART_RELEVANCE_HIGH);
918 expect(request.replacementOffset, 0);
919 expect(request.replacementLength, 3);
920 }
921
922 test_import_partial3() {
923 addTestSource(' ^imp import "package:foo/foo.dart"; import "bar.dart";');
924 expect(computeFast(), isTrue);
925 // TODO(danrubel) should not suggest declaration keywords
926 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
927 relevance: DART_RELEVANCE_HIGH);
928 expect(request.replacementOffset, 1);
929 expect(request.replacementLength, 3);
930 }
931
932 test_import_partial4() {
933 addTestSource('^ imp import "package:foo/foo.dart";');
934 expect(computeFast(), isTrue);
935 // TODO(danrubel) should not suggest declaration keywords
936 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
937 relevance: DART_RELEVANCE_HIGH);
938 expect(request.replacementOffset, 0);
939 expect(request.replacementLength, 0);
940 }
941
942 test_import_partial5() {
943 addTestSource('library libA; imp^ import "package:foo/foo.dart";');
944 expect(computeFast(), isTrue);
945 // TODO(danrubel) should not suggest declaration keywords
946 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
947 relevance: DART_RELEVANCE_HIGH);
948 expect(request.replacementOffset, 14);
949 expect(request.replacementLength, 3);
950 }
951
952 test_import_partial6() {
953 addTestSource(
954 'library bar; import "zoo.dart"; imp^ import "package:foo/foo.dart";');
955 expect(computeFast(), isTrue);
956 // TODO(danrubel) should not suggest declaration keywords
957 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
958 relevance: DART_RELEVANCE_HIGH);
959 expect(request.replacementOffset, 32);
960 expect(request.replacementLength, 3);
856 } 961 }
857 962
858 test_library() { 963 test_library() {
859 addTestSource('library foo;^'); 964 addTestSource('library foo;^');
860 expect(computeFast(), isTrue); 965 expect(computeFast(), isTrue);
861 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS, 966 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
862 relevance: DART_RELEVANCE_HIGH); 967 relevance: DART_RELEVANCE_HIGH);
863 } 968 }
864 969
865 test_library_declaration() { 970 test_library_declaration() {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}')); 1299 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}'));
1195 } 1300 }
1196 1301
1197 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) { 1302 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) {
1198 if (iter1.length != iter2.length) return false; 1303 if (iter1.length != iter2.length) return false;
1199 if (iter1.any((c) => !iter2.contains(c))) return false; 1304 if (iter1.any((c) => !iter2.contains(c))) return false;
1200 if (iter2.any((c) => !iter1.contains(c))) return false; 1305 if (iter2.any((c) => !iter1.contains(c))) return false;
1201 return true; 1306 return true;
1202 } 1307 }
1203 } 1308 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/domain_completion_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698