Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: pkg/analyzer_plugin/test/plugin/navigation_mixin_test.dart

Issue 2932553004: Add tests for recently added mixins and improve plugin tests (Closed)
Patch Set: Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'dart:async';
6
7 import 'package:analyzer/dart/analysis/results.dart' hide AnalysisResult;
8 import 'package:analyzer/file_system/file_system.dart';
9 import 'package:analyzer/file_system/memory_file_system.dart';
10 import 'package:analyzer/src/dart/analysis/driver.dart';
11 import 'package:analyzer_plugin/plugin/navigation_mixin.dart';
12 import 'package:analyzer_plugin/protocol/protocol_common.dart';
13 import 'package:analyzer_plugin/protocol/protocol_generated.dart';
14 import 'package:analyzer_plugin/utilities/navigation/navigation.dart';
15 import 'package:path/src/context.dart';
16 import 'package:test/test.dart';
17 import 'package:test_reflective_loader/test_reflective_loader.dart';
18
19 import 'mocks.dart';
20
21 void main() {
22 defineReflectiveTests(NavigationMixinTest);
23 }
24
25 @reflectiveTest
26 class NavigationMixinTest {
27 MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
28
29 String packagePath1;
30 String filePath1;
31 ContextRoot contextRoot1;
32
33 MockChannel channel;
34 _TestServerPlugin plugin;
35
36 void setUp() {
37 Context pathContext = resourceProvider.pathContext;
38
39 packagePath1 = resourceProvider.convertPath('/package1');
40 filePath1 = pathContext.join(packagePath1, 'lib', 'test.dart');
41 resourceProvider.newFile(filePath1, '');
42 contextRoot1 = new ContextRoot(packagePath1, <String>[]);
43
44 channel = new MockChannel();
45 plugin = new _TestServerPlugin(resourceProvider);
46 plugin.start(channel);
47 }
48
49 test_handleAnalysisGetNavigation() async {
50 await plugin.handleAnalysisSetContextRoots(
51 new AnalysisSetContextRootsParams([contextRoot1]));
52
53 var result = await plugin.handleAnalysisGetNavigation(
54 new AnalysisGetNavigationParams(filePath1, 1, 2));
55 expect(result, isNotNull);
56 expect(result.files, hasLength(1));
57 expect(result.targets, hasLength(1));
58 expect(result.regions, hasLength(2));
59 }
60 }
61
62 class _TestNavigationContributor implements NavigationContributor {
63 int regionCount;
64
65 _TestNavigationContributor(this.regionCount);
66
67 @override
68 void computeNavigation(
69 NavigationRequest request, NavigationCollector collector) {
70 for (int i = 0; i < regionCount; i++) {
71 collector.addRegion(
72 i, 5, ElementKind.METHOD, new Location('a', 5, 5, 1, 5));
73 }
74 }
75 }
76
77 class _TestServerPlugin extends MockServerPlugin with NavigationMixin {
78 _TestServerPlugin(ResourceProvider resourceProvider)
79 : super(resourceProvider);
80
81 @override
82 List<NavigationContributor> getNavigationContributors(
83 AnalysisDriverGeneric driver) {
84 return <NavigationContributor>[
85 new _TestNavigationContributor(2),
86 new _TestNavigationContributor(1)
87 ];
88 }
89
90 @override
91 Future<ResolveResult> getResolveResultForNavigation(
92 AnalysisDriverGeneric driver, String path) async {
93 return new AnalysisResult(
94 null, null, null, null, null, null, null, null, null, null, null);
95 }
96 }
OLDNEW
« no previous file with comments | « pkg/analyzer_plugin/test/plugin/mocks.dart ('k') | pkg/analyzer_plugin/test/plugin/plugin_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698