| OLD | NEW |
| 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_declarations; | 5 library test.search.member_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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 @reflectiveTest | 22 @reflectiveTest |
| 23 class MemberDeclarationsTest extends AbstractSearchDomainTest { | 23 class MemberDeclarationsTest extends AbstractSearchDomainTest { |
| 24 void assertHasDeclaration(ElementKind kind, String className) { | 24 void assertHasDeclaration(ElementKind kind, String className) { |
| 25 result = findTopLevelResult(kind, className); | 25 result = findTopLevelResult(kind, className); |
| 26 if (result == null) { | 26 if (result == null) { |
| 27 fail('Not found: kind=$kind in="$className"\nin\n' + results.join('\n')); | 27 fail('Not found: kind=$kind in="$className"\nin\n' + results.join('\n')); |
| 28 } | 28 } |
| 29 } | 29 } |
| 30 | 30 |
| 31 void assertNoDeclaration(ElementKind kind, String className) { | 31 Future findMemberDeclarations(String name) async { |
| 32 result = findTopLevelResult(kind, className); | 32 await waitForTasksFinished(); |
| 33 if (result != null) { | 33 Request request = |
| 34 fail('Unexpected: kind=$kind in="$className"\nin\n' + results.join('\n')); | 34 new SearchFindMemberDeclarationsParams(name).toRequest('0'); |
| 35 } | 35 Response response = await waitResponse(request); |
| 36 } | 36 var result = new SearchFindMemberDeclarationsResult.fromResponse(response); |
| 37 | 37 searchId = result.id; |
| 38 Future findMemberDeclarations(String name) { | 38 return waitForSearchResults(); |
| 39 return waitForTasksFinished().then((_) { | |
| 40 Request request = | |
| 41 new SearchFindMemberDeclarationsParams(name).toRequest('0'); | |
| 42 Response response = handleSuccessfulRequest(request); | |
| 43 var result = | |
| 44 new SearchFindMemberDeclarationsResult.fromResponse(response); | |
| 45 searchId = result.id; | |
| 46 results.clear(); | |
| 47 return waitForSearchResults(); | |
| 48 }); | |
| 49 } | 39 } |
| 50 | 40 |
| 51 SearchResult findTopLevelResult(ElementKind kind, String enclosingClass) { | 41 SearchResult findTopLevelResult(ElementKind kind, String enclosingClass) { |
| 52 for (SearchResult result in results) { | 42 for (SearchResult result in results) { |
| 53 Element element = result.path[0]; | 43 Element element = result.path[0]; |
| 54 Element clazz = result.path[1]; | 44 Element clazz = result.path[1]; |
| 55 if (element.kind == kind && clazz.name == enclosingClass) { | 45 if (element.kind == kind && clazz.name == enclosingClass) { |
| 56 return result; | 46 return result; |
| 57 } | 47 } |
| 58 } | 48 } |
| 59 return null; | 49 return null; |
| 60 } | 50 } |
| 61 | 51 |
| 62 test_localVariable() { | 52 test_localVariable() async { |
| 63 addTestFile(''' | 53 addTestFile(''' |
| 64 class A { | 54 class A { |
| 65 main() { | 55 main() { |
| 66 var foo = 42; | 56 var foo = 42; |
| 67 } | 57 } |
| 68 } | 58 } |
| 69 '''); | 59 '''); |
| 70 return findMemberDeclarations('foo').then((_) { | 60 await findMemberDeclarations('foo'); |
| 71 expect(results, isEmpty); | 61 expect(results, isEmpty); |
| 72 }); | |
| 73 } | 62 } |
| 74 | 63 |
| 75 test_localVariable_forIn() { | 64 test_localVariable_forIn() async { |
| 76 addTestFile(''' | 65 addTestFile(''' |
| 77 class A { | 66 class A { |
| 78 main() { | 67 main() { |
| 79 for (int foo in []) { | 68 for (int foo in []) { |
| 80 } | 69 } |
| 81 } | 70 } |
| 82 } | 71 } |
| 83 '''); | 72 '''); |
| 84 return findMemberDeclarations('foo').then((_) { | 73 await findMemberDeclarations('foo'); |
| 85 expect(results, isEmpty); | 74 expect(results, isEmpty); |
| 86 }); | |
| 87 } | 75 } |
| 88 | 76 |
| 89 test_methodField() { | 77 test_methodField() async { |
| 90 addTestFile(''' | 78 addTestFile(''' |
| 91 class A { | 79 class A { |
| 92 foo() {} | 80 foo() {} |
| 93 bar() {} | 81 bar() {} |
| 94 } | 82 } |
| 95 class B { | 83 class B { |
| 96 int foo; | 84 int foo; |
| 97 } | 85 } |
| 98 '''); | 86 '''); |
| 99 return findMemberDeclarations('foo').then((_) { | 87 await findMemberDeclarations('foo'); |
| 100 expect(results, hasLength(2)); | 88 expect(results, hasLength(2)); |
| 101 assertHasDeclaration(ElementKind.METHOD, 'A'); | 89 assertHasDeclaration(ElementKind.METHOD, 'A'); |
| 102 assertHasDeclaration(ElementKind.FIELD, 'B'); | 90 assertHasDeclaration(ElementKind.FIELD, 'B'); |
| 103 }); | |
| 104 } | 91 } |
| 105 | 92 |
| 106 test_methodGetter() { | 93 test_methodGetter() async { |
| 107 addTestFile(''' | 94 addTestFile(''' |
| 108 class A { | 95 class A { |
| 109 foo() {} | 96 foo() {} |
| 110 bar() {} | 97 bar() {} |
| 111 } | 98 } |
| 112 class B { | 99 class B { |
| 113 get foo => null; | 100 get foo => null; |
| 114 } | 101 } |
| 115 '''); | 102 '''); |
| 116 return findMemberDeclarations('foo').then((_) { | 103 await findMemberDeclarations('foo'); |
| 117 expect(results, hasLength(2)); | 104 expect(results, hasLength(2)); |
| 118 assertHasDeclaration(ElementKind.METHOD, 'A'); | 105 assertHasDeclaration(ElementKind.METHOD, 'A'); |
| 119 assertHasDeclaration(ElementKind.GETTER, 'B'); | 106 assertHasDeclaration(ElementKind.GETTER, 'B'); |
| 120 }); | |
| 121 } | 107 } |
| 122 | 108 |
| 123 test_methodGetterSetter() { | 109 test_methodGetterSetter() async { |
| 124 addTestFile(''' | 110 addTestFile(''' |
| 125 class A { | 111 class A { |
| 126 foo() {} | 112 foo() {} |
| 127 bar() {} | 113 bar() {} |
| 128 } | 114 } |
| 129 class B { | 115 class B { |
| 130 get foo => null; | 116 get foo => null; |
| 131 set foo(x) {} | 117 set foo(x) {} |
| 132 } | 118 } |
| 133 '''); | 119 '''); |
| 134 return findMemberDeclarations('foo').then((_) { | 120 await findMemberDeclarations('foo'); |
| 135 expect(results, hasLength(3)); | 121 expect(results, hasLength(3)); |
| 136 assertHasDeclaration(ElementKind.METHOD, 'A'); | 122 assertHasDeclaration(ElementKind.METHOD, 'A'); |
| 137 assertHasDeclaration(ElementKind.GETTER, 'B'); | 123 assertHasDeclaration(ElementKind.GETTER, 'B'); |
| 138 assertHasDeclaration(ElementKind.SETTER, 'B'); | 124 assertHasDeclaration(ElementKind.SETTER, 'B'); |
| 139 }); | |
| 140 } | 125 } |
| 141 | 126 |
| 142 test_methodMethod() { | 127 test_methodMethod() async { |
| 143 addTestFile(''' | 128 addTestFile(''' |
| 144 class A { | 129 class A { |
| 145 foo() {} | 130 foo() {} |
| 146 bar() {} | 131 bar() {} |
| 147 } | 132 } |
| 148 class B { | 133 class B { |
| 149 foo() {} | 134 foo() {} |
| 150 } | 135 } |
| 151 '''); | 136 '''); |
| 152 return findMemberDeclarations('foo').then((_) { | 137 await findMemberDeclarations('foo'); |
| 153 expect(results, hasLength(2)); | 138 expect(results, hasLength(2)); |
| 154 assertHasDeclaration(ElementKind.METHOD, 'A'); | 139 assertHasDeclaration(ElementKind.METHOD, 'A'); |
| 155 assertHasDeclaration(ElementKind.METHOD, 'B'); | 140 assertHasDeclaration(ElementKind.METHOD, 'B'); |
| 156 }); | |
| 157 } | 141 } |
| 158 | 142 |
| 159 test_methodSetter() { | 143 test_methodSetter() async { |
| 160 addTestFile(''' | 144 addTestFile(''' |
| 161 class A { | 145 class A { |
| 162 foo() {} | 146 foo() {} |
| 163 bar() {} | 147 bar() {} |
| 164 } | 148 } |
| 165 class B { | 149 class B { |
| 166 set foo(x) {} | 150 set foo(x) {} |
| 167 } | 151 } |
| 168 '''); | 152 '''); |
| 169 return findMemberDeclarations('foo').then((_) { | 153 await findMemberDeclarations('foo'); |
| 170 expect(results, hasLength(2)); | 154 expect(results, hasLength(2)); |
| 171 assertHasDeclaration(ElementKind.METHOD, 'A'); | 155 assertHasDeclaration(ElementKind.METHOD, 'A'); |
| 172 assertHasDeclaration(ElementKind.SETTER, 'B'); | 156 assertHasDeclaration(ElementKind.SETTER, 'B'); |
| 173 }); | |
| 174 } | 157 } |
| 175 } | 158 } |
| OLD | NEW |