Chromium Code Reviews| Index: pkg/analysis_server/test/integration/analysis/highlights_test.dart |
| diff --git a/pkg/analysis_server/test/integration/analysis/highlights_test.dart b/pkg/analysis_server/test/integration/analysis/highlights_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2a0108a0cc879ba6ee3c8421e0662f8cf35a0ae1 |
| --- /dev/null |
| +++ b/pkg/analysis_server/test/integration/analysis/highlights_test.dart |
| @@ -0,0 +1,134 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library test.integration.analysis.highlights; |
| + |
| +import 'package:analysis_testing/reflective_tests.dart'; |
| +import 'package:unittest/unittest.dart'; |
| + |
| +import '../integration_tests.dart'; |
| + |
| +@ReflectiveTestCase() |
| +class AnalysisHighlightsTest extends AbstractAnalysisServerIntegrationTest { |
| + test_highlights() { |
| + String pathname = sourcePath('test.dart'); |
| + String text = |
| + r''' |
| +import 'dart:async' as async; |
| + |
| +/** |
| + * Doc comment |
| + */ |
| +class Class<TypeParameter> { |
| + Class() { |
| + field = {1.0: [].toList()}; |
| + } |
| + |
| + Class.constructor() { |
| + dynamic local = true; |
| + field = {2: local}; |
| + } |
| + |
| + Map field; |
| + static int staticField; |
| + |
| + method() { |
| + // End of line comment |
| + /* Block comment */ |
| + } |
| + |
| + static staticMethod() { |
| + } |
| + |
| + get getter { |
| + } |
| + |
| + set setter(int parameter) { |
| + } |
| +} |
| + |
| +class Class2<TypeParameter> extends Class<TypeParameter> { |
| + @override |
| + method() { |
| + } |
| +} |
| + |
| +typedef functionType(); |
| + |
| +function(dynamicType) { |
| + print('string'); |
| + return async.Future.wait([]); |
| +} |
| + |
| +int topLevelVariable; |
| +'''; |
| + writeFile(pathname, text); |
| + standardAnalysisSetup(); |
| + sendAnalysisSetSubscriptions({'HIGHLIGHTS': [pathname]}); |
| + // Map from highlight type to highlighted text |
| + Map<String, Set<String>> highlights; |
| + onAnalysisHighlights.listen((params) { |
| + expect(params['file'], equals(pathname)); |
| + highlights = <String, Set<String>>{}; |
| + for (var region in params['regions']) { |
| + int startIndex = region['offset']; |
| + int endIndex = startIndex + region['length']; |
| + String highlightedText = text.substring(startIndex, endIndex); |
| + String type = region['type']; |
| + if (!highlights.containsKey(type)) { |
| + highlights[type] = new Set<String>(); |
| + } |
| + highlights[type].add(highlightedText); |
| + } |
| + }); |
| + return analysisFinished.then((_) { |
| + expect(currentAnalysisErrors[pathname], hasLength(0)); |
| + void check(String type, List<String> expected) { |
| + expect(highlights[type], equals(expected.toSet())); |
| + highlights.remove(type); |
| + } |
| + check('ANNOTATION', ['@override']); |
| + check('BUILT_IN', ['as', 'get', 'import', 'set', 'static', 'typedef']); |
| + check('CLASS', ['Class', 'Class2', 'Future', 'Map', 'int']); |
| + check('COMMENT_BLOCK', ['/* Block comment */']); |
| + check('COMMENT_DOCUMENTATION', ['/**\n * Doc comment\n */']); |
| + check('COMMENT_END_OF_LINE', ['// End of line comment']); |
| + check('CONSTRUCTOR', ['constructor']); |
| + // TODO(paulberry): When is the 'DIRECTIVE' type used? |
|
scheglov
2014/08/12 02:28:46
It's a bug in the highlights computer.
|
| + check('DYNAMIC_TYPE', ['dynamicType']); |
| + check('FIELD', ['field']); |
| + // TODO(paulberry): Why is "override" annotated as FIELD_STATIC? |
|
scheglov
2014/08/12 02:28:46
It's a bug in the highlights computer.
|
| + check('FIELD_STATIC', ['override', 'staticField']); |
| + check('FUNCTION', ['print']); |
| + check('FUNCTION_DECLARATION', ['function']); |
| + check('FUNCTION_TYPE_ALIAS', ['functionType']); |
| + check('GETTER_DECLARATION', ['getter']); |
| + // TODO(paulberry): When is the 'IDENTIFIER_DEFAULT' type used? |
|
scheglov
2014/08/12 02:28:47
For unresolved identifiers: aaa, bbb, CCC.
main()
|
| + check('IMPORT_PREFIX', ['async']); |
| + // TODO(paulberry): When is the 'KEYWORD' type used? |
|
scheglov
2014/08/12 02:28:46
It's a bug in the highlights computer.
|
| + check('LITERAL_BOOLEAN', ['true']); |
| + check('LITERAL_DOUBLE', ['1.0']); |
| + check('LITERAL_INTEGER', ['2']); |
| + // TODO(paulberry): When is the 'LITERAL_LIST' type used? |
| + // TODO(paulberry): When is the 'LITERAL_MAP' type used? |
|
scheglov
2014/08/12 02:28:46
These are bugs in the highlights computer.
|
| + check('LITERAL_STRING', ["'dart:async'", "'string'"]); |
| + check('LOCAL_VARIABLE', ['local']); |
| + check('LOCAL_VARIABLE_DECLARATION', ['local']); |
| + check('METHOD', ['toList']); |
| + check('METHOD_DECLARATION', ['method']); |
| + check('METHOD_DECLARATION_STATIC', ['staticMethod']); |
| + check('METHOD_STATIC', ['wait']); |
| + check('PARAMETER', ['parameter']); |
| + check('SETTER_DECLARATION', ['setter']); |
| + check('TOP_LEVEL_VARIABLE', ['topLevelVariable']); |
| + check('TYPE_NAME_DYNAMIC', ['dynamic']); |
| + check('TYPE_PARAMETER', ['TypeParameter']); |
| + expect(highlights, isEmpty); |
| + }); |
| + } |
| +} |
| + |
| +main() { |
| + runReflectiveTests(AnalysisHighlightsTest); |
| +} |