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

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: 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
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 823 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 } 834 }
835 835
836 test_import_deferred_as4() { 836 test_import_deferred_as4() {
837 addTestSource('import "foo" d^'); 837 addTestSource('import "foo" d^');
838 expect(computeFast(), isTrue); 838 expect(computeFast(), isTrue);
839 assertSuggestKeywords([Keyword.AS], 839 assertSuggestKeywords([Keyword.AS],
840 pseudoKeywords: ['deferred as', 'show', 'hide'], 840 pseudoKeywords: ['deferred as', 'show', 'hide'],
841 relevance: DART_RELEVANCE_HIGH); 841 relevance: DART_RELEVANCE_HIGH);
842 } 842 }
843 843
844 test_import_deferred_as5() {
845 addTestSource('import "foo" sh^ import "bar"; import "baz";');
846 expect(computeFast(), isTrue);
847 assertSuggestKeywords([Keyword.AS],
848 pseudoKeywords: ['deferred as', 'show', 'hide'],
849 relevance: DART_RELEVANCE_HIGH);
850 }
851
844 test_import_deferred_not() { 852 test_import_deferred_not() {
845 addTestSource('import "foo" as foo ^;'); 853 addTestSource('import "foo" as foo ^;');
846 expect(computeFast(), isTrue); 854 expect(computeFast(), isTrue);
847 assertSuggestKeywords([], 855 assertSuggestKeywords([],
848 pseudoKeywords: ['show', 'hide'], relevance: DART_RELEVANCE_HIGH); 856 pseudoKeywords: ['show', 'hide'], relevance: DART_RELEVANCE_HIGH);
849 } 857 }
850 858
859 test_import_deferred_partial() {
860 addTestSource('import "package:foo/foo.dart" def^ as foo;');
861 expect(computeFast(), isTrue);
862 assertSuggestKeywords([Keyword.DEFERRED], relevance: DART_RELEVANCE_HIGH);
863 expect(request.replacementOffset, 30);
864 expect(request.replacementLength, 3);
865 }
866
851 test_import_incomplete() { 867 test_import_incomplete() {
852 addTestSource('import "^"'); 868 addTestSource('import "^"');
853 expect(computeFast(), isTrue); 869 expect(computeFast(), isTrue);
854 assertNoSuggestions(); 870 assertNoSuggestions();
855 assertSuggestKeywords([]); 871 assertSuggestKeywords([]);
Brian Wilkerson 2015/08/12 13:59:25 I would have expected that 'assertNoSuggestions()'
danrubel 2015/08/15 19:17:16 Yup. That 2nd line is unnecessary. Removed.
856 } 872 }
857 873
874 test_import_partial() {
875 addTestSource('imp^ import "package:foo/foo.dart"; import "bar.dart";');
876 expect(computeFast(), isTrue);
877 // TODO(danrubel) should not suggest declaration keywords
Brian Wilkerson 2015/08/12 13:59:25 I'd rather see a test that is correct that is mark
danrubel 2015/08/15 19:17:17 Fair enough. Added.
878 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
879 relevance: DART_RELEVANCE_HIGH);
880 expect(request.replacementOffset, 0);
881 expect(request.replacementLength, 3);
882 }
883
884 test_import_partial2() {
885 addTestSource('^imp import "package:foo/foo.dart";');
886 expect(computeFast(), isTrue);
887 // TODO(danrubel) should not suggest declaration keywords
888 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
889 relevance: DART_RELEVANCE_HIGH);
890 expect(request.replacementOffset, 0);
891 expect(request.replacementLength, 3);
892 }
893
894 test_import_partial3() {
895 addTestSource(' ^imp import "package:foo/foo.dart"; import "bar.dart";');
896 expect(computeFast(), isTrue);
897 // TODO(danrubel) should not suggest declaration keywords
898 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
899 relevance: DART_RELEVANCE_HIGH);
900 expect(request.replacementOffset, 1);
901 expect(request.replacementLength, 3);
902 }
903
904 test_import_partial4() {
905 addTestSource('^ imp import "package:foo/foo.dart";');
906 expect(computeFast(), isTrue);
907 // TODO(danrubel) should not suggest declaration keywords
908 assertSuggestKeywords(DIRECTIVE_DECLARATION_AND_LIBRARY_KEYWORDS,
909 relevance: DART_RELEVANCE_HIGH);
910 expect(request.replacementOffset, 0);
911 expect(request.replacementLength, 0);
912 }
913
914 test_import_partial5() {
915 addTestSource('library libA; imp^ import "package:foo/foo.dart";');
916 expect(computeFast(), isTrue);
917 // TODO(danrubel) should not suggest declaration keywords
918 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
919 relevance: DART_RELEVANCE_HIGH);
920 expect(request.replacementOffset, 14);
921 expect(request.replacementLength, 3);
922 }
923
924 test_import_partial6() {
925 addTestSource(
926 'library bar; import "zoo.dart"; imp^ import "package:foo/foo.dart";');
927 expect(computeFast(), isTrue);
928 // TODO(danrubel) should not suggest declaration keywords
929 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
930 relevance: DART_RELEVANCE_HIGH);
931 expect(request.replacementOffset, 32);
932 expect(request.replacementLength, 3);
933 }
934
858 test_library() { 935 test_library() {
859 addTestSource('library foo;^'); 936 addTestSource('library foo;^');
860 expect(computeFast(), isTrue); 937 expect(computeFast(), isTrue);
861 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS, 938 assertSuggestKeywords(DIRECTIVE_AND_DECLARATION_KEYWORDS,
862 relevance: DART_RELEVANCE_HIGH); 939 relevance: DART_RELEVANCE_HIGH);
863 } 940 }
864 941
865 test_library_declaration() { 942 test_library_declaration() {
866 addTestSource('library ^'); 943 addTestSource('library ^');
867 expect(computeFast(), isTrue); 944 expect(computeFast(), isTrue);
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}')); 1271 (c) => msg.writeln(' $c, ${other.contains(c) ? '' : '<<<<<<<<<<<'}'));
1195 } 1272 }
1196 1273
1197 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) { 1274 bool _equalSets(Iterable<String> iter1, Iterable<String> iter2) {
1198 if (iter1.length != iter2.length) return false; 1275 if (iter1.length != iter2.length) return false;
1199 if (iter1.any((c) => !iter2.contains(c))) return false; 1276 if (iter1.any((c) => !iter2.contains(c))) return false;
1200 if (iter2.any((c) => !iter1.contains(c))) return false; 1277 if (iter2.any((c) => !iter1.contains(c))) return false;
1201 return true; 1278 return true;
1202 } 1279 }
1203 } 1280 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698