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

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

Issue 396883002: Implementation for the 'search.findMemberReferences' API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.search.member_references;
6
7 import 'package:analysis_server/src/constants.dart';
8 import 'package:analysis_server/src/protocol.dart';
9 import 'package:analysis_server/src/search/search_result.dart';
10 import 'package:analysis_testing/reflective_tests.dart';
11 import 'package:unittest/unittest.dart';
12
13 import 'abstract_search_domain.dart';
14 import 'dart:async';
15 import 'package:analysis_server/src/computer/element.dart';
16
17
18 main() {
19 groupSep = ' | ';
20 group('MemberReferencesTest', () {
21 runReflectiveTests(MemberReferencesTest);
22 });
23 }
24
25
26 @ReflectiveTestCase()
27 class MemberReferencesTest extends AbstractSearchDomainTest {
28 Future findMemberReferences(String name) {
29 return waitForTasksFinished().then((_) {
30 Request request = new Request('0', SEARCH_FIND_MEMBER_REFERENCES);
31 request.setParameter(NAME, name);
32 Response response = handleSuccessfulRequest(request);
33 searchId = response.getResult(ID);
34 results.clear();
35 return waitForSearchResults();
36 });
37 }
38
39 void assertHasRef(SearchResultKind kind, String search, bool isPotential) {
40 assertHasResult(kind, search);
41 expect(result.isPotential, isPotential);
42 }
43
44 test_methods() {
45 addTestFile('''
46 class A {
47 foo() {}
48 }
49 class B {
50 foo() {}
51 }
52 mainResolved(A a, B b) {
53 a.foo(1);
54 b.foo(2);
55 }
56 mainUnresolved(a, b) {
57 a.foo(10);
58 b.foo(20);
59 }
60 ''');
61 return findMemberReferences('foo').then((_) {
62 assertHasRef(SearchResultKind.INVOCATION, 'foo(1)', false);
63 assertHasRef(SearchResultKind.INVOCATION, 'foo(2)', false);
64 assertHasRef(SearchResultKind.INVOCATION, 'foo(10)', true);
65 assertHasRef(SearchResultKind.INVOCATION, 'foo(20)', true);
66 });
67 }
68
69 test_fields_explicit() {
70 addTestFile('''
71 class A {
72 var foo;
73 }
74 class B {
75 var foo;
76 }
77 mainResolved(A a, B b) {
78 a.foo = 1;
79 b.foo = 2;
80 print(a.foo); // resolved A
81 print(b.foo); // resolved B
82 }
83 mainUnresolved(a, b) {
84 a.foo = 10;
85 b.foo = 20;
86 print(a.foo); // unresolved A
87 print(b.foo); // unresolved B
88 }
89 ''');
90 return findMemberReferences('foo').then((_) {
91 assertHasRef(SearchResultKind.WRITE, 'foo = 1;', false);
Brian Wilkerson 2014/07/16 13:52:37 It would be good to add an example of READ_WRITE.
92 assertHasRef(SearchResultKind.WRITE, 'foo = 2;', false);
93 assertHasRef(SearchResultKind.READ, 'foo); // resolved A', false);
94 assertHasRef(SearchResultKind.READ, 'foo); // resolved B', false);
95 assertHasRef(SearchResultKind.WRITE, 'foo = 10;', true);
96 assertHasRef(SearchResultKind.WRITE, 'foo = 20;', true);
97 assertHasRef(SearchResultKind.READ, 'foo); // unresolved A', true);
98 assertHasRef(SearchResultKind.READ, 'foo); // unresolved B', true);
99 });
100 }
101
102 test_fields_implicit() {
103 addTestFile('''
104 class A {
105 get foo => null;
106 }
107 class B {
108 get foo => null;
109 }
110 mainResolved(A a, B b) {
111 print(a.foo); // resolved A
112 print(b.foo); // resolved B
113 }
114 mainUnresolved(a, b) {
115 print(a.foo); // unresolved A
116 print(b.foo); // unresolved B
117 }
118 ''');
119 return findMemberReferences('foo').then((_) {
120 assertHasRef(SearchResultKind.READ, 'foo); // resolved A', false);
121 assertHasRef(SearchResultKind.READ, 'foo); // resolved B', false);
122 assertHasRef(SearchResultKind.READ, 'foo); // unresolved A', true);
123 assertHasRef(SearchResultKind.READ, 'foo); // unresolved B', true);
124 });
125 }
126 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/search/top_level_declarations.dart ('k') | pkg/analysis_server/test/search/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698