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

Side by Side Diff: pkg/analysis_server/test/integration/analysis/highlights_test.dart

Issue 463643002: Add an integration test for analysis.highlights. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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.integration.analysis.highlights;
6
7 import 'package:analysis_testing/reflective_tests.dart';
8 import 'package:unittest/unittest.dart';
9
10 import '../integration_tests.dart';
11
12 @ReflectiveTestCase()
13 class AnalysisHighlightsTest extends AbstractAnalysisServerIntegrationTest {
14 test_highlights() {
15 String pathname = sourcePath('test.dart');
16 String text =
17 r'''
18 import 'dart:async' as async;
19
20 /**
21 * Doc comment
22 */
23 class Class<TypeParameter> {
24 Class() {
25 field = {1.0: [].toList()};
26 }
27
28 Class.constructor() {
29 dynamic local = true;
30 field = {2: local};
31 }
32
33 Map field;
34 static int staticField;
35
36 method() {
37 // End of line comment
38 /* Block comment */
39 }
40
41 static staticMethod() {
42 }
43
44 get getter {
45 }
46
47 set setter(int parameter) {
48 }
49 }
50
51 class Class2<TypeParameter> extends Class<TypeParameter> {
52 @override
53 method() {
54 }
55 }
56
57 typedef functionType();
58
59 function(dynamicType) {
60 print('string');
61 return async.Future.wait([]);
62 }
63
64 int topLevelVariable;
65 ''';
66 writeFile(pathname, text);
67 standardAnalysisSetup();
68 sendAnalysisSetSubscriptions({'HIGHLIGHTS': [pathname]});
69 // Map from highlight type to highlighted text
70 Map<String, Set<String>> highlights;
71 onAnalysisHighlights.listen((params) {
72 expect(params['file'], equals(pathname));
73 highlights = <String, Set<String>>{};
74 for (var region in params['regions']) {
75 int startIndex = region['offset'];
76 int endIndex = startIndex + region['length'];
77 String highlightedText = text.substring(startIndex, endIndex);
78 String type = region['type'];
79 if (!highlights.containsKey(type)) {
80 highlights[type] = new Set<String>();
81 }
82 highlights[type].add(highlightedText);
83 }
84 });
85 return analysisFinished.then((_) {
86 expect(currentAnalysisErrors[pathname], hasLength(0));
87 void check(String type, List<String> expected) {
88 expect(highlights[type], equals(expected.toSet()));
89 highlights.remove(type);
90 }
91 check('ANNOTATION', ['@override']);
92 check('BUILT_IN', ['as', 'get', 'import', 'set', 'static', 'typedef']);
93 check('CLASS', ['Class', 'Class2', 'Future', 'Map', 'int']);
94 check('COMMENT_BLOCK', ['/* Block comment */']);
95 check('COMMENT_DOCUMENTATION', ['/**\n * Doc comment\n */']);
96 check('COMMENT_END_OF_LINE', ['// End of line comment']);
97 check('CONSTRUCTOR', ['constructor']);
98 // TODO(paulberry): When is the 'DIRECTIVE' type used?
scheglov 2014/08/12 02:28:46 It's a bug in the highlights computer.
99 check('DYNAMIC_TYPE', ['dynamicType']);
100 check('FIELD', ['field']);
101 // TODO(paulberry): Why is "override" annotated as FIELD_STATIC?
scheglov 2014/08/12 02:28:46 It's a bug in the highlights computer.
102 check('FIELD_STATIC', ['override', 'staticField']);
103 check('FUNCTION', ['print']);
104 check('FUNCTION_DECLARATION', ['function']);
105 check('FUNCTION_TYPE_ALIAS', ['functionType']);
106 check('GETTER_DECLARATION', ['getter']);
107 // TODO(paulberry): When is the 'IDENTIFIER_DEFAULT' type used?
scheglov 2014/08/12 02:28:47 For unresolved identifiers: aaa, bbb, CCC. main()
108 check('IMPORT_PREFIX', ['async']);
109 // TODO(paulberry): When is the 'KEYWORD' type used?
scheglov 2014/08/12 02:28:46 It's a bug in the highlights computer.
110 check('LITERAL_BOOLEAN', ['true']);
111 check('LITERAL_DOUBLE', ['1.0']);
112 check('LITERAL_INTEGER', ['2']);
113 // TODO(paulberry): When is the 'LITERAL_LIST' type used?
114 // TODO(paulberry): When is the 'LITERAL_MAP' type used?
scheglov 2014/08/12 02:28:46 These are bugs in the highlights computer.
115 check('LITERAL_STRING', ["'dart:async'", "'string'"]);
116 check('LOCAL_VARIABLE', ['local']);
117 check('LOCAL_VARIABLE_DECLARATION', ['local']);
118 check('METHOD', ['toList']);
119 check('METHOD_DECLARATION', ['method']);
120 check('METHOD_DECLARATION_STATIC', ['staticMethod']);
121 check('METHOD_STATIC', ['wait']);
122 check('PARAMETER', ['parameter']);
123 check('SETTER_DECLARATION', ['setter']);
124 check('TOP_LEVEL_VARIABLE', ['topLevelVariable']);
125 check('TYPE_NAME_DYNAMIC', ['dynamic']);
126 check('TYPE_PARAMETER', ['TypeParameter']);
127 expect(highlights, isEmpty);
128 });
129 }
130 }
131
132 main() {
133 runReflectiveTests(AnalysisHighlightsTest);
134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698