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 }); |
| 23 group('HighlightType', () { |
| 24 runReflectiveTests(HighlightTypeTest); |
22 }); | 25 }); |
23 } | 26 } |
24 | 27 |
25 | 28 |
26 @ReflectiveTestCase() | 29 @ReflectiveTestCase() |
27 class _AnalysisNotificationHighlightsTest extends AbstractAnalysisTest { | 30 class AnalysisNotificationHighlightsTest extends AbstractAnalysisTest { |
28 List<_HighlightRegion> regions; | 31 List<HighlightRegion> regions; |
29 | 32 |
30 void assertHasRawRegion(HighlightType type, int offset, int length) { | 33 void assertHasRawRegion(HighlightType type, int offset, int length) { |
31 for (_HighlightRegion region in regions) { | 34 for (HighlightRegion region in regions) { |
32 if (region.offset == offset && region.length == length && region.type == | 35 if (region.offset == offset && region.length == length && region.type == |
33 type.name) { | 36 type) { |
34 return; | 37 return; |
35 } | 38 } |
36 } | 39 } |
37 StringBuffer buffer = new StringBuffer(); | 40 fail('Expected to find (offset=$offset; length=$length; type=$type) in\n' |
38 buffer.write('Expected to find (type='); | 41 '${regions.join('\n')}'); |
39 buffer.write(type.name); | |
40 buffer.write('; offset='); | |
41 buffer.write(offset); | |
42 buffer.write('; length='); | |
43 buffer.write(length); | |
44 buffer.write(') in\n'); | |
45 for (_HighlightRegion region in regions) { | |
46 buffer.write(' (type='); | |
47 buffer.write(region.type); | |
48 buffer.write('; offset='); | |
49 buffer.write(region.offset); | |
50 buffer.write('; length='); | |
51 buffer.write(region.length); | |
52 buffer.write(') in\n'); | |
53 } | |
54 fail(buffer.toString()); | |
55 } | 42 } |
56 | 43 |
57 void assertHasRegion(HighlightType type, String search, [int length = -1]) { | 44 void assertHasRegion(HighlightType type, String search, [int length = -1]) { |
58 int offset = findOffset(search); | 45 int offset = findOffset(search); |
59 length = findRegionLength(search, length); | 46 length = findRegionLength(search, length); |
60 assertHasRawRegion(type, offset, length); | 47 assertHasRawRegion(type, offset, length); |
61 } | 48 } |
62 | 49 |
63 void assertNoRawRegion(HighlightType type, int offset, int length) { | 50 void assertNoRawRegion(HighlightType type, int offset, int length) { |
64 for (_HighlightRegion region in regions) { | 51 for (HighlightRegion region in regions) { |
65 if (region.offset == offset && region.length == length && region.type == | 52 if (region.offset == offset && region.length == length && region.type == |
66 type.name) { | 53 type) { |
67 fail( | 54 fail( |
68 'Not expected to find (offset=$offset; length=$length; type=$type) i
n\n' | 55 'Not expected to find (offset=$offset; length=$length; type=$type) i
n\n' |
69 '${regions.join('\n')}'); | 56 '${regions.join('\n')}'); |
70 } | 57 } |
71 } | 58 } |
72 } | 59 } |
73 | 60 |
74 | 61 |
75 void assertNoRegion(HighlightType type, String search, [int length = -1]) { | 62 void assertNoRegion(HighlightType type, String search, [int length = -1]) { |
76 int offset = findOffset(search); | 63 int offset = findOffset(search); |
(...skipping 29 matching lines...) Expand all Loading... |
106 } | 93 } |
107 | 94 |
108 void processNotification(Notification notification) { | 95 void processNotification(Notification notification) { |
109 if (notification.event == ANALYSIS_HIGHLIGHTS) { | 96 if (notification.event == ANALYSIS_HIGHLIGHTS) { |
110 String file = notification.getParameter(FILE); | 97 String file = notification.getParameter(FILE); |
111 if (file == testFile) { | 98 if (file == testFile) { |
112 regions = []; | 99 regions = []; |
113 List<Map<String, Object>> regionsJson = notification.getParameter( | 100 List<Map<String, Object>> regionsJson = notification.getParameter( |
114 REGIONS); | 101 REGIONS); |
115 for (Map<String, Object> regionJson in regionsJson) { | 102 for (Map<String, Object> regionJson in regionsJson) { |
116 regions.add(new _HighlightRegion.fromJson(regionJson)); | 103 regions.add(new HighlightRegion.fromJson(regionJson)); |
117 } | 104 } |
118 } | 105 } |
119 } | 106 } |
120 } | 107 } |
121 | 108 |
122 @override | 109 @override |
123 void setUp() { | 110 void setUp() { |
124 super.setUp(); | 111 super.setUp(); |
125 createProject(); | 112 createProject(); |
126 } | 113 } |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 void main() { | 449 void main() { |
463 // end-of-line comment | 450 // end-of-line comment |
464 my_function(1); | 451 my_function(1); |
465 } | 452 } |
466 | 453 |
467 void my_function(String a) { | 454 void my_function(String a) { |
468 /* block comment */ | 455 /* block comment */ |
469 } | 456 } |
470 '''); | 457 '''); |
471 return prepareHighlights(() { | 458 return prepareHighlights(() { |
472 // TODO(brianwilkerson) Make this test pass. | 459 assertHasRegion(HighlightType.COMMENT_DOCUMENTATION, '/**', 32); |
473 // assertHasRegion(HighlightType.COMMENT_END_OF_LINE, '//', 22); | 460 assertHasRegion(HighlightType.COMMENT_END_OF_LINE, '//', 22); |
474 // assertHasRegion(HighlightType.COMMENT_BLOCK, '/* b', 19); | 461 assertHasRegion(HighlightType.COMMENT_BLOCK, '/* b', 19); |
475 // assertHasRegion(HighlightType.COMMENT_DOCUMENTATION, '/**', 32); | |
476 }); | 462 }); |
477 } | 463 } |
478 | 464 |
479 test_CONSTRUCTOR() { | 465 test_CONSTRUCTOR() { |
480 addTestFile(''' | 466 addTestFile(''' |
481 class AAA { | 467 class AAA { |
482 AAA() {} | 468 AAA() {} |
483 AAA.name(p) {} | 469 AAA.name(p) {} |
484 } | 470 } |
485 main() { | 471 main() { |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 return prepareHighlights(() { | 773 return prepareHighlights(() { |
788 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T> {'); | 774 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T> {'); |
789 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T fff;'); | 775 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T fff;'); |
790 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T mmm('); | 776 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T mmm('); |
791 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T p)'); | 777 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T p)'); |
792 }); | 778 }); |
793 } | 779 } |
794 } | 780 } |
795 | 781 |
796 | 782 |
797 class _HighlightRegion { | 783 @ReflectiveTestCase() |
798 final int length; | 784 class HighlightTypeTest { |
799 final int offset; | 785 void test_toString() { |
800 final String type; | 786 expect(HighlightType.CLASS.toString(), HighlightType.CLASS.name); |
| 787 } |
801 | 788 |
802 _HighlightRegion(this.type, this.offset, this.length); | 789 void test_valueOf() { |
| 790 expect(HighlightType.CLASS, HighlightType.valueOf( |
| 791 HighlightType.CLASS.name)); |
| 792 } |
803 | 793 |
804 factory _HighlightRegion.fromJson(Map<String, Object> map) { | 794 void test_valueOf_unknown() { |
805 return new _HighlightRegion(map[TYPE], map[OFFSET], map[LENGTH]); | 795 expect(() { |
| 796 HighlightType.valueOf('no-such-type'); |
| 797 }, throws); |
806 } | 798 } |
807 } | 799 } |
OLD | NEW |