OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 'package:analyzer/dart/analysis/results.dart'; | 5 import 'package:analyzer/dart/analysis/results.dart'; |
6 import 'package:analyzer/file_system/memory_file_system.dart'; | 6 import 'package:analyzer/file_system/memory_file_system.dart'; |
7 import 'package:analyzer/src/dart/analysis/driver.dart' as driver; | 7 import 'package:analyzer/src/dart/analysis/driver.dart' as driver; |
8 import 'package:analyzer_plugin/src/utilities/navigation/navigation.dart'; | 8 import 'package:analyzer_plugin/src/utilities/navigation/navigation.dart'; |
9 import 'package:analyzer_plugin/utilities/generator.dart'; | 9 import 'package:analyzer_plugin/utilities/generator.dart'; |
10 import 'package:analyzer_plugin/utilities/navigation/navigation.dart'; | 10 import 'package:analyzer_plugin/utilities/navigation/navigation.dart'; |
11 import 'package:test/test.dart'; | 11 import 'package:test/test.dart'; |
12 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 12 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
13 | 13 |
14 void main() { | 14 void main() { |
15 defineReflectiveTests(NavigationGeneratorTest); | 15 defineReflectiveTests(NavigationGeneratorTest); |
16 } | 16 } |
17 | 17 |
18 @reflectiveTest | 18 @reflectiveTest |
19 class NavigationGeneratorTest { | 19 class NavigationGeneratorTest { |
20 MemoryResourceProvider provider = new MemoryResourceProvider(); | 20 MemoryResourceProvider provider = new MemoryResourceProvider(); |
21 | 21 |
22 ResolveResult resolveResult = new driver.AnalysisResult( | 22 ResolveResult resolveResult = new driver.AnalysisResult( |
23 null, null, 'a.dart', null, true, '', null, '', null, null, null); | 23 null, null, 'a.dart', null, true, '', null, '', null, null, null); |
24 | 24 |
25 test_none() { | 25 test_none() { |
26 NavigationGenerator generator = new NavigationGenerator([]); | 26 NavigationGenerator generator = new NavigationGenerator([]); |
27 NavigationRequest request = | 27 NavigationRequest request = |
28 new NavigationRequestImpl(provider, 0, 100, resolveResult); | 28 new DartNavigationRequestImpl(provider, 0, 100, resolveResult); |
29 GeneratorResult result = generator.generateNavigationNotification(request); | 29 GeneratorResult result = generator.generateNavigationNotification(request); |
30 expect(result.notifications, hasLength(1)); | 30 expect(result.notifications, hasLength(1)); |
31 } | 31 } |
32 | 32 |
33 test_normal() { | 33 test_normal() { |
34 TestContributor contributor = new TestContributor(); | 34 TestContributor contributor = new TestContributor(); |
35 NavigationGenerator generator = new NavigationGenerator([contributor]); | 35 NavigationGenerator generator = new NavigationGenerator([contributor]); |
36 NavigationRequest request = | 36 NavigationRequest request = |
37 new NavigationRequestImpl(provider, 0, 100, resolveResult); | 37 new DartNavigationRequestImpl(provider, 0, 100, resolveResult); |
38 GeneratorResult result = generator.generateNavigationNotification(request); | 38 GeneratorResult result = generator.generateNavigationNotification(request); |
39 expect(result.notifications, hasLength(1)); | 39 expect(result.notifications, hasLength(1)); |
40 expect(contributor.count, 1); | 40 expect(contributor.count, 1); |
41 } | 41 } |
42 | 42 |
43 /** | 43 /** |
44 * This tests that we get an error notification for each contributor that | 44 * This tests that we get an error notification for each contributor that |
45 * throws an error and that an error in one contributor doesn't prevent other | 45 * throws an error and that an error in one contributor doesn't prevent other |
46 * contributors from being called. | 46 * contributors from being called. |
47 */ | 47 */ |
48 test_withException() { | 48 test_withException() { |
49 TestContributor contributor1 = new TestContributor(); | 49 TestContributor contributor1 = new TestContributor(); |
50 TestContributor contributor2 = new TestContributor(throwException: true); | 50 TestContributor contributor2 = new TestContributor(throwException: true); |
51 TestContributor contributor3 = new TestContributor(); | 51 TestContributor contributor3 = new TestContributor(); |
52 TestContributor contributor4 = new TestContributor(throwException: true); | 52 TestContributor contributor4 = new TestContributor(throwException: true); |
53 NavigationGenerator generator = new NavigationGenerator( | 53 NavigationGenerator generator = new NavigationGenerator( |
54 [contributor1, contributor2, contributor3, contributor4]); | 54 [contributor1, contributor2, contributor3, contributor4]); |
55 NavigationRequest request = | 55 NavigationRequest request = |
56 new NavigationRequestImpl(provider, 0, 100, resolveResult); | 56 new DartNavigationRequestImpl(provider, 0, 100, resolveResult); |
57 GeneratorResult result = generator.generateNavigationNotification(request); | 57 GeneratorResult result = generator.generateNavigationNotification(request); |
58 expect(result.notifications, hasLength(3)); | 58 expect(result.notifications, hasLength(3)); |
59 expect( | 59 expect( |
60 result.notifications.where( | 60 result.notifications.where( |
61 (notification) => notification.event == 'analysis.navigation'), | 61 (notification) => notification.event == 'analysis.navigation'), |
62 hasLength(1)); | 62 hasLength(1)); |
63 expect( | 63 expect( |
64 result.notifications | 64 result.notifications |
65 .where((notification) => notification.event == 'plugin.error'), | 65 .where((notification) => notification.event == 'plugin.error'), |
66 hasLength(2)); | 66 hasLength(2)); |
(...skipping 20 matching lines...) Expand all Loading... |
87 | 87 |
88 @override | 88 @override |
89 void computeNavigation( | 89 void computeNavigation( |
90 NavigationRequest request, NavigationCollector collector) { | 90 NavigationRequest request, NavigationCollector collector) { |
91 count++; | 91 count++; |
92 if (throwException) { | 92 if (throwException) { |
93 throw new Exception(); | 93 throw new Exception(); |
94 } | 94 } |
95 } | 95 } |
96 } | 96 } |
OLD | NEW |