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

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

Issue 894323003: Wait for analysis in search domain. Rewrite with async/await. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
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/src/protocol.dart'; 9 import 'package:analysis_server/src/protocol.dart';
10 import 'package:unittest/unittest.dart'; 10 import 'package:unittest/unittest.dart';
(...skipping 17 matching lines...) Expand all
28 } 28 }
29 } 29 }
30 30
31 void assertNoDeclaration(ElementKind kind, String name) { 31 void assertNoDeclaration(ElementKind kind, String name) {
32 result = findTopLevelResult(kind, name); 32 result = findTopLevelResult(kind, name);
33 if (result != null) { 33 if (result != null) {
34 fail('Unexpected: kind=$kind name="$name"\nin\n' + results.join('\n')); 34 fail('Unexpected: kind=$kind name="$name"\nin\n' + results.join('\n'));
35 } 35 }
36 } 36 }
37 37
38 Future findTopLevelDeclarations(String pattern) { 38 Future findTopLevelDeclarations(String pattern) async {
39 return waitForTasksFinished().then((_) { 39 await waitForTasksFinished();
40 Request request = 40 Request request =
41 new SearchFindTopLevelDeclarationsParams(pattern).toRequest('0'); 41 new SearchFindTopLevelDeclarationsParams(pattern).toRequest('0');
42 Response response = handleSuccessfulRequest(request); 42 Response response = await waitResponse(request);
43 searchId = 43 searchId =
44 new SearchFindTopLevelDeclarationsResult.fromResponse(response).id; 44 new SearchFindTopLevelDeclarationsResult.fromResponse(response).id;
45 results.clear(); 45 return waitForSearchResults();
46 return waitForSearchResults();
47 });
48 } 46 }
49 47
50 SearchResult findTopLevelResult(ElementKind kind, String name) { 48 SearchResult findTopLevelResult(ElementKind kind, String name) {
51 for (SearchResult result in results) { 49 for (SearchResult result in results) {
52 Element element = result.path[0]; 50 Element element = result.path[0];
53 if (element.kind == kind && element.name == name) { 51 if (element.kind == kind && element.name == name) {
54 return result; 52 return result;
55 } 53 }
56 } 54 }
57 return null; 55 return null;
58 } 56 }
59 57
60 test_startEndPattern() { 58 test_startEndPattern() async {
61 addTestFile(''' 59 addTestFile('''
62 class A {} // A 60 class A {} // A
63 class B = Object with A; 61 class B = Object with A;
64 typedef C(); 62 typedef C();
65 D() {} 63 D() {}
66 var E = null; 64 var E = null;
67 class ABC {} 65 class ABC {}
68 '''); 66 ''');
69 return findTopLevelDeclarations('^[A-E]\$').then((_) { 67 await findTopLevelDeclarations('^[A-E]\$');
70 assertHasDeclaration(ElementKind.CLASS, 'A'); 68 assertHasDeclaration(ElementKind.CLASS, 'A');
71 assertHasDeclaration(ElementKind.CLASS, 'B'); 69 assertHasDeclaration(ElementKind.CLASS, 'B');
72 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C'); 70 assertHasDeclaration(ElementKind.FUNCTION_TYPE_ALIAS, 'C');
73 assertHasDeclaration(ElementKind.FUNCTION, 'D'); 71 assertHasDeclaration(ElementKind.FUNCTION, 'D');
74 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E'); 72 assertHasDeclaration(ElementKind.TOP_LEVEL_VARIABLE, 'E');
75 assertNoDeclaration(ElementKind.CLASS, 'ABC'); 73 assertNoDeclaration(ElementKind.CLASS, 'ABC');
76 });
77 } 74 }
78 } 75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698