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.analysis.get_navigation; | 5 library test.analysis.get_navigation; |
6 | 6 |
7 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
8 import 'package:analysis_server/src/domain_analysis.dart'; | 8 import 'package:analysis_server/src/domain_analysis.dart'; |
9 import 'package:analyzer/file_system/file_system.dart'; | 9 import 'package:analyzer/file_system/file_system.dart'; |
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 addFile( | 51 addFile( |
52 file, | 52 file, |
53 ''' | 53 ''' |
54 main() { | 54 main() { |
55 print(42); | 55 print(42); |
56 } | 56 } |
57 '''); | 57 '''); |
58 return _checkInvalid(file, -1, -1); | 58 return _checkInvalid(file, -1, -1); |
59 } | 59 } |
60 | 60 |
61 test_issue24599_importDirective() async { | 61 test_importDirective() async { |
62 addTestFile(''' | 62 addTestFile(''' |
63 import 'dart:math'; | 63 import 'dart:math'; |
64 | 64 |
65 main() { | 65 main() { |
66 }'''); | 66 }'''); |
67 await waitForTasksFinished(); | 67 await waitForTasksFinished(); |
68 await _getNavigation(testFile, 0, 17); | 68 await _getNavigation(testFile, 0, 17); |
69 expect(regions, hasLength(1)); | 69 expect(regions, hasLength(1)); |
70 assertHasRegionString("'dart:math'"); | 70 assertHasRegionString("'dart:math'"); |
71 expect(testTargets, hasLength(1)); | 71 expect(testTargets, hasLength(1)); |
72 expect(testTargets[0].kind, ElementKind.LIBRARY); | 72 expect(testTargets[0].kind, ElementKind.LIBRARY); |
73 } | 73 } |
74 | 74 |
75 test_issue24599_importKeyword() async { | 75 test_importKeyword() async { |
76 addTestFile(''' | 76 addTestFile(''' |
77 import 'dart:math'; | 77 import 'dart:math'; |
78 | 78 |
79 main() { | 79 main() { |
80 }'''); | 80 }'''); |
81 await waitForTasksFinished(); | 81 await waitForTasksFinished(); |
82 await _getNavigation(testFile, 0, 1); | 82 await _getNavigation(testFile, 0, 1); |
83 expect(regions, hasLength(1)); | 83 expect(regions, hasLength(1)); |
84 assertHasRegionString("'dart:math'"); | 84 assertHasRegionString("'dart:math'"); |
85 expect(testTargets, hasLength(1)); | 85 expect(testTargets, hasLength(1)); |
86 expect(testTargets[0].kind, ElementKind.LIBRARY); | 86 expect(testTargets[0].kind, ElementKind.LIBRARY); |
87 } | 87 } |
88 | 88 |
89 test_issue24599_importUri() async { | 89 test_importUri() async { |
90 addTestFile(''' | 90 addTestFile(''' |
91 import 'dart:math'; | 91 import 'dart:math'; |
92 | 92 |
93 main() { | 93 main() { |
94 }'''); | 94 }'''); |
95 await waitForTasksFinished(); | 95 await waitForTasksFinished(); |
96 await _getNavigation(testFile, 7, 11); | 96 await _getNavigation(testFile, 7, 11); |
97 expect(regions, hasLength(1)); | 97 expect(regions, hasLength(1)); |
98 assertHasRegionString("'dart:math'"); | 98 assertHasRegionString("'dart:math'"); |
99 expect(testTargets, hasLength(1)); | 99 expect(testTargets, hasLength(1)); |
(...skipping 23 matching lines...) Expand all Loading... |
123 assertHasRegion('bbb +'); | 123 assertHasRegion('bbb +'); |
124 assertHasTarget('bbb = 2'); | 124 assertHasTarget('bbb = 2'); |
125 } | 125 } |
126 { | 126 { |
127 assertHasRegion('ccc +'); | 127 assertHasRegion('ccc +'); |
128 assertHasTarget('ccc = 3'); | 128 assertHasTarget('ccc = 3'); |
129 } | 129 } |
130 assertNoRegionAt('ddd)'); | 130 assertNoRegionAt('ddd)'); |
131 } | 131 } |
132 | 132 |
| 133 test_operator_index() async { |
| 134 addTestFile(''' |
| 135 class A { |
| 136 A operator [](index) => null; |
| 137 operator []=(index, A value) {} |
| 138 } |
| 139 main() { |
| 140 var a = new A(); |
| 141 a[0] // []; |
| 142 a[1] = 1; // []=; |
| 143 a[2] += 2; |
| 144 } |
| 145 '''); |
| 146 await waitForTasksFinished(); |
| 147 { |
| 148 String search = '[0'; |
| 149 await _getNavigation(testFile, testCode.indexOf(search), 1); |
| 150 assertHasOperatorRegion(search, 1, '[](index)', 2); |
| 151 } |
| 152 { |
| 153 String search = '] // []'; |
| 154 await _getNavigation(testFile, testCode.indexOf(search), 1); |
| 155 assertHasOperatorRegion(search, 1, '[](index)', 2); |
| 156 } |
| 157 { |
| 158 String search = '[1'; |
| 159 await _getNavigation(testFile, testCode.indexOf(search), 1); |
| 160 assertHasOperatorRegion(search, 1, '[]=(index', 3); |
| 161 } |
| 162 { |
| 163 String search = '] = 1'; |
| 164 await _getNavigation(testFile, testCode.indexOf(search), 1); |
| 165 assertHasOperatorRegion(search, 1, '[]=(index', 3); |
| 166 } |
| 167 { |
| 168 String search = '[2'; |
| 169 await _getNavigation(testFile, testCode.indexOf(search), 1); |
| 170 assertHasOperatorRegion(search, 1, '[]=(index', 3); |
| 171 } |
| 172 { |
| 173 String search = '] += 2'; |
| 174 await _getNavigation(testFile, testCode.indexOf(search), 1); |
| 175 assertHasOperatorRegion(search, 1, '[]=(index', 3); |
| 176 } |
| 177 } |
| 178 |
133 test_removeContextAfterRequest() async { | 179 test_removeContextAfterRequest() async { |
134 addTestFile(''' | 180 addTestFile(''' |
135 main() { | 181 main() { |
136 var test = 0; | 182 var test = 0; |
137 print(test); | 183 print(test); |
138 } | 184 } |
139 '''); | 185 '''); |
140 // handle the request synchronously | 186 // handle the request synchronously |
141 Request request = | 187 Request request = |
142 _createGetNavigationRequest(testFile, testCode.indexOf('test);'), 0); | 188 _createGetNavigationRequest(testFile, testCode.indexOf('test);'), 0); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 _getNavigation(String file, int offset, int length) async { | 239 _getNavigation(String file, int offset, int length) async { |
194 Request request = _createGetNavigationRequest(file, offset, length); | 240 Request request = _createGetNavigationRequest(file, offset, length); |
195 Response response = await serverChannel.sendRequest(request); | 241 Response response = await serverChannel.sendRequest(request); |
196 AnalysisGetNavigationResult result = | 242 AnalysisGetNavigationResult result = |
197 new AnalysisGetNavigationResult.fromResponse(response); | 243 new AnalysisGetNavigationResult.fromResponse(response); |
198 targetFiles = result.files; | 244 targetFiles = result.files; |
199 targets = result.targets; | 245 targets = result.targets; |
200 regions = result.regions; | 246 regions = result.regions; |
201 } | 247 } |
202 } | 248 } |
OLD | NEW |