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

Side by Side Diff: pkg/analysis_server/test/analysis_notification_highlights_test.dart

Issue 454843004: Fixes for the missing highlights. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove unused function Created 6 years, 4 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
« no previous file with comments | « pkg/analysis_server/test/analysis_abstract.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.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';
(...skipping 28 matching lines...) Expand all
39 'Expected to find (offset=$offset; length=$length; type=$type) in\n' 39 'Expected to find (offset=$offset; length=$length; type=$type) in\n'
40 '${regions.join('\n')}'); 40 '${regions.join('\n')}');
41 } 41 }
42 42
43 void assertHasRegion(HighlightType type, String search, [int length = -1]) { 43 void assertHasRegion(HighlightType type, String search, [int length = -1]) {
44 int offset = findOffset(search); 44 int offset = findOffset(search);
45 length = findRegionLength(search, length); 45 length = findRegionLength(search, length);
46 assertHasRawRegion(type, offset, length); 46 assertHasRawRegion(type, offset, length);
47 } 47 }
48 48
49 void assertHasStringRegion(HighlightType type, String str) {
50 int offset = findOffset(str);
51 int length = str.length;
52 assertHasRawRegion(type, offset, length);
53 }
54
49 void assertNoRawRegion(HighlightType type, int offset, int length) { 55 void assertNoRawRegion(HighlightType type, int offset, int length) {
50 for (HighlightRegion region in regions) { 56 for (HighlightRegion region in regions) {
51 if (region.offset == offset && 57 if (region.offset == offset &&
52 region.length == length && 58 region.length == length &&
53 region.type == type) { 59 region.type == type) {
54 fail( 60 fail(
55 'Not expected to find (offset=$offset; length=$length; type=$type) i n\n' 61 'Not expected to find (offset=$offset; length=$length; type=$type) i n\n'
56 '${regions.join('\n')}'); 62 '${regions.join('\n')}');
57 } 63 }
58 } 64 }
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 }); 342 });
337 } 343 }
338 344
339 test_BUILT_IN_partOf() { 345 test_BUILT_IN_partOf() {
340 addTestFile(''' 346 addTestFile('''
341 part of lib; 347 part of lib;
342 main() { 348 main() {
343 var part = 1; 349 var part = 1;
344 var of = 2; 350 var of = 2;
345 }'''); 351 }''');
346 addFile('/project/bin/my_lib.dart', ''' 352 _addLibraryForTestPart();
347 library lib;
348 part 'test.dart';
349 ''');
350 return prepareHighlights().then((_) { 353 return prepareHighlights().then((_) {
351 assertHasRegion(HighlightType.BUILT_IN, 'part of', 'part of'.length); 354 assertHasRegion(HighlightType.BUILT_IN, 'part of', 'part of'.length);
352 assertNoRegion(HighlightType.BUILT_IN, 'part = 1'); 355 assertNoRegion(HighlightType.BUILT_IN, 'part = 1');
353 assertNoRegion(HighlightType.BUILT_IN, 'of = 2'); 356 assertNoRegion(HighlightType.BUILT_IN, 'of = 2');
354 }); 357 });
355 } 358 }
356 359
357 test_BUILT_IN_set() { 360 test_BUILT_IN_set() {
358 addTestFile(''' 361 addTestFile('''
359 set aaa(x) {} 362 set aaa(x) {}
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 } 475 }
473 '''); 476 ''');
474 return prepareHighlights().then((_) { 477 return prepareHighlights().then((_) {
475 assertHasRegion(HighlightType.CONSTRUCTOR, 'name(p)'); 478 assertHasRegion(HighlightType.CONSTRUCTOR, 'name(p)');
476 assertHasRegion(HighlightType.CONSTRUCTOR, 'name(42)'); 479 assertHasRegion(HighlightType.CONSTRUCTOR, 'name(42)');
477 assertNoRegion(HighlightType.CONSTRUCTOR, 'AAA() {}'); 480 assertNoRegion(HighlightType.CONSTRUCTOR, 'AAA() {}');
478 assertNoRegion(HighlightType.CONSTRUCTOR, 'AAA();'); 481 assertNoRegion(HighlightType.CONSTRUCTOR, 'AAA();');
479 }); 482 });
480 } 483 }
481 484
485 test_DIRECTIVE() {
486 addTestFile('''
487 library lib;
488 import 'dart:math';
489 export 'dart:math';
490 part 'part.dart';
491 ''');
492 return prepareHighlights().then((_) {
493 assertHasStringRegion(HighlightType.DIRECTIVE, "library lib;");
494 assertHasStringRegion(HighlightType.DIRECTIVE, "import 'dart:math';");
495 assertHasStringRegion(HighlightType.DIRECTIVE, "export 'dart:math';");
496 assertHasStringRegion(HighlightType.DIRECTIVE, "part 'part.dart';");
497 });
498 }
499
500 test_DIRECTIVE_partOf() {
501 addTestFile('''
502 part of lib;
503 ''');
504 _addLibraryForTestPart();
505 return prepareHighlights().then((_) {
506 assertHasStringRegion(HighlightType.DIRECTIVE, "part of lib;");
507 });
508 }
509
482 test_DYNAMIC_TYPE() { 510 test_DYNAMIC_TYPE() {
483 addTestFile(''' 511 addTestFile('''
484 f() {} 512 f() {}
485 main(p) { 513 main(p) {
486 print(p); 514 print(p);
487 var v1 = f(); 515 var v1 = f();
488 int v2; 516 int v2;
489 var v3 = v2; 517 var v3 = v2;
490 } 518 }
491 '''); 519 ''');
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 get bbb => null; 599 get bbb => null;
572 } 600 }
573 main(A a) { 601 main(A a) {
574 aaa; 602 aaa;
575 a.bbb; 603 a.bbb;
576 } 604 }
577 '''); 605 ''');
578 return prepareHighlights().then((_) { 606 return prepareHighlights().then((_) {
579 assertHasRegion(HighlightType.GETTER_DECLARATION, 'aaa => null'); 607 assertHasRegion(HighlightType.GETTER_DECLARATION, 'aaa => null');
580 assertHasRegion(HighlightType.GETTER_DECLARATION, 'bbb => null'); 608 assertHasRegion(HighlightType.GETTER_DECLARATION, 'bbb => null');
581 assertHasRegion(HighlightType.FIELD_STATIC, 'aaa;'); 609 assertHasRegion(HighlightType.TOP_LEVEL_VARIABLE, 'aaa;');
582 assertHasRegion(HighlightType.FIELD, 'bbb;'); 610 assertHasRegion(HighlightType.FIELD, 'bbb;');
583 }); 611 });
584 } 612 }
585 613
586 test_IDENTIFIER_DEFAULT() { 614 test_IDENTIFIER_DEFAULT() {
587 addTestFile(''' 615 addTestFile('''
588 main() { 616 main() {
589 aaa = 42; 617 aaa = 42;
590 bbb(84); 618 bbb(84);
591 CCC ccc; 619 CCC ccc;
(...skipping 12 matching lines...) Expand all
604 main() { 632 main() {
605 ma.max(1, 2); 633 ma.max(1, 2);
606 } 634 }
607 '''); 635 ''');
608 return prepareHighlights().then((_) { 636 return prepareHighlights().then((_) {
609 assertHasRegion(HighlightType.IMPORT_PREFIX, 'ma;'); 637 assertHasRegion(HighlightType.IMPORT_PREFIX, 'ma;');
610 assertHasRegion(HighlightType.IMPORT_PREFIX, 'ma.max'); 638 assertHasRegion(HighlightType.IMPORT_PREFIX, 'ma.max');
611 }); 639 });
612 } 640 }
613 641
642 test_KEYWORD() {
643 addTestFile('''
644 main() {
645 assert(true);
646 for (;;) break;
647 switch (0) {
648 case 0: break;
649 default: break;
650 }
651 try {} catch (e) {}
652 const v1 = 0;
653 for (;;) continue;
654 do {} while (true);
655 if (true) {} else {}
656 var v2 = false;
657 final v3 = 1;
658 try {} finally {}
659 for (var v4 in []) {}
660 v3 is int;
661 new A();
662 try {} catch (e) {rethrow;}
663 var v5 = true;
664 while (true) {}
665 }
666 class A {}
667 class B extends A {
668 B() : super();
669 m() {
670 return this;
671 }
672 }
673 class C = Object with A;
674 ''');
675 return prepareHighlights().then((_) {
676 assertHasRegion(HighlightType.KEYWORD, 'assert(true)');
677 assertHasRegion(HighlightType.KEYWORD, 'for (;;)');
678 assertHasRegion(HighlightType.KEYWORD, 'for (var v4 in');
679 assertHasRegion(HighlightType.KEYWORD, 'break;');
680 assertHasRegion(HighlightType.KEYWORD, 'case 0:');
681 assertHasRegion(HighlightType.KEYWORD, 'catch (e) {}');
682 assertHasRegion(HighlightType.KEYWORD, 'class A {}');
683 assertHasRegion(HighlightType.KEYWORD, 'const v1');
684 assertHasRegion(HighlightType.KEYWORD, 'continue;');
685 assertHasRegion(HighlightType.KEYWORD, 'default:');
686 assertHasRegion(HighlightType.KEYWORD, 'do {} while');
687 assertHasRegion(HighlightType.KEYWORD, 'if (true)');
688 assertHasRegion(HighlightType.KEYWORD, 'false;');
689 assertHasRegion(HighlightType.KEYWORD, 'final v3 =');
690 assertHasRegion(HighlightType.KEYWORD, 'finally {}');
691 assertHasRegion(HighlightType.KEYWORD, 'in []');
692 assertHasRegion(HighlightType.KEYWORD, 'is int');
693 assertHasRegion(HighlightType.KEYWORD, 'new A();');
694 assertHasRegion(HighlightType.KEYWORD, 'rethrow;');
695 assertHasRegion(HighlightType.KEYWORD, 'return this');
696 assertHasRegion(HighlightType.KEYWORD, 'super();');
697 assertHasRegion(HighlightType.KEYWORD, 'switch (0)');
698 assertHasRegion(HighlightType.KEYWORD, 'this;');
699 assertHasRegion(HighlightType.KEYWORD, 'true;');
700 assertHasRegion(HighlightType.KEYWORD, 'try {');
701 assertHasRegion(HighlightType.KEYWORD, 'while (true) {}');
702 assertHasRegion(HighlightType.KEYWORD, 'while (true);');
703 assertHasRegion(HighlightType.KEYWORD, 'with A;');
704 });
705 }
706
614 test_KEYWORD_void() { 707 test_KEYWORD_void() {
615 addTestFile(''' 708 addTestFile('''
616 void main() { 709 void main() {
617 } 710 }
618 '''); 711 ''');
619 return prepareHighlights().then((_) { 712 return prepareHighlights().then((_) {
620 assertHasRegion(HighlightType.KEYWORD, 'void main()'); 713 assertHasRegion(HighlightType.KEYWORD, 'void main()');
621 }); 714 });
622 } 715 }
623 716
(...skipping 11 matching lines...) Expand all
635 }); 728 });
636 } 729 }
637 730
638 test_LITERAL_INTEGER() { 731 test_LITERAL_INTEGER() {
639 addTestFile('var V = 42;'); 732 addTestFile('var V = 42;');
640 return prepareHighlights().then((_) { 733 return prepareHighlights().then((_) {
641 assertHasRegion(HighlightType.LITERAL_INTEGER, '42;'); 734 assertHasRegion(HighlightType.LITERAL_INTEGER, '42;');
642 }); 735 });
643 } 736 }
644 737
738 test_LITERAL_LIST() {
739 addTestFile('var V = <int>[1, 2, 3];');
740 return prepareHighlights().then((_) {
741 assertHasStringRegion(HighlightType.LITERAL_LIST, '<int>[1, 2, 3]');
742 });
743 }
744
745 test_LITERAL_MAP() {
746 addTestFile("var V = const <int, String>{1: 'a', 2: 'b', 3: 'c'};");
747 return prepareHighlights().then((_) {
748 assertHasStringRegion(
749 HighlightType.LITERAL_MAP,
750 "const <int, String>{1: 'a', 2: 'b', 3: 'c'}");
751 });
752 }
753
645 test_LITERAL_STRING() { 754 test_LITERAL_STRING() {
646 addTestFile('var V = "abc";'); 755 addTestFile('var V = "abc";');
647 return prepareHighlights().then((_) { 756 return prepareHighlights().then((_) {
648 assertHasRegion(HighlightType.LITERAL_STRING, '"abc";', '"abc"'.length); 757 assertHasRegion(HighlightType.LITERAL_STRING, '"abc";', '"abc"'.length);
649 }); 758 });
650 } 759 }
651 760
652 test_LOCAL_VARIABLE() { 761 test_LOCAL_VARIABLE() {
653 addTestFile(''' 762 addTestFile('''
654 main() { 763 main() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 set bbb(x) {} 830 set bbb(x) {}
722 } 831 }
723 main(A a) { 832 main(A a) {
724 aaa = 1; 833 aaa = 1;
725 a.bbb = 2; 834 a.bbb = 2;
726 } 835 }
727 '''); 836 ''');
728 return prepareHighlights().then((_) { 837 return prepareHighlights().then((_) {
729 assertHasRegion(HighlightType.SETTER_DECLARATION, 'aaa(x)'); 838 assertHasRegion(HighlightType.SETTER_DECLARATION, 'aaa(x)');
730 assertHasRegion(HighlightType.SETTER_DECLARATION, 'bbb(x)'); 839 assertHasRegion(HighlightType.SETTER_DECLARATION, 'bbb(x)');
731 assertHasRegion(HighlightType.FIELD_STATIC, 'aaa = 1'); 840 assertHasRegion(HighlightType.TOP_LEVEL_VARIABLE, 'aaa = 1');
732 assertHasRegion(HighlightType.FIELD, 'bbb = 2'); 841 assertHasRegion(HighlightType.FIELD, 'bbb = 2');
733 }); 842 });
734 } 843 }
735 844
736 test_TOP_LEVEL_VARIABLE() { 845 test_TOP_LEVEL_VARIABLE() {
737 addTestFile(''' 846 addTestFile('''
738 var VVV = 0; 847 const VVV = 0;
848 @VVV // annotation
739 main() { 849 main() {
740 print(VVV); 850 print(VVV);
741 VVV = 1; 851 VVV = 1;
742 } 852 }
743 '''); 853 ''');
744 return prepareHighlights().then((_) { 854 return prepareHighlights().then((_) {
745 assertHasRegion(HighlightType.TOP_LEVEL_VARIABLE, 'VVV = 0'); 855 assertHasRegion(HighlightType.TOP_LEVEL_VARIABLE, 'VVV = 0');
746 assertHasRegion(HighlightType.FIELD_STATIC, 'VVV);'); 856 assertHasRegion(HighlightType.TOP_LEVEL_VARIABLE, 'VVV // annotation');
747 assertHasRegion(HighlightType.FIELD_STATIC, 'VVV = 1'); 857 assertHasRegion(HighlightType.TOP_LEVEL_VARIABLE, 'VVV);');
858 assertHasRegion(HighlightType.TOP_LEVEL_VARIABLE, 'VVV = 1');
748 }); 859 });
749 } 860 }
750 861
751 test_TYPE_NAME_DYNAMIC() { 862 test_TYPE_NAME_DYNAMIC() {
752 addTestFile(''' 863 addTestFile('''
753 dynamic main() { 864 dynamic main() {
754 dynamic = 42; 865 dynamic = 42;
755 } 866 }
756 '''); 867 ''');
757 return prepareHighlights().then((_) { 868 return prepareHighlights().then((_) {
(...skipping 10 matching lines...) Expand all
768 T mmm(T p) => null; 879 T mmm(T p) => null;
769 } 880 }
770 '''); 881 ''');
771 return prepareHighlights().then((_) { 882 return prepareHighlights().then((_) {
772 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T> {'); 883 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T> {');
773 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T fff;'); 884 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T fff;');
774 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T mmm('); 885 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T mmm(');
775 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T p)'); 886 assertHasRegion(HighlightType.TYPE_PARAMETER, 'T p)');
776 }); 887 });
777 } 888 }
889
890 void _addLibraryForTestPart() {
891 addFile('$testFolder/my_lib.dart', '''
892 library lib;
893 part 'test.dart';
894 ''');
895 }
778 } 896 }
779 897
780 898
781 @ReflectiveTestCase() 899 @ReflectiveTestCase()
782 class HighlightTypeTest { 900 class HighlightTypeTest {
783 void test_toString() { 901 void test_toString() {
784 expect(HighlightType.CLASS.toString(), HighlightType.CLASS.name); 902 expect(HighlightType.CLASS.toString(), HighlightType.CLASS.name);
785 } 903 }
786 904
787 void test_valueOf() { 905 void test_valueOf() {
788 expect( 906 expect(
789 HighlightType.CLASS, 907 HighlightType.CLASS,
790 HighlightType.valueOf(HighlightType.CLASS.name)); 908 HighlightType.valueOf(HighlightType.CLASS.name));
791 } 909 }
792 910
793 void test_valueOf_unknown() { 911 void test_valueOf_unknown() {
794 expect(() { 912 expect(() {
795 HighlightType.valueOf('no-such-type'); 913 HighlightType.valueOf('no-such-type');
796 }, throws); 914 }, throws);
797 } 915 }
798 } 916 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/test/analysis_abstract.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698