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

Side by Side Diff: pkg/analysis_server/test/analysis_hover_test.dart

Issue 362893004: Implementation for 'analysis.getHover'. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library test.domain.analysis.hover;
6
7 import 'dart:async';
8
9 import 'package:analysis_server/src/computer/computer_hover.dart';
10 import 'package:analysis_server/src/constants.dart';
11 import 'package:analysis_server/src/protocol.dart';
12 import 'package:unittest/unittest.dart';
13
14 import 'analysis_abstract.dart';
15 import 'reflective_tests.dart';
16
17
18 main() {
19 group('notification.hover', () {
20 runReflectiveTests(AnalysisHoverTest);
21 });
22 }
23
24
25 @ReflectiveTestCase()
26 class AnalysisHoverTest extends AbstractAnalysisTest {
27 List<Hover> hovers;
28 Hover hover;
29
30 Future prepareHover(String search, then()) {
31 int offset = findOffset(search);
32 return prepareHoverAt(offset, then);
33 }
34
35 Future prepareHoverAt(int offset, then()) {
36 return waitForTasksFinished().then((_) {
37 Request request = new Request('0', ANALYSIS_GET_HOVER);
38 request.setParameter(FILE, testFile);
39 request.setParameter(OFFSET, offset);
40 Response response = handleSuccessfulRequest(request);
41 List<Map<String, Object>> hoverJsons = response.getResult(HOVERS);
42 hovers = hoverJsons.map((json) {
43 return new Hover.fromJson(json);
44 }).toList();
45 hover = hovers.isNotEmpty ? hovers.first : null;
46 then();
47 });
48 }
49
50 @override
51 void setUp() {
52 super.setUp();
53 createProject();
54 }
55
56 test_expression_function() {
57 addTestFile('''
58 library my.library;
59 /// doc aaa
60 /// doc bbb
61 List<String> fff(int a, String b) {
62 }
63 ''');
64 return prepareHover('fff(int a', () {
65 // element
66 expect(hover.containingLibraryName, 'my.library');
67 expect(hover.containingLibraryPath, testFile);
68 expect(hover.dartDoc, '''/// doc aaa\n/// doc bbb''');
Brian Wilkerson 2014/07/02 13:58:06 I think I need to update the spec. because I think
scheglov 2014/07/02 17:33:09 No need to change the spec. I will change the impl
69 expect(hover.elementDescription, 'fff(int a, String b) → List<String>');
70 // types
71 expect(hover.staticType, '(int, String) → List<String>');
72 expect(hover.propagatedType, isNull);
73 // no parameter
74 expect(hover.parameter, isNull);
75 });
76 }
77
78 test_expression_method() {
79 addTestFile('''
80 library my.library;
81 class A {
82 /// doc aaa
83 /// doc bbb
84 List<String> mmm(int a, String b) {
85 }
86 }
87 ''');
88 return prepareHover('mmm(int a', () {
89 // element
90 expect(hover.containingLibraryName, 'my.library');
91 expect(hover.containingLibraryPath, testFile);
92 expect(hover.dartDoc, '''/// doc aaa\n/// doc bbb''');
93 expect(hover.elementDescription, 'A.mmm(int a, String b) → List<String>');
94 // types
95 expect(hover.staticType, '(int, String) → List<String>');
96 expect(hover.propagatedType, isNull);
97 // no parameter
98 expect(hover.parameter, isNull);
99 });
100 }
101
102 test_expression_syntheticGetter() {
103 addTestFile('''
104 library my.library;
105 class A {
106 /// doc aaa
107 /// doc bbb
108 String fff;
109 }
110 main(A a) {
111 print(a.fff);
112 }
113 ''');
114 return prepareHover('fff);', () {
115 // element
116 expect(hover.containingLibraryName, 'my.library');
117 expect(hover.containingLibraryPath, testFile);
118 expect(hover.dartDoc, '''/// doc aaa\n/// doc bbb''');
119 expect(hover.elementDescription, 'String fff');
120 // types
121 expect(hover.staticType, 'String');
122 expect(hover.propagatedType, isNull);
123 });
124 }
125
126 test_expression_literal_noElement() {
127 addTestFile('''
128 main() {
129 foo(123);
130 }
131 foo(Object myParameter) {}
132 ''');
133 return prepareHover('123', () {
134 // literal, no Element
135 expect(hover.elementDescription, isNull);
136 // types
137 expect(hover.staticType, 'int');
138 expect(hover.propagatedType, isNull);
139 // parameter
140 expect(hover.parameter, 'Object myParameter');
141 });
142 }
143
144 test_expression_variable_hasPropagatedType() {
145 addTestFile('''
146 library my.library;
147 main() {
148 var vvv = 123;
149 print(vvv);
150 }
151 ''');
152 return prepareHover('vvv);', () {
153 // element
154 expect(hover.containingLibraryName, 'my.library');
155 expect(hover.containingLibraryPath, testFile);
156 expect(hover.dartDoc, isNull);
157 expect(hover.elementDescription, 'dynamic vvv');
158 // types
159 expect(hover.staticType, 'dynamic');
160 expect(hover.propagatedType, 'int');
161 });
162 }
163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698