Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/element/element.dart'; | 8 import 'package:analyzer/dart/element/element.dart'; |
| 9 import 'package:analyzer/src/dart/analysis/driver.dart'; | 9 import 'package:analyzer/src/dart/analysis/driver.dart'; |
| 10 import 'package:analyzer/src/dart/analysis/search.dart'; | 10 import 'package:analyzer/src/dart/analysis/search.dart'; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 '''); | 134 '''); |
| 135 CompilationUnitElement element = _findElementAtString('my_part'); | 135 CompilationUnitElement element = _findElementAtString('my_part'); |
| 136 var expected = [ | 136 var expected = [ |
| 137 _expectIdQ(element.library.definingCompilationUnit, | 137 _expectIdQ(element.library.definingCompilationUnit, |
| 138 SearchResultKind.REFERENCE, "'my_part.dart'", | 138 SearchResultKind.REFERENCE, "'my_part.dart'", |
| 139 length: "'my_part.dart'".length) | 139 length: "'my_part.dart'".length) |
| 140 ]; | 140 ]; |
| 141 await _verifyReferences(element, expected); | 141 await _verifyReferences(element, expected); |
| 142 } | 142 } |
| 143 | 143 |
| 144 test_searchReferences_ConstructorElement() async { | 144 test_searchReferences_ConstructorElement_default() async { |
| 145 await _resolveTestUnit(''' | |
| 146 class A { | |
| 147 A() {} | |
| 148 } | |
| 149 main() { | |
| 150 new A(); | |
| 151 } | |
| 152 '''); | |
| 153 ConstructorElement element = _findElementAtString('A() {}'); | |
| 154 Element mainElement = _findElement('main'); | |
| 155 var expected = [ | |
| 156 _expectIdQ(mainElement, SearchResultKind.REFERENCE, '();', length: 0) | |
| 157 ]; | |
| 158 await _verifyReferences(element, expected); | |
| 159 } | |
| 160 | |
| 161 test_searchReferences_ConstructorElement_default_otherFile() async { | |
| 162 String other = _p('$testProject/other.dart'); | |
|
Paul Berry
2016/12/01 13:18:03
This test fails on Windows. See https://build.chr
| |
| 163 String otherCode = ''' | |
| 164 import 'test.dart'; | |
| 165 main() { | |
| 166 new A(); // in other | |
| 167 } | |
| 168 '''; | |
| 169 provider.newFile(other, otherCode); | |
| 170 driver.addFile(other); | |
| 171 | |
| 172 await _resolveTestUnit(''' | |
| 173 class A { | |
| 174 A() {} | |
| 175 } | |
| 176 '''); | |
| 177 ConstructorElement element = _findElementAtString('A() {}'); | |
| 178 | |
| 179 CompilationUnit otherUnit = (await driver.getResult(other)).unit; | |
| 180 Element main = otherUnit.element.functions[0]; | |
| 181 var expected = [ | |
| 182 new ExpectedResult(main, SearchResultKind.REFERENCE, | |
| 183 otherCode.indexOf('(); // in other'), 0, | |
| 184 isResolved: true, isQualified: true) | |
| 185 ]; | |
| 186 await _verifyReferences(element, expected); | |
| 187 } | |
| 188 | |
| 189 test_searchReferences_ConstructorElement_named() async { | |
| 145 await _resolveTestUnit(''' | 190 await _resolveTestUnit(''' |
| 146 class A { | 191 class A { |
| 147 A.named() {} | 192 A.named() {} |
| 148 } | 193 } |
| 149 main() { | 194 main() { |
| 150 new A.named(); | 195 new A.named(); |
| 151 } | 196 } |
| 152 '''); | 197 '''); |
| 153 ConstructorElement element = _findElement('named'); | 198 ConstructorElement element = _findElement('named'); |
| 154 Element mainElement = _findElement('main'); | 199 Element mainElement = _findElement('main'); |
| 155 var expected = [ | 200 var expected = [ |
| 156 _expectIdQ(mainElement, SearchResultKind.REFERENCE, '.named();', | 201 _expectIdQ(mainElement, SearchResultKind.REFERENCE, '.named();', |
| 157 length: 6) | 202 length: '.named'.length) |
| 158 ]; | 203 ]; |
| 159 await _verifyReferences(element, expected); | 204 await _verifyReferences(element, expected); |
| 160 } | 205 } |
| 161 | 206 |
| 162 test_searchReferences_ConstructorElement_synthetic() async { | 207 test_searchReferences_ConstructorElement_synthetic() async { |
| 163 await _resolveTestUnit(''' | 208 await _resolveTestUnit(''' |
| 164 class A { | 209 class A { |
| 165 } | 210 } |
| 166 main() { | 211 main() { |
| 167 new A(); | 212 new A(); |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 List<SearchResult> results = await driver.search.references(element); | 851 List<SearchResult> results = await driver.search.references(element); |
| 807 _assertResults(results, expectedMatches); | 852 _assertResults(results, expectedMatches); |
| 808 expect(results, hasLength(expectedMatches.length)); | 853 expect(results, hasLength(expectedMatches.length)); |
| 809 } | 854 } |
| 810 | 855 |
| 811 static void _assertResults( | 856 static void _assertResults( |
| 812 List<SearchResult> matches, List<ExpectedResult> expectedMatches) { | 857 List<SearchResult> matches, List<ExpectedResult> expectedMatches) { |
| 813 expect(matches, unorderedEquals(expectedMatches)); | 858 expect(matches, unorderedEquals(expectedMatches)); |
| 814 } | 859 } |
| 815 } | 860 } |
| OLD | NEW |