| 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.domain.analysis.notification.highlights; | 5 library test.domain.analysis.notification.highlights; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/computer/computer_highlights.dart'; | 10 import 'package:analysis_server/src/computer/computer_highlights.dart'; |
| 11 import 'package:analysis_server/src/constants.dart'; | 11 import 'package:analysis_server/src/constants.dart'; |
| 12 import 'package:analysis_server/src/protocol.dart'; | 12 import 'package:analysis_server/src/protocol.dart'; |
| 13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
| 14 | 14 |
| 15 import 'analysis_abstract.dart'; | 15 import 'analysis_abstract.dart'; |
| 16 import 'reflective_tests.dart'; | 16 import 'reflective_tests.dart'; |
| 17 | 17 |
| 18 | 18 |
| 19 main() { | 19 main() { |
| 20 group('notification.highlights', () { | 20 group('notification.highlights', () { |
| 21 runReflectiveTests(_AnalysisNotificationHighlightsTest); | 21 runReflectiveTests(_AnalysisNotificationHighlightsTest); |
| 22 }); | 22 }); |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 |
| 26 @ReflectiveTestCase() | 26 @ReflectiveTestCase() |
| 27 class _AnalysisNotificationHighlightsTest extends AbstractAnalysisTest { | 27 class _AnalysisNotificationHighlightsTest extends AbstractAnalysisTest { |
| 28 List<_HighlighRegion> regions; | 28 List<_HighlightRegion> regions; |
| 29 | 29 |
| 30 void assertHasRawRegion(HighlightType type, int offset, int length) { | 30 void assertHasRawRegion(HighlightType type, int offset, int length) { |
| 31 for (_HighlighRegion region in regions) { | 31 for (_HighlightRegion region in regions) { |
| 32 if (region.offset == offset && region.length == length && region.type == | 32 if (region.offset == offset && region.length == length && region.type == |
| 33 type.name) { | 33 type.name) { |
| 34 return; | 34 return; |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 fail('Expected to find (offset=$offset; length=$length; type=$type) in\n' | 37 fail('Expected to find (offset=$offset; length=$length; type=$type) in\n' |
| 38 '${regions.join('\n')}'); | 38 '${regions.join('\n')}'); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void assertHasRegion(HighlightType type, String search, [int length = -1]) { | 41 void assertHasRegion(HighlightType type, String search, [int length = -1]) { |
| 42 int offset = findOffset(search); | 42 int offset = findOffset(search); |
| 43 length = findRegionLength(search, length); | 43 length = findRegionLength(search, length); |
| 44 assertHasRawRegion(type, offset, length); | 44 assertHasRawRegion(type, offset, length); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void assertNoRawRegion(HighlightType type, int offset, int length) { | 47 void assertNoRawRegion(HighlightType type, int offset, int length) { |
| 48 for (_HighlighRegion region in regions) { | 48 for (_HighlightRegion region in regions) { |
| 49 if (region.offset == offset && region.length == length && region.type == | 49 if (region.offset == offset && region.length == length && region.type == |
| 50 type.name) { | 50 type.name) { |
| 51 fail( | 51 fail( |
| 52 'Not expected to find (offset=$offset; length=$length; type=$type) i
n\n' | 52 'Not expected to find (offset=$offset; length=$length; type=$type) i
n\n' |
| 53 '${regions.join('\n')}'); | 53 '${regions.join('\n')}'); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 | 58 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 | 91 |
| 92 void processNotification(Notification notification) { | 92 void processNotification(Notification notification) { |
| 93 if (notification.event == ANALYSIS_HIGHLIGHTS) { | 93 if (notification.event == ANALYSIS_HIGHLIGHTS) { |
| 94 String file = notification.getParameter(FILE); | 94 String file = notification.getParameter(FILE); |
| 95 if (file == testFile) { | 95 if (file == testFile) { |
| 96 regions = []; | 96 regions = []; |
| 97 List<Map<String, Object>> regionsJson = notification.getParameter( | 97 List<Map<String, Object>> regionsJson = notification.getParameter( |
| 98 REGIONS); | 98 REGIONS); |
| 99 for (Map<String, Object> regionJson in regionsJson) { | 99 for (Map<String, Object> regionJson in regionsJson) { |
| 100 regions.add(new _HighlighRegion.fromJson(regionJson)); | 100 regions.add(new _HighlightRegion.fromJson(regionJson)); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 @override | 106 @override |
| 107 void setUp() { | 107 void setUp() { |
| 108 super.setUp(); | 108 super.setUp(); |
| 109 createProject(); | 109 createProject(); |
| 110 } | 110 } |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 return prepareHighlights(() { | 749 return prepareHighlights(() { |
| 750 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T> {'); | 750 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T> {'); |
| 751 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T fff;'); | 751 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T fff;'); |
| 752 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T mmm('); | 752 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T mmm('); |
| 753 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T p)'); | 753 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T p)'); |
| 754 }); | 754 }); |
| 755 } | 755 } |
| 756 } | 756 } |
| 757 | 757 |
| 758 | 758 |
| 759 class _HighlighRegion { | 759 class _HighlightRegion { |
| 760 final int length; | 760 final int length; |
| 761 final int offset; | 761 final int offset; |
| 762 final String type; | 762 final String type; |
| 763 | 763 |
| 764 _HighlighRegion(this.type, this.offset, this.length); | 764 _HighlightRegion(this.type, this.offset, this.length); |
| 765 | 765 |
| 766 factory _HighlighRegion.fromJson(Map<String, Object> map) { | 766 factory _HighlightRegion.fromJson(Map<String, Object> map) { |
| 767 return new _HighlighRegion(map[TYPE], map[OFFSET], map[LENGTH]); | 767 return new _HighlightRegion(map[TYPE], map[OFFSET], map[LENGTH]); |
| 768 } | 768 } |
| 769 } | 769 } |
| OLD | NEW |