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

Side by Side Diff: pkg/analysis_server/test/search/member_references_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.member_references; 5 library test.search.member_references;
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';
11 11
12 import '../reflective_tests.dart'; 12 import '../reflective_tests.dart';
13 import 'abstract_search_domain.dart'; 13 import 'abstract_search_domain.dart';
14 14
15 15
16 main() { 16 main() {
17 groupSep = ' | '; 17 groupSep = ' | ';
18 runReflectiveTests(MemberReferencesTest); 18 runReflectiveTests(MemberReferencesTest);
19 } 19 }
20 20
21 21
22 @reflectiveTest 22 @reflectiveTest
23 class MemberReferencesTest extends AbstractSearchDomainTest { 23 class MemberReferencesTest extends AbstractSearchDomainTest {
24 void assertHasRef(SearchResultKind kind, String search, bool isPotential) { 24 void assertHasRef(SearchResultKind kind, String search, bool isPotential) {
25 assertHasResult(kind, search); 25 assertHasResult(kind, search);
26 expect(result.isPotential, isPotential); 26 expect(result.isPotential, isPotential);
27 } 27 }
28 28
29 Future findMemberReferences(String name) { 29 Future findMemberReferences(String name) async {
30 return waitForTasksFinished().then((_) { 30 await waitForTasksFinished();
31 Request request = 31 Request request = new SearchFindMemberReferencesParams(name).toRequest('0');
32 new SearchFindMemberReferencesParams(name).toRequest('0'); 32 Response response = await waitResponse(request);
33 Response response = handleSuccessfulRequest(request); 33 searchId = new SearchFindMemberReferencesResult.fromResponse(response).id;
34 searchId = new SearchFindMemberReferencesResult.fromResponse(response).id; 34 return waitForSearchResults();
35 results.clear();
36 return waitForSearchResults();
37 });
38 } 35 }
39 36
40 test_fields_explicit() { 37 test_fields_explicit() async {
41 addTestFile(''' 38 addTestFile('''
42 class A { 39 class A {
43 var foo; 40 var foo;
44 } 41 }
45 class B { 42 class B {
46 var foo; 43 var foo;
47 } 44 }
48 mainResolved(A a, B b) { 45 mainResolved(A a, B b) {
49 a.foo = 1; 46 a.foo = 1;
50 b.foo = 2; 47 b.foo = 2;
51 print(a.foo); // resolved A 48 print(a.foo); // resolved A
52 print(b.foo); // resolved B 49 print(b.foo); // resolved B
53 } 50 }
54 mainUnresolved(a, b) { 51 mainUnresolved(a, b) {
55 a.foo = 10; 52 a.foo = 10;
56 b.foo = 20; 53 b.foo = 20;
57 print(a.foo); // unresolved A 54 print(a.foo); // unresolved A
58 print(b.foo); // unresolved B 55 print(b.foo); // unresolved B
59 } 56 }
60 '''); 57 ''');
61 return findMemberReferences('foo').then((_) { 58 await findMemberReferences('foo');
62 assertHasRef(SearchResultKind.WRITE, 'foo = 1;', false); 59 assertHasRef(SearchResultKind.WRITE, 'foo = 1;', false);
63 assertHasRef(SearchResultKind.WRITE, 'foo = 2;', false); 60 assertHasRef(SearchResultKind.WRITE, 'foo = 2;', false);
64 assertHasRef(SearchResultKind.READ, 'foo); // resolved A', false); 61 assertHasRef(SearchResultKind.READ, 'foo); // resolved A', false);
65 assertHasRef(SearchResultKind.READ, 'foo); // resolved B', false); 62 assertHasRef(SearchResultKind.READ, 'foo); // resolved B', false);
66 assertHasRef(SearchResultKind.WRITE, 'foo = 10;', true); 63 assertHasRef(SearchResultKind.WRITE, 'foo = 10;', true);
67 assertHasRef(SearchResultKind.WRITE, 'foo = 20;', true); 64 assertHasRef(SearchResultKind.WRITE, 'foo = 20;', true);
68 assertHasRef(SearchResultKind.READ, 'foo); // unresolved A', true); 65 assertHasRef(SearchResultKind.READ, 'foo); // unresolved A', true);
69 assertHasRef(SearchResultKind.READ, 'foo); // unresolved B', true); 66 assertHasRef(SearchResultKind.READ, 'foo); // unresolved B', true);
70 });
71 } 67 }
72 68
73 test_fields_implicit() { 69 test_fields_implicit() async {
74 addTestFile(''' 70 addTestFile('''
75 class A { 71 class A {
76 get foo => null; 72 get foo => null;
77 } 73 }
78 class B { 74 class B {
79 get foo => null; 75 get foo => null;
80 } 76 }
81 mainResolved(A a, B b) { 77 mainResolved(A a, B b) {
82 print(a.foo); // resolved A 78 print(a.foo); // resolved A
83 print(b.foo); // resolved B 79 print(b.foo); // resolved B
84 } 80 }
85 mainUnresolved(a, b) { 81 mainUnresolved(a, b) {
86 print(a.foo); // unresolved A 82 print(a.foo); // unresolved A
87 print(b.foo); // unresolved B 83 print(b.foo); // unresolved B
88 } 84 }
89 '''); 85 ''');
90 return findMemberReferences('foo').then((_) { 86 await findMemberReferences('foo');
91 assertHasRef(SearchResultKind.READ, 'foo); // resolved A', false); 87 assertHasRef(SearchResultKind.READ, 'foo); // resolved A', false);
92 assertHasRef(SearchResultKind.READ, 'foo); // resolved B', false); 88 assertHasRef(SearchResultKind.READ, 'foo); // resolved B', false);
93 assertHasRef(SearchResultKind.READ, 'foo); // unresolved A', true); 89 assertHasRef(SearchResultKind.READ, 'foo); // unresolved A', true);
94 assertHasRef(SearchResultKind.READ, 'foo); // unresolved B', true); 90 assertHasRef(SearchResultKind.READ, 'foo); // unresolved B', true);
95 });
96 } 91 }
97 92
98 test_methods() { 93 test_methods() async {
99 addTestFile(''' 94 addTestFile('''
100 class A { 95 class A {
101 foo() {} 96 foo() {}
102 } 97 }
103 class B { 98 class B {
104 foo() {} 99 foo() {}
105 } 100 }
106 mainResolved(A a, B b) { 101 mainResolved(A a, B b) {
107 a.foo(1); 102 a.foo(1);
108 b.foo(2); 103 b.foo(2);
109 } 104 }
110 mainUnresolved(a, b) { 105 mainUnresolved(a, b) {
111 a.foo(10); 106 a.foo(10);
112 b.foo(20); 107 b.foo(20);
113 } 108 }
114 '''); 109 ''');
115 return findMemberReferences('foo').then((_) { 110 await findMemberReferences('foo');
116 assertHasRef(SearchResultKind.INVOCATION, 'foo(1)', false); 111 assertHasRef(SearchResultKind.INVOCATION, 'foo(1)', false);
117 assertHasRef(SearchResultKind.INVOCATION, 'foo(2)', false); 112 assertHasRef(SearchResultKind.INVOCATION, 'foo(2)', false);
118 assertHasRef(SearchResultKind.INVOCATION, 'foo(10)', true); 113 assertHasRef(SearchResultKind.INVOCATION, 'foo(10)', true);
119 assertHasRef(SearchResultKind.INVOCATION, 'foo(20)', true); 114 assertHasRef(SearchResultKind.INVOCATION, 'foo(20)', true);
120 });
121 } 115 }
122 } 116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698