| OLD | NEW |
| 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.highlights2; | 5 library test.integration.analysis.highlights2; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 | 12 |
| 13 import '../../utils.dart'; |
| 13 import '../integration_tests.dart'; | 14 import '../integration_tests.dart'; |
| 14 | 15 |
| 15 main() { | 16 main() { |
| 17 initializeTestEnvironment(); |
| 16 defineReflectiveTests(AnalysisHighlightsTest); | 18 defineReflectiveTests(AnalysisHighlightsTest); |
| 17 } | 19 } |
| 18 | 20 |
| 19 @reflectiveTest | 21 @reflectiveTest |
| 20 class AnalysisHighlightsTest extends AbstractAnalysisServerIntegrationTest { | 22 class AnalysisHighlightsTest extends AbstractAnalysisServerIntegrationTest { |
| 21 Future startServer() { | 23 Future startServer() { |
| 22 return server.start(useAnalysisHighlight2: true); | 24 return server.start(useAnalysisHighlight2: true); |
| 23 } | 25 } |
| 24 | 26 |
| 25 test_highlights() { | 27 test_highlights() { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 function(dynamicType) { | 72 function(dynamicType) { |
| 71 print('string'); | 73 print('string'); |
| 72 unresolvedIdentifier = 42; | 74 unresolvedIdentifier = 42; |
| 73 return async.Future.wait([]); | 75 return async.Future.wait([]); |
| 74 } | 76 } |
| 75 | 77 |
| 76 int topLevelVariable; | 78 int topLevelVariable; |
| 77 '''; | 79 '''; |
| 78 writeFile(pathname, text); | 80 writeFile(pathname, text); |
| 79 standardAnalysisSetup(); | 81 standardAnalysisSetup(); |
| 80 sendAnalysisSetSubscriptions({AnalysisService.HIGHLIGHTS: [pathname]}); | 82 sendAnalysisSetSubscriptions({ |
| 83 AnalysisService.HIGHLIGHTS: [pathname] |
| 84 }); |
| 81 // Map from highlight type to highlighted text | 85 // Map from highlight type to highlighted text |
| 82 Map<HighlightRegionType, Set<String>> highlights; | 86 Map<HighlightRegionType, Set<String>> highlights; |
| 83 onAnalysisHighlights.listen((AnalysisHighlightsParams params) { | 87 onAnalysisHighlights.listen((AnalysisHighlightsParams params) { |
| 84 expect(params.file, equals(pathname)); | 88 expect(params.file, equals(pathname)); |
| 85 highlights = <HighlightRegionType, Set<String>>{}; | 89 highlights = <HighlightRegionType, Set<String>>{}; |
| 86 for (HighlightRegion region in params.regions) { | 90 for (HighlightRegion region in params.regions) { |
| 87 int startIndex = region.offset; | 91 int startIndex = region.offset; |
| 88 int endIndex = startIndex + region.length; | 92 int endIndex = startIndex + region.length; |
| 89 String highlightedText = text.substring(startIndex, endIndex); | 93 String highlightedText = text.substring(startIndex, endIndex); |
| 90 HighlightRegionType type = region.type; | 94 HighlightRegionType type = region.type; |
| 91 if (!highlights.containsKey(type)) { | 95 if (!highlights.containsKey(type)) { |
| 92 highlights[type] = new Set<String>(); | 96 highlights[type] = new Set<String>(); |
| 93 } | 97 } |
| 94 highlights[type].add(highlightedText); | 98 highlights[type].add(highlightedText); |
| 95 } | 99 } |
| 96 }); | 100 }); |
| 97 return analysisFinished.then((_) { | 101 return analysisFinished.then((_) { |
| 98 // There should be 1 error due to the fact that unresolvedIdentifier is | 102 // There should be 1 error due to the fact that unresolvedIdentifier is |
| 99 // unresolved. | 103 // unresolved. |
| 100 expect(currentAnalysisErrors[pathname], hasLength(1)); | 104 expect(currentAnalysisErrors[pathname], hasLength(1)); |
| 101 void check(HighlightRegionType type, List<String> expected) { | 105 void check(HighlightRegionType type, List<String> expected) { |
| 102 expect(highlights[type], equals(expected.toSet())); | 106 expect(highlights[type], equals(expected.toSet())); |
| 103 highlights.remove(type); | 107 highlights.remove(type); |
| 104 } | 108 } |
| 105 check(HighlightRegionType.ANNOTATION, ['@override']); | 109 check(HighlightRegionType.ANNOTATION, ['@override']); |
| 106 check(HighlightRegionType.BUILT_IN, [ | 110 check(HighlightRegionType.BUILT_IN, |
| 107 'as', | 111 ['as', 'get', 'import', 'set', 'static', 'typedef']); |
| 108 'get', | 112 check(HighlightRegionType.CLASS, |
| 109 'import', | 113 ['Class', 'Class2', 'Future', 'Map', 'int']); |
| 110 'set', | |
| 111 'static', | |
| 112 'typedef' | |
| 113 ]); | |
| 114 check(HighlightRegionType.CLASS, [ | |
| 115 'Class', | |
| 116 'Class2', | |
| 117 'Future', | |
| 118 'Map', | |
| 119 'int' | |
| 120 ]); | |
| 121 check(HighlightRegionType.COMMENT_BLOCK, ['/* Block comment */']); | 114 check(HighlightRegionType.COMMENT_BLOCK, ['/* Block comment */']); |
| 122 check(HighlightRegionType.COMMENT_DOCUMENTATION, | 115 check(HighlightRegionType.COMMENT_DOCUMENTATION, |
| 123 ['/**\n * Doc comment\n */']); | 116 ['/**\n * Doc comment\n */']); |
| 124 check( | 117 check( |
| 125 HighlightRegionType.COMMENT_END_OF_LINE, ['// End of line comment']); | 118 HighlightRegionType.COMMENT_END_OF_LINE, ['// End of line comment']); |
| 126 check(HighlightRegionType.CONSTRUCTOR, ['constructor']); | 119 check(HighlightRegionType.CONSTRUCTOR, ['constructor']); |
| 127 check(HighlightRegionType.DIRECTIVE, ["import 'dart:async' as async;"]); | 120 check(HighlightRegionType.DIRECTIVE, ["import 'dart:async' as async;"]); |
| 128 check(HighlightRegionType.DYNAMIC_PARAMETER_DECLARATION, ['dynamicType']); | 121 check(HighlightRegionType.DYNAMIC_PARAMETER_DECLARATION, ['dynamicType']); |
| 129 check(HighlightRegionType.INSTANCE_FIELD_DECLARATION, ['field']); | 122 check(HighlightRegionType.INSTANCE_FIELD_DECLARATION, ['field']); |
| 130 check(HighlightRegionType.INSTANCE_SETTER_REFERENCE, ['field']); | 123 check(HighlightRegionType.INSTANCE_SETTER_REFERENCE, ['field']); |
| 131 check(HighlightRegionType.STATIC_FIELD_DECLARATION, ['staticField']); | 124 check(HighlightRegionType.STATIC_FIELD_DECLARATION, ['staticField']); |
| 132 check(HighlightRegionType.TOP_LEVEL_FUNCTION_REFERENCE, ['print']); | 125 check(HighlightRegionType.TOP_LEVEL_FUNCTION_REFERENCE, ['print']); |
| 133 check(HighlightRegionType.TOP_LEVEL_FUNCTION_DECLARATION, ['function']); | 126 check(HighlightRegionType.TOP_LEVEL_FUNCTION_DECLARATION, ['function']); |
| 134 check(HighlightRegionType.FUNCTION_TYPE_ALIAS, ['functionType']); | 127 check(HighlightRegionType.FUNCTION_TYPE_ALIAS, ['functionType']); |
| 135 check(HighlightRegionType.INSTANCE_GETTER_DECLARATION, ['getter']); | 128 check(HighlightRegionType.INSTANCE_GETTER_DECLARATION, ['getter']); |
| 136 check(HighlightRegionType.IDENTIFIER_DEFAULT, ['unresolvedIdentifier']); | 129 check(HighlightRegionType.IDENTIFIER_DEFAULT, ['unresolvedIdentifier']); |
| 137 check(HighlightRegionType.IMPORT_PREFIX, ['async']); | 130 check(HighlightRegionType.IMPORT_PREFIX, ['async']); |
| 138 check(HighlightRegionType.KEYWORD, ['class', 'true', 'return']); | 131 check(HighlightRegionType.KEYWORD, ['class', 'true', 'return']); |
| 139 check(HighlightRegionType.LITERAL_BOOLEAN, ['true']); | 132 check(HighlightRegionType.LITERAL_BOOLEAN, ['true']); |
| 140 check(HighlightRegionType.LITERAL_DOUBLE, ['1.0']); | 133 check(HighlightRegionType.LITERAL_DOUBLE, ['1.0']); |
| 141 check(HighlightRegionType.LITERAL_INTEGER, ['2', '42']); | 134 check(HighlightRegionType.LITERAL_INTEGER, ['2', '42']); |
| 142 check(HighlightRegionType.LITERAL_LIST, ['[]']); | 135 check(HighlightRegionType.LITERAL_LIST, ['[]']); |
| 143 check(HighlightRegionType.LITERAL_MAP, [ | 136 check(HighlightRegionType.LITERAL_MAP, |
| 144 '{1.0: [].toList()}', | 137 ['{1.0: [].toList()}', '{2: local}']); |
| 145 '{2: local}' | |
| 146 ]); | |
| 147 check(HighlightRegionType.LITERAL_STRING, ["'dart:async'", "'string'"]); | 138 check(HighlightRegionType.LITERAL_STRING, ["'dart:async'", "'string'"]); |
| 148 check(HighlightRegionType.LOCAL_VARIABLE_DECLARATION, ['local']); | 139 check(HighlightRegionType.LOCAL_VARIABLE_DECLARATION, ['local']); |
| 149 check(HighlightRegionType.LOCAL_VARIABLE_REFERENCE, ['local']); | 140 check(HighlightRegionType.LOCAL_VARIABLE_REFERENCE, ['local']); |
| 150 check(HighlightRegionType.INSTANCE_METHOD_REFERENCE, ['toList']); | 141 check(HighlightRegionType.INSTANCE_METHOD_REFERENCE, ['toList']); |
| 151 check(HighlightRegionType.INSTANCE_METHOD_DECLARATION, ['method']); | 142 check(HighlightRegionType.INSTANCE_METHOD_DECLARATION, ['method']); |
| 152 check(HighlightRegionType.STATIC_METHOD_DECLARATION, ['staticMethod']); | 143 check(HighlightRegionType.STATIC_METHOD_DECLARATION, ['staticMethod']); |
| 153 check(HighlightRegionType.STATIC_METHOD_REFERENCE, ['wait']); | 144 check(HighlightRegionType.STATIC_METHOD_REFERENCE, ['wait']); |
| 154 check(HighlightRegionType.PARAMETER_DECLARATION, ['parameter']); | 145 check(HighlightRegionType.PARAMETER_DECLARATION, ['parameter']); |
| 155 check(HighlightRegionType.PARAMETER_REFERENCE, ['parameter']); | 146 check(HighlightRegionType.PARAMETER_REFERENCE, ['parameter']); |
| 156 check(HighlightRegionType.INSTANCE_SETTER_DECLARATION, ['setter']); | 147 check(HighlightRegionType.INSTANCE_SETTER_DECLARATION, ['setter']); |
| 157 check(HighlightRegionType.TOP_LEVEL_GETTER_REFERENCE, ['override']); | 148 check(HighlightRegionType.TOP_LEVEL_GETTER_REFERENCE, ['override']); |
| 158 check(HighlightRegionType.TOP_LEVEL_VARIABLE_DECLARATION, | 149 check(HighlightRegionType.TOP_LEVEL_VARIABLE_DECLARATION, |
| 159 ['topLevelVariable']); | 150 ['topLevelVariable']); |
| 160 check(HighlightRegionType.TYPE_NAME_DYNAMIC, ['dynamic']); | 151 check(HighlightRegionType.TYPE_NAME_DYNAMIC, ['dynamic']); |
| 161 check(HighlightRegionType.TYPE_PARAMETER, ['TypeParameter']); | 152 check(HighlightRegionType.TYPE_PARAMETER, ['TypeParameter']); |
| 162 expect(highlights, isEmpty); | 153 expect(highlights, isEmpty); |
| 163 }); | 154 }); |
| 164 } | 155 } |
| 165 } | 156 } |
| OLD | NEW |