| 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.notification.navigation; | 5 library test.analysis.notification.navigation; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 10 import 'package:analysis_server/src/constants.dart'; | 10 import 'package:analysis_server/src/constants.dart'; |
| 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 11 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 12 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
| 13 | 13 |
| 14 import '../analysis_abstract.dart'; | 14 import '../analysis_abstract.dart'; |
| 15 import '../utils.dart'; | 15 import '../utils.dart'; |
| 16 | 16 |
| 17 main() { | 17 main() { |
| 18 initializeTestEnvironment(); | 18 initializeTestEnvironment(); |
| 19 defineReflectiveTests(AnalysisNotificationNavigationTest); | 19 defineReflectiveTests(AnalysisNotificationNavigationTest); |
| 20 } | 20 } |
| 21 | 21 |
| 22 class AbstractNavigationTest extends AbstractAnalysisTest { | 22 class AbstractNavigationTest extends AbstractAnalysisTest { |
| 23 List<NavigationRegion> regions; | 23 List<NavigationRegion> regions; |
| 24 List<NavigationTarget> targets; | 24 List<NavigationTarget> targets; |
| 25 List<String> targetFiles; | 25 List<String> targetFiles; |
| 26 | 26 |
| 27 NavigationRegion testRegion; | 27 NavigationRegion testRegion; |
| 28 List<int> testTargetIndexes; | 28 List<int> testTargetIndexes; |
| 29 List<NavigationTarget> testTargets; |
| 29 NavigationTarget testTarget; | 30 NavigationTarget testTarget; |
| 30 | 31 |
| 31 /** | 32 /** |
| 32 * Validates that there is a target in [testTargetIndexes] with [file], | 33 * Validates that there is a target in [testTargetIndexes] with [file], |
| 33 * at [offset] and with the given [length]. | 34 * at [offset] and with the given [length]. |
| 34 */ | 35 */ |
| 35 void assertHasFileTarget(String file, int offset, int length) { | 36 void assertHasFileTarget(String file, int offset, int length) { |
| 36 List<NavigationTarget> testTargets = | |
| 37 testTargetIndexes.map((int index) => targets[index]).toList(); | |
| 38 for (NavigationTarget target in testTargets) { | 37 for (NavigationTarget target in testTargets) { |
| 39 if (targetFiles[target.fileIndex] == file && | 38 if (targetFiles[target.fileIndex] == file && |
| 40 target.offset == offset && | 39 target.offset == offset && |
| 41 target.length == length) { | 40 target.length == length) { |
| 42 testTarget = target; | 41 testTarget = target; |
| 43 return; | 42 return; |
| 44 } | 43 } |
| 45 } | 44 } |
| 46 fail( | 45 fail( |
| 47 'Expected to find target (file=$file; offset=$offset; length=$length) in
\n' | 46 'Expected to find target (file=$file; offset=$offset; length=$length) in
\n' |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 void findRegion(int offset, int length, bool exists) { | 159 void findRegion(int offset, int length, bool exists) { |
| 161 for (NavigationRegion region in regions) { | 160 for (NavigationRegion region in regions) { |
| 162 if (region.offset == offset && | 161 if (region.offset == offset && |
| 163 (length == -1 || region.length == length)) { | 162 (length == -1 || region.length == length)) { |
| 164 if (exists == false) { | 163 if (exists == false) { |
| 165 fail('Not expected to find (offset=$offset; length=$length) in\n' | 164 fail('Not expected to find (offset=$offset; length=$length) in\n' |
| 166 '${regions.join('\n')}'); | 165 '${regions.join('\n')}'); |
| 167 } | 166 } |
| 168 testRegion = region; | 167 testRegion = region; |
| 169 testTargetIndexes = region.targets; | 168 testTargetIndexes = region.targets; |
| 169 testTargets = testTargetIndexes.map((i) => targets[i]).toList(); |
| 170 return; | 170 return; |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 if (exists == true) { | 173 if (exists == true) { |
| 174 fail('Expected to find (offset=$offset; length=$length) in\n' | 174 fail('Expected to find (offset=$offset; length=$length) in\n' |
| 175 '${regions.join('\n')}'); | 175 '${regions.join('\n')}'); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 924 test_type_void() { | 924 test_type_void() { |
| 925 addTestFile(''' | 925 addTestFile(''' |
| 926 void main() { | 926 void main() { |
| 927 } | 927 } |
| 928 '''); | 928 '''); |
| 929 return prepareNavigation().then((_) { | 929 return prepareNavigation().then((_) { |
| 930 assertNoRegionAt('void'); | 930 assertNoRegionAt('void'); |
| 931 }); | 931 }); |
| 932 } | 932 } |
| 933 } | 933 } |
| OLD | NEW |