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

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

Issue 631553002: Change integration test notifications to use structured objects. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 library test.integration.analysis.highlights; 5 library test.integration.analysis.highlights;
6 6
7 import 'package:analysis_server/src/protocol.dart'; 7 import 'package:analysis_server/src/protocol.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 import '../../reflective_tests.dart'; 10 import '../../reflective_tests.dart';
11 import '../integration_tests.dart'; 11 import '../integration_tests.dart';
12 12
13 @ReflectiveTestCase() 13 @ReflectiveTestCase()
14 class AnalysisHighlightsTest extends AbstractAnalysisServerIntegrationTest { 14 class AnalysisHighlightsTest extends AbstractAnalysisServerIntegrationTest {
15 test_highlights() { 15 test_highlights() {
16 String pathname = sourcePath('test.dart'); 16 String pathname = sourcePath('test.dart');
17 String text = 17 String text = r'''
18 r'''
19 import 'dart:async' as async; 18 import 'dart:async' as async;
20 19
21 /** 20 /**
22 * Doc comment 21 * Doc comment
23 */ 22 */
24 class Class<TypeParameter> { 23 class Class<TypeParameter> {
25 Class() { 24 Class() {
26 field = {1.0: [].toList()}; 25 field = {1.0: [].toList()};
27 } 26 }
28 27
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 function(dynamicType) { 59 function(dynamicType) {
61 print('string'); 60 print('string');
62 unresolvedIdentifier = 42; 61 unresolvedIdentifier = 42;
63 return async.Future.wait([]); 62 return async.Future.wait([]);
64 } 63 }
65 64
66 int topLevelVariable; 65 int topLevelVariable;
67 '''; 66 ''';
68 writeFile(pathname, text); 67 writeFile(pathname, text);
69 standardAnalysisSetup(); 68 standardAnalysisSetup();
70 sendAnalysisSetSubscriptions({AnalysisService.HIGHLIGHTS: [pathname]}); 69 sendAnalysisSetSubscriptions({
70 AnalysisService.HIGHLIGHTS: [pathname]
71 });
71 // Map from highlight type to highlighted text 72 // Map from highlight type to highlighted text
72 Map<String, Set<String>> highlights; 73 Map<HighlightRegionType, Set<String>> highlights;
73 onAnalysisHighlights.listen((params) { 74 onAnalysisHighlights.listen((AnalysisHighlightsParams params) {
74 expect(params['file'], equals(pathname)); 75 expect(params.file, equals(pathname));
75 highlights = <String, Set<String>>{}; 76 highlights = <HighlightRegionType, Set<String>>{};
76 for (var region in params['regions']) { 77 for (HighlightRegion region in params.regions) {
77 int startIndex = region['offset']; 78 int startIndex = region.offset;
78 int endIndex = startIndex + region['length']; 79 int endIndex = startIndex + region.length;
79 String highlightedText = text.substring(startIndex, endIndex); 80 String highlightedText = text.substring(startIndex, endIndex);
80 String type = region['type']; 81 HighlightRegionType type = region.type;
81 if (!highlights.containsKey(type)) { 82 if (!highlights.containsKey(type)) {
82 highlights[type] = new Set<String>(); 83 highlights[type] = new Set<String>();
83 } 84 }
84 highlights[type].add(highlightedText); 85 highlights[type].add(highlightedText);
85 } 86 }
86 }); 87 });
87 return analysisFinished.then((_) { 88 return analysisFinished.then((_) {
88 // There should be 1 error due to the fact that unresolvedIdentifier is 89 // There should be 1 error due to the fact that unresolvedIdentifier is
89 // unresolved. 90 // unresolved.
90 expect(currentAnalysisErrors[pathname], hasLength(1)); 91 expect(currentAnalysisErrors[pathname], hasLength(1));
91 void check(String type, List<String> expected) { 92 void check(HighlightRegionType type, List<String> expected) {
92 expect(highlights[type], equals(expected.toSet())); 93 expect(highlights[type], equals(expected.toSet()));
93 highlights.remove(type); 94 highlights.remove(type);
94 } 95 }
95 check('ANNOTATION', ['@override']); 96 check(HighlightRegionType.ANNOTATION, ['@override']);
96 check('BUILT_IN', ['as', 'get', 'import', 'set', 'static', 'typedef']); 97 check(
97 check('CLASS', ['Class', 'Class2', 'Future', 'Map', 'int']); 98 HighlightRegionType.BUILT_IN,
98 check('COMMENT_BLOCK', ['/* Block comment */']); 99 ['as', 'get', 'import', 'set', 'static', 'typedef']);
99 check('COMMENT_DOCUMENTATION', ['/**\n * Doc comment\n */']); 100 check(
100 check('COMMENT_END_OF_LINE', ['// End of line comment']); 101 HighlightRegionType.CLASS,
101 check('CONSTRUCTOR', ['constructor']); 102 ['Class', 'Class2', 'Future', 'Map', 'int']);
102 check('DIRECTIVE', ["import 'dart:async' as async;"]); 103 check(HighlightRegionType.COMMENT_BLOCK, ['/* Block comment */']);
103 check('DYNAMIC_TYPE', ['dynamicType']); 104 check(
104 check('FIELD', ['field']); 105 HighlightRegionType.COMMENT_DOCUMENTATION,
105 check('FIELD_STATIC', ['staticField']); 106 ['/**\n * Doc comment\n */']);
106 check('FUNCTION', ['print']); 107 check(
107 check('FUNCTION_DECLARATION', ['function']); 108 HighlightRegionType.COMMENT_END_OF_LINE,
108 check('FUNCTION_TYPE_ALIAS', ['functionType']); 109 ['// End of line comment']);
109 check('GETTER_DECLARATION', ['getter']); 110 check(HighlightRegionType.CONSTRUCTOR, ['constructor']);
110 check('IDENTIFIER_DEFAULT', ['unresolvedIdentifier']); 111 check(HighlightRegionType.DIRECTIVE, ["import 'dart:async' as async;"]);
111 check('IMPORT_PREFIX', ['async']); 112 check(HighlightRegionType.DYNAMIC_TYPE, ['dynamicType']);
112 check('KEYWORD', ['class', 'true', 'return']); 113 check(HighlightRegionType.FIELD, ['field']);
113 check('LITERAL_BOOLEAN', ['true']); 114 check(HighlightRegionType.FIELD_STATIC, ['staticField']);
114 check('LITERAL_DOUBLE', ['1.0']); 115 check(HighlightRegionType.FUNCTION, ['print']);
115 check('LITERAL_INTEGER', ['2', '42']); 116 check(HighlightRegionType.FUNCTION_DECLARATION, ['function']);
116 check('LITERAL_LIST', ['[]']); 117 check(HighlightRegionType.FUNCTION_TYPE_ALIAS, ['functionType']);
117 check('LITERAL_MAP', ['{1.0: [].toList()}', '{2: local}']); 118 check(HighlightRegionType.GETTER_DECLARATION, ['getter']);
118 check('LITERAL_STRING', ["'dart:async'", "'string'"]); 119 check(HighlightRegionType.IDENTIFIER_DEFAULT, ['unresolvedIdentifier']);
119 check('LOCAL_VARIABLE', ['local']); 120 check(HighlightRegionType.IMPORT_PREFIX, ['async']);
120 check('LOCAL_VARIABLE_DECLARATION', ['local']); 121 check(HighlightRegionType.KEYWORD, ['class', 'true', 'return']);
121 check('METHOD', ['toList']); 122 check(HighlightRegionType.LITERAL_BOOLEAN, ['true']);
122 check('METHOD_DECLARATION', ['method']); 123 check(HighlightRegionType.LITERAL_DOUBLE, ['1.0']);
123 check('METHOD_DECLARATION_STATIC', ['staticMethod']); 124 check(HighlightRegionType.LITERAL_INTEGER, ['2', '42']);
124 check('METHOD_STATIC', ['wait']); 125 check(HighlightRegionType.LITERAL_LIST, ['[]']);
125 check('PARAMETER', ['parameter']); 126 check(
126 check('SETTER_DECLARATION', ['setter']); 127 HighlightRegionType.LITERAL_MAP,
127 check('TOP_LEVEL_VARIABLE', ['override', 'topLevelVariable']); 128 ['{1.0: [].toList()}', '{2: local}']);
128 check('TYPE_NAME_DYNAMIC', ['dynamic']); 129 check(HighlightRegionType.LITERAL_STRING, ["'dart:async'", "'string'"]);
129 check('TYPE_PARAMETER', ['TypeParameter']); 130 check(HighlightRegionType.LOCAL_VARIABLE, ['local']);
131 check(HighlightRegionType.LOCAL_VARIABLE_DECLARATION, ['local']);
132 check(HighlightRegionType.METHOD, ['toList']);
133 check(HighlightRegionType.METHOD_DECLARATION, ['method']);
134 check(HighlightRegionType.METHOD_DECLARATION_STATIC, ['staticMethod']);
135 check(HighlightRegionType.METHOD_STATIC, ['wait']);
136 check(HighlightRegionType.PARAMETER, ['parameter']);
137 check(HighlightRegionType.SETTER_DECLARATION, ['setter']);
138 check(
139 HighlightRegionType.TOP_LEVEL_VARIABLE,
140 ['override', 'topLevelVariable']);
141 check(HighlightRegionType.TYPE_NAME_DYNAMIC, ['dynamic']);
142 check(HighlightRegionType.TYPE_PARAMETER, ['TypeParameter']);
130 expect(highlights, isEmpty); 143 expect(highlights, isEmpty);
131 }); 144 });
132 } 145 }
133 } 146 }
134 147
135 main() { 148 main() {
136 runReflectiveTests(AnalysisHighlightsTest); 149 runReflectiveTests(AnalysisHighlightsTest);
137 } 150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698