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

Side by Side Diff: pkg/analysis_server/test/search/top_level_declarations_test.dart

Issue 2149853002: Handle bad regexs in search.findTopLevelDeclarations. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: updates from review Created 4 years, 5 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/lib/src/search/search_domain.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.search.top_level_declarations; 5 library test.search.top_level_declarations;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; 9 import 'package:analysis_server/plugin/protocol/protocol.dart';
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; 10 import 'package:test_reflective_loader/test_reflective_loader.dart';
(...skipping 21 matching lines...) Expand all
32 if (result != null) { 32 if (result != null) {
33 fail('Unexpected: kind=$kind name="$name"\nin\n' + results.join('\n')); 33 fail('Unexpected: kind=$kind name="$name"\nin\n' + results.join('\n'));
34 } 34 }
35 } 35 }
36 36
37 Future findTopLevelDeclarations(String pattern) async { 37 Future findTopLevelDeclarations(String pattern) async {
38 await waitForTasksFinished(); 38 await waitForTasksFinished();
39 Request request = 39 Request request =
40 new SearchFindTopLevelDeclarationsParams(pattern).toRequest('0'); 40 new SearchFindTopLevelDeclarationsParams(pattern).toRequest('0');
41 Response response = await waitResponse(request); 41 Response response = await waitResponse(request);
42 if (response.error != null) {
43 return response.error;
44 }
42 searchId = 45 searchId =
43 new SearchFindTopLevelDeclarationsResult.fromResponse(response).id; 46 new SearchFindTopLevelDeclarationsResult.fromResponse(response).id;
44 return waitForSearchResults(); 47 return waitForSearchResults();
45 } 48 }
46 49
47 SearchResult findTopLevelResult(ElementKind kind, String name) { 50 SearchResult findTopLevelResult(ElementKind kind, String name) {
48 for (SearchResult result in results) { 51 for (SearchResult result in results) {
49 Element element = result.path[0]; 52 Element element = result.path[0];
50 if (element.kind == kind && element.name == name) { 53 if (element.kind == kind && element.name == name) {
51 return result; 54 return result;
52 } 55 }
53 } 56 }
54 return null; 57 return null;
55 } 58 }
56 59
57 test_startEndPattern() async { 60 test_startEndPattern() async {
58 addTestFile(''' 61 addTestFile('''
59 class A {} // A 62 class A {} // A
60 class B = Object with A; 63 class B = Object with A;
61 typedef C(); 64 typedef C();
62 D() {} 65 D() {}
63 var E = null; 66 var E = null;
64 class ABC {} 67 class ABC {}
65 '''); 68 ''');
69
66 await findTopLevelDeclarations('^[A-E]\$'); 70 await findTopLevelDeclarations('^[A-E]\$');
67 assertHasDeclaration(ElementKind.CLASS, 'A'); 71 assertHasDeclaration(ElementKind.CLASS, 'A');
68 assertHasDeclaration(ElementKind.CLASS, 'B'); 72 assertHasDeclaration(ElementKind.CLASS, 'B');
69 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C'); 73 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C');
70 assertHasDeclaration(ElementKind.FUNCTION, 'D'); 74 assertHasDeclaration(ElementKind.FUNCTION, 'D');
71 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E'); 75 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E');
72 assertNoDeclaration(ElementKind.CLASS, 'ABC'); 76 assertNoDeclaration(ElementKind.CLASS, 'ABC');
73 } 77 }
78
79 test_invalidRegex() async {
80 var result = await findTopLevelDeclarations('[A');
81 expect(result, new isInstanceOf<RequestError>());
82 }
74 } 83 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/search/search_domain.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698