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

Side by Side Diff: pkg/analyzer_plugin/test/src/utilities/navigation_test.dart

Issue 2902193002: Add navigation support in plugins (Closed)
Patch Set: Created 3 years, 7 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 'package:analyzer_plugin/protocol/protocol_common.dart';
6 import 'package:analyzer_plugin/src/utilities/navigation.dart';
7 import 'package:test/test.dart';
8 import 'package:test_reflective_loader/test_reflective_loader.dart';
9
10 void main() {
11 defineReflectiveTests(NavigationCollectorImplTest);
12 }
13
14 @reflectiveTest
15 class NavigationCollectorImplTest {
16 NavigationCollectorImpl collector = new NavigationCollectorImpl();
17
18 test_createRegions_multiple() {
19 // Two files, each with two targets.
20 String fileA = 'a.dart';
21 int targetOffsetA1 = 1;
22 int targetLengthA1 = 2;
23 int targetStartLineA1 = 3;
24 int targetStartColumnA1 = 4;
25 ElementKind targetKindA1 = ElementKind.CLASS;
26 Location targetLocationA1 = new Location(fileA, targetOffsetA1,
27 targetLengthA1, targetStartLineA1, targetStartColumnA1);
28 int targetOffsetA2 = 5;
29 int targetLengthA2 = 6;
30 int targetStartLineA2 = 7;
31 int targetStartColumnA2 = 8;
32 ElementKind targetKindA2 = ElementKind.FUNCTION;
33 Location targetLocationA2 = new Location(fileA, targetOffsetA2,
34 targetLengthA2, targetStartLineA2, targetStartColumnA2);
35
36 String fileB = 'b.dart';
37 int targetOffsetB1 = 9;
38 int targetLengthB1 = 10;
39 int targetStartLineB1 = 11;
40 int targetStartColumnB1 = 12;
41 ElementKind targetKindB1 = ElementKind.ENUM;
42 Location targetLocationB1 = new Location(fileB, targetOffsetB1,
43 targetLengthB1, targetStartLineB1, targetStartColumnB1);
44 int targetOffsetB2 = 13;
45 int targetLengthB2 = 14;
46 int targetStartLineB2 = 15;
47 int targetStartColumnB2 = 16;
48 ElementKind targetKindB2 = ElementKind.METHOD;
49 Location targetLocationB2 = new Location(fileB, targetOffsetB2,
50 targetLengthB2, targetStartLineB2, targetStartColumnB2);
51
52 // Six regions targeting a1, b1, a2, b1, a1, b2
53 List<int> regionOffsets = [17, 18, 19, 20, 21, 22];
54 List<int> regionLengths = [23, 24, 25, 26, 27, 28];
55 List<ElementKind> targetKinds = [
56 targetKindA1,
57 targetKindB1,
58 targetKindA2,
59 targetKindB1,
60 targetKindA1,
61 targetKindB2
62 ];
63 List<Location> targetLocations = [
64 targetLocationA1,
65 targetLocationB1,
66 targetLocationA2,
67 targetLocationB1,
68 targetLocationA1,
69 targetLocationB2
70 ];
71 for (int i = 0; i < 6; i++) {
72 collector.addRegion(regionOffsets[i], regionLengths[i], targetKinds[i],
73 targetLocations[i]);
74 }
75
76 collector.createRegions();
77 expect(collector.files, [fileA, fileB]);
78 expect(collector.regions, [
79 new NavigationRegion(regionOffsets[0], regionLengths[0], [0]),
80 new NavigationRegion(regionOffsets[1], regionLengths[1], [1]),
81 new NavigationRegion(regionOffsets[2], regionLengths[2], [2]),
82 new NavigationRegion(regionOffsets[3], regionLengths[3], [1]),
83 new NavigationRegion(regionOffsets[4], regionLengths[4], [0]),
84 new NavigationRegion(regionOffsets[5], regionLengths[5], [3]),
85 ]);
86 expect(collector.targets, [
87 new NavigationTarget(targetKindA1, 0, targetOffsetA1, targetLengthA1,
88 targetStartLineA1, targetStartColumnA1),
89 new NavigationTarget(targetKindB1, 1, targetOffsetB1, targetLengthB1,
90 targetStartLineB1, targetStartColumnB1),
91 new NavigationTarget(targetKindA2, 0, targetOffsetA2, targetLengthA2,
92 targetStartLineA2, targetStartColumnA2),
93 new NavigationTarget(targetKindB2, 1, targetOffsetB2, targetLengthB2,
94 targetStartLineB2, targetStartColumnB2),
95 ]);
96 }
97
98 test_createRegions_none() {
99 collector.createRegions();
100 expect(collector.files, isEmpty);
101 expect(collector.regions, isEmpty);
102 expect(collector.targets, isEmpty);
103 }
104
105 test_createRegions_single() {
106 int regionOffset = 13;
107 int regionLength = 7;
108 ElementKind targetKind = ElementKind.CLASS;
109 String targetFile = 'c.dart';
110 int targetOffset = 17;
111 int targetLength = 1;
112 int targetStartLine = 5;
113 int targetStartColumn = 1;
114 Location targetLocation = new Location(targetFile, targetOffset,
115 targetLength, targetStartLine, targetStartColumn);
116 collector.addRegion(regionOffset, regionLength, targetKind, targetLocation);
117 collector.createRegions();
118 expect(collector.files, [targetFile]);
119 expect(collector.regions, [
120 new NavigationRegion(regionOffset, regionLength, [0])
121 ]);
122 expect(collector.targets, [
123 new NavigationTarget(targetKind, 0, targetOffset, targetLength,
124 targetStartLine, targetStartColumn)
125 ]);
126 }
127 }
OLDNEW
« no previous file with comments | « pkg/analyzer_plugin/lib/utilities/pair.dart ('k') | pkg/analyzer_plugin/test/src/utilities/test_all.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698