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

Side by Side Diff: pkg/analysis_server/test/analysis/notification_highlights_test.dart

Issue 1227143003: Update Analysis Server highlight API and implementation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Split DYNAMIC_VARIABLE, add UNRESOLVED_INSTANCE_MEMBER_REFERENCE. Created 5 years, 5 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
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.analysis.notification.highlights; 5 library test.analysis.notification.highlights;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/constants.dart'; 9 import 'package:analysis_server/src/constants.dart';
10 import 'package:analysis_server/src/protocol.dart'; 10 import 'package:analysis_server/src/protocol.dart';
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 test_DIRECTIVE_partOf() { 562 test_DIRECTIVE_partOf() {
563 addTestFile(''' 563 addTestFile('''
564 part of lib; 564 part of lib;
565 '''); 565 ''');
566 _addLibraryForTestPart(); 566 _addLibraryForTestPart();
567 return prepareHighlights().then((_) { 567 return prepareHighlights().then((_) {
568 assertHasStringRegion(HighlightRegionType.DIRECTIVE, "part of lib;"); 568 assertHasStringRegion(HighlightRegionType.DIRECTIVE, "part of lib;");
569 }); 569 });
570 } 570 }
571 571
572 test_DYNAMIC_TYPE() { 572 test_DYNAMIC_LOCAL_VARIABLE() {
573 addTestFile(''' 573 addTestFile('''
574 f() {} 574 f() {}
575 main(p) { 575 main(p) {
576 print(p); 576 var v = f();
577 var v1 = f(); 577 v;
578 int v2;
579 var v3 = v2;
580 } 578 }
581 '''); 579 ''');
582 return prepareHighlights().then((_) { 580 return prepareHighlights().then((_) {
583 assertHasRegion(HighlightRegionType.DYNAMIC_TYPE, 'p)'); 581 assertHasRegion(
584 assertHasRegion(HighlightRegionType.DYNAMIC_TYPE, 'v1 ='); 582 HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_DECLARATION, 'v = f()');
585 assertNoRegion(HighlightRegionType.DYNAMIC_TYPE, 'v2;'); 583 assertHasRegion(
586 assertNoRegion(HighlightRegionType.DYNAMIC_TYPE, 'v3 ='); 584 HighlightRegionType.DYNAMIC_LOCAL_VARIABLE_REFERENCE, 'v;');
585 });
586 }
587
588 test_DYNAMIC_PARAMETER() {
589 addTestFile('''
590 main(p) {
591 print(p);
592 }
593 ''');
594 return prepareHighlights().then((_) {
595 assertHasRegion(HighlightRegionType.DYNAMIC_PARAMETER_DECLARATION, 'p)');
596 assertHasRegion(HighlightRegionType.DYNAMIC_PARAMETER_REFERENCE, 'p);');
597 });
598 }
599
600 test_DYNAMIC_VARIABLE_field() {
601 addTestFile('''
602 class A {
603 var f;
604 m() {
605 f = 1;
606 }
607 }
608 ''');
609 return prepareHighlights().then((_) {
610 assertHasRegion(HighlightRegionType.INSTANCE_FIELD_DECLARATION, 'f;');
611 assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'f = 1');
587 }); 612 });
588 } 613 }
589 614
590 test_ENUM() { 615 test_ENUM() {
591 addTestFile(''' 616 addTestFile('''
592 enum MyEnum {A, B, C} 617 enum MyEnum {A, B, C}
593 MyEnum value; 618 MyEnum value;
594 '''); 619 ''');
595 return prepareHighlights().then((_) { 620 return prepareHighlights().then((_) {
596 assertHasRegion(HighlightRegionType.ENUM, 'MyEnum {'); 621 assertHasRegion(HighlightRegionType.ENUM, 'MyEnum {');
(...skipping 10 matching lines...) Expand all
607 } 632 }
608 '''); 633 ''');
609 return prepareHighlights().then((_) { 634 return prepareHighlights().then((_) {
610 assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'AAA, '); 635 assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'AAA, ');
611 assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'BBB}'); 636 assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'BBB}');
612 assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'AAA);'); 637 assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'AAA);');
613 assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'BBB);'); 638 assertHasRegion(HighlightRegionType.ENUM_CONSTANT, 'BBB);');
614 }); 639 });
615 } 640 }
616 641
617 test_FIELD() {
618 addTestFile('''
619 class A {
620 int aaa = 1;
621 int bbb = 2;
622 A([this.bbb = 3]);
623 }
624 main(A a) {
625 a.aaa = 4;
626 a.bbb = 5;
627 }
628 ''');
629 return prepareHighlights().then((_) {
630 assertHasRegion(HighlightRegionType.FIELD, 'aaa = 1');
631 assertHasRegion(HighlightRegionType.FIELD, 'bbb = 2');
632 assertHasRegion(HighlightRegionType.FIELD, 'bbb = 3');
633 assertHasRegion(HighlightRegionType.FIELD, 'aaa = 4');
634 assertHasRegion(HighlightRegionType.FIELD, 'bbb = 5');
635 });
636 }
637
638 test_FIELD_STATIC() {
639 addTestFile('''
640 class A {
641 static aaa = 1;
642 static get bbb => null;
643 static set ccc(x) {}
644 }
645 main() {
646 A.aaa = 2;
647 A.bbb;
648 A.ccc = 3;
649 }
650 ''');
651 return prepareHighlights().then((_) {
652 assertHasRegion(HighlightRegionType.FIELD_STATIC, 'aaa = 1');
653 assertHasRegion(HighlightRegionType.FIELD_STATIC, 'aaa = 2');
654 assertHasRegion(HighlightRegionType.FIELD_STATIC, 'bbb;');
655 assertHasRegion(HighlightRegionType.FIELD_STATIC, 'ccc = 3');
656 });
657 }
658
659 test_FUNCTION() {
660 addTestFile('''
661 fff(p) {}
662 main() {
663 fff(42);
664 }
665 ''');
666 return prepareHighlights().then((_) {
667 assertHasRegion(HighlightRegionType.FUNCTION_DECLARATION, 'fff(p) {}');
668 assertHasRegion(HighlightRegionType.FUNCTION, 'fff(42)');
669 });
670 }
671
672 test_FUNCTION_TYPE_ALIAS() { 642 test_FUNCTION_TYPE_ALIAS() {
673 addTestFile(''' 643 addTestFile('''
674 typedef FFF(p); 644 typedef FFF(p);
675 main(FFF fff) { 645 main(FFF fff) {
676 } 646 }
677 '''); 647 ''');
678 return prepareHighlights().then((_) { 648 return prepareHighlights().then((_) {
679 assertHasRegion(HighlightRegionType.FUNCTION_TYPE_ALIAS, 'FFF(p)'); 649 assertHasRegion(HighlightRegionType.FUNCTION_TYPE_ALIAS, 'FFF(p)');
680 assertHasRegion(HighlightRegionType.FUNCTION_TYPE_ALIAS, 'FFF fff)'); 650 assertHasRegion(HighlightRegionType.FUNCTION_TYPE_ALIAS, 'FFF fff)');
681 }); 651 });
682 } 652 }
683 653
684 test_GETTER_DECLARATION() { 654 test_GETTER() {
685 addTestFile(''' 655 addTestFile('''
686 get aaa => null; 656 get aaa => null;
687 class A { 657 class A {
688 get bbb => null; 658 get bbb => null;
659 static get ccc => null;
689 } 660 }
690 main(A a) { 661 main(A a) {
691 aaa; 662 aaa;
692 a.bbb; 663 a.bbb;
664 A.ccc;
693 } 665 }
694 '''); 666 ''');
695 return prepareHighlights().then((_) { 667 return prepareHighlights().then((_) {
696 assertHasRegion(HighlightRegionType.GETTER_DECLARATION, 'aaa => null'); 668 assertHasRegion(
697 assertHasRegion(HighlightRegionType.GETTER_DECLARATION, 'bbb => null'); 669 HighlightRegionType.TOP_LEVEL_GETTER_DECLARATION, 'aaa => null');
698 assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE, 'aaa;'); 670 assertHasRegion(
699 assertHasRegion(HighlightRegionType.FIELD, 'bbb;'); 671 HighlightRegionType.INSTANCE_GETTER_DECLARATION, 'bbb => null');
672 assertHasRegion(
673 HighlightRegionType.STATIC_GETTER_DECLARATION, 'ccc => null');
674 assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE, 'aaa;');
675 assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'bbb;');
676 assertHasRegion(HighlightRegionType.STATIC_FIELD_REFERENCE, 'ccc;');
700 }); 677 });
701 } 678 }
702 679
703 test_IDENTIFIER_DEFAULT() { 680 test_IDENTIFIER_DEFAULT() {
704 addTestFile(''' 681 addTestFile('''
705 main() { 682 main() {
706 aaa = 42; 683 aaa = 42;
707 bbb(84); 684 bbb(84);
708 CCC ccc; 685 CCC ccc;
709 } 686 }
(...skipping 11 matching lines...) Expand all
721 main() { 698 main() {
722 ma.max(1, 2); 699 ma.max(1, 2);
723 } 700 }
724 '''); 701 ''');
725 return prepareHighlights().then((_) { 702 return prepareHighlights().then((_) {
726 assertHasRegion(HighlightRegionType.IMPORT_PREFIX, 'ma;'); 703 assertHasRegion(HighlightRegionType.IMPORT_PREFIX, 'ma;');
727 assertHasRegion(HighlightRegionType.IMPORT_PREFIX, 'ma.max'); 704 assertHasRegion(HighlightRegionType.IMPORT_PREFIX, 'ma.max');
728 }); 705 });
729 } 706 }
730 707
708 test_INSTANCE_FIELD() {
709 addTestFile('''
710 class A {
711 int aaa = 1;
712 int bbb = 2;
713 A([this.bbb = 3]);
714 }
715 main(A a) {
716 a.aaa = 4;
717 a.bbb = 5;
718 }
719 ''');
720 return prepareHighlights().then((_) {
721 assertHasRegion(
722 HighlightRegionType.INSTANCE_FIELD_DECLARATION, 'aaa = 1');
723 assertHasRegion(
724 HighlightRegionType.INSTANCE_FIELD_DECLARATION, 'bbb = 2');
725 assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'bbb = 3');
726 assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'aaa = 4');
727 assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'bbb = 5');
728 });
729 }
730
731 test_KEYWORD() { 731 test_KEYWORD() {
732 addTestFile(''' 732 addTestFile('''
733 main() { 733 main() {
734 assert(true); 734 assert(true);
735 for (;;) break; 735 for (;;) break;
736 switch (0) { 736 switch (0) {
737 case 0: break; 737 case 0: break;
738 default: break; 738 default: break;
739 } 739 }
740 try {} catch (e) {} 740 try {} catch (e) {}
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 } 855 }
856 856
857 test_LITERAL_STRING() { 857 test_LITERAL_STRING() {
858 addTestFile('var V = "abc";'); 858 addTestFile('var V = "abc";');
859 return prepareHighlights().then((_) { 859 return prepareHighlights().then((_) {
860 assertHasRegion( 860 assertHasRegion(
861 HighlightRegionType.LITERAL_STRING, '"abc";', '"abc"'.length); 861 HighlightRegionType.LITERAL_STRING, '"abc";', '"abc"'.length);
862 }); 862 });
863 } 863 }
864 864
865 test_LOCAL_FUNCTION() {
866 addTestFile('''
867 main() {
868 fff() {}
869 fff();
870 fff;
871 }
872 ''');
873 return prepareHighlights().then((_) {
874 assertHasRegion(
875 HighlightRegionType.LOCAL_FUNCTION_DECLARATION, 'fff() {}');
876 assertHasRegion(HighlightRegionType.LOCAL_FUNCTION_REFERENCE, 'fff();');
877 assertHasRegion(HighlightRegionType.LOCAL_FUNCTION_REFERENCE, 'fff;');
878 });
879 }
880
865 test_LOCAL_VARIABLE() { 881 test_LOCAL_VARIABLE() {
866 addTestFile(''' 882 addTestFile('''
867 main() { 883 main() {
868 int vvv = 0; 884 int vvv = 0;
869 vvv; 885 vvv;
870 vvv = 1; 886 vvv = 1;
871 } 887 }
872 '''); 888 ''');
873 return prepareHighlights().then((_) { 889 return prepareHighlights().then((_) {
874 assertHasRegion( 890 assertHasRegion(
875 HighlightRegionType.LOCAL_VARIABLE_DECLARATION, 'vvv = 0'); 891 HighlightRegionType.LOCAL_VARIABLE_DECLARATION, 'vvv = 0');
876 assertHasRegion(HighlightRegionType.LOCAL_VARIABLE, 'vvv;'); 892 assertHasRegion(HighlightRegionType.LOCAL_VARIABLE_REFERENCE, 'vvv;');
877 assertHasRegion(HighlightRegionType.LOCAL_VARIABLE, 'vvv = 1;'); 893 assertHasRegion(HighlightRegionType.LOCAL_VARIABLE_REFERENCE, 'vvv = 1;');
878 }); 894 });
879 } 895 }
880 896
881 test_METHOD() { 897 test_METHOD() {
882 addTestFile(''' 898 addTestFile('''
883 class A { 899 class A {
884 aaa() {} 900 aaa() {}
885 static bbb() {} 901 static bbb() {}
886 } 902 }
887 main(A a) { 903 main(A a) {
888 a.aaa(); 904 a.aaa();
889 a.aaa; 905 a.aaa;
890 A.bbb(); 906 A.bbb();
891 A.bbb; 907 A.bbb;
892 } 908 }
893 '''); 909 ''');
894 return prepareHighlights().then((_) { 910 return prepareHighlights().then((_) {
895 assertHasRegion(HighlightRegionType.METHOD_DECLARATION, 'aaa() {}');
896 assertHasRegion( 911 assertHasRegion(
897 HighlightRegionType.METHOD_DECLARATION_STATIC, 'bbb() {}'); 912 HighlightRegionType.INSTANCE_METHOD_DECLARATION, 'aaa() {}');
898 assertHasRegion(HighlightRegionType.METHOD, 'aaa();'); 913 assertHasRegion(
899 assertHasRegion(HighlightRegionType.METHOD, 'aaa;'); 914 HighlightRegionType.STATIC_METHOD_DECLARATION, 'bbb() {}');
900 assertHasRegion(HighlightRegionType.METHOD_STATIC, 'bbb();'); 915 assertHasRegion(HighlightRegionType.INSTANCE_METHOD_REFERENCE, 'aaa();');
901 assertHasRegion(HighlightRegionType.METHOD_STATIC, 'bbb;'); 916 assertHasRegion(HighlightRegionType.INSTANCE_METHOD_REFERENCE, 'aaa;');
917 assertHasRegion(HighlightRegionType.STATIC_METHOD_REFERENCE, 'bbb();');
918 assertHasRegion(HighlightRegionType.STATIC_METHOD_REFERENCE, 'bbb;');
902 }); 919 });
903 } 920 }
904 921
905 test_METHOD_bestType() { 922 test_METHOD_bestType() {
906 addTestFile(''' 923 addTestFile('''
907 main(p) { 924 main(p) {
908 if (p is List) { 925 if (p is List) {
909 p.add(null); 926 p.add(null);
910 } 927 }
911 } 928 }
912 '''); 929 ''');
913 return prepareHighlights().then((_) { 930 return prepareHighlights().then((_) {
914 assertHasRegion(HighlightRegionType.METHOD, 'add(null)'); 931 assertHasRegion(
932 HighlightRegionType.INSTANCE_METHOD_REFERENCE, 'add(null)');
915 }); 933 });
916 } 934 }
917 935
918 test_PARAMETER() { 936 test_PARAMETER() {
919 addTestFile(''' 937 addTestFile('''
920 main(int p) { 938 main(int p) {
921 p; 939 p;
922 p = 42; 940 p = 42;
923 } 941 }
924 '''); 942 ''');
925 return prepareHighlights().then((_) { 943 return prepareHighlights().then((_) {
926 assertHasRegion(HighlightRegionType.PARAMETER, 'p) {'); 944 assertHasRegion(HighlightRegionType.PARAMETER_DECLARATION, 'p) {');
927 assertHasRegion(HighlightRegionType.PARAMETER, 'p;'); 945 assertHasRegion(HighlightRegionType.PARAMETER_REFERENCE, 'p;');
928 assertHasRegion(HighlightRegionType.PARAMETER, 'p = 42'); 946 assertHasRegion(HighlightRegionType.PARAMETER_REFERENCE, 'p = 42');
929 }); 947 });
930 } 948 }
931 949
932 test_SETTER_DECLARATION() { 950 test_SETTER_DECLARATION() {
933 addTestFile(''' 951 addTestFile('''
934 set aaa(x) {} 952 set aaa(x) {}
935 class A { 953 class A {
936 set bbb(x) {} 954 set bbb(x) {}
955 static set ccc(x) {}
937 } 956 }
938 main(A a) { 957 main(A a) {
939 aaa = 1; 958 aaa = 1;
940 a.bbb = 2; 959 a.bbb = 2;
960 A.ccc = 3;
941 } 961 }
942 '''); 962 ''');
943 return prepareHighlights().then((_) { 963 return prepareHighlights().then((_) {
944 assertHasRegion(HighlightRegionType.SETTER_DECLARATION, 'aaa(x)'); 964 assertHasRegion(
945 assertHasRegion(HighlightRegionType.SETTER_DECLARATION, 'bbb(x)'); 965 HighlightRegionType.TOP_LEVEL_SETTER_DECLARATION, 'aaa(x)');
946 assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE, 'aaa = 1'); 966 assertHasRegion(
947 assertHasRegion(HighlightRegionType.FIELD, 'bbb = 2'); 967 HighlightRegionType.INSTANCE_SETTER_DECLARATION, 'bbb(x)');
968 assertHasRegion(HighlightRegionType.STATIC_SETTER_DECLARATION, 'ccc(x)');
969 assertHasRegion(
970 HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE, 'aaa = 1');
971 assertHasRegion(HighlightRegionType.INSTANCE_FIELD_REFERENCE, 'bbb = 2');
972 assertHasRegion(HighlightRegionType.STATIC_FIELD_REFERENCE, 'ccc = 3');
948 }); 973 });
949 } 974 }
950 975
976 test_STATIC_FIELD() {
977 addTestFile('''
978 class A {
979 static aaa = 1;
980 static get bbb => null;
981 static set ccc(x) {}
982 }
983 main() {
984 A.aaa = 2;
985 A.bbb;
986 A.ccc = 3;
987 }
988 ''');
989 return prepareHighlights().then((_) {
990 assertHasRegion(HighlightRegionType.STATIC_FIELD_DECLARATION, 'aaa = 1');
991 assertHasRegion(HighlightRegionType.STATIC_FIELD_REFERENCE, 'aaa = 2');
992 assertHasRegion(HighlightRegionType.STATIC_FIELD_REFERENCE, 'bbb;');
993 assertHasRegion(HighlightRegionType.STATIC_FIELD_REFERENCE, 'ccc = 3');
994 });
995 }
996
997 test_TOP_LEVEL_FUNCTION() {
998 addTestFile('''
999 fff(p) {}
1000 main() {
1001 fff(42);
1002 }
1003 ''');
1004 return prepareHighlights().then((_) {
1005 assertHasRegion(
1006 HighlightRegionType.TOP_LEVEL_FUNCTION_DECLARATION, 'fff(p) {}');
1007 assertHasRegion(
1008 HighlightRegionType.TOP_LEVEL_FUNCTION_REFERENCE, 'fff(42)');
1009 });
1010 }
1011
951 test_TOP_LEVEL_VARIABLE() { 1012 test_TOP_LEVEL_VARIABLE() {
952 addTestFile(''' 1013 addTestFile('''
953 const VVV = 0; 1014 const VVV = 0;
954 @VVV // annotation 1015 @VVV // annotation
955 main() { 1016 main() {
956 print(VVV); 1017 print(VVV);
957 VVV = 1; 1018 VVV = 1;
958 } 1019 }
959 '''); 1020 ''');
960 return prepareHighlights().then((_) { 1021 return prepareHighlights().then((_) {
961 assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE, 'VVV = 0');
962 assertHasRegion( 1022 assertHasRegion(
963 HighlightRegionType.TOP_LEVEL_VARIABLE, 'VVV // annotation'); 1023 HighlightRegionType.TOP_LEVEL_VARIABLE_DECLARATION, 'VVV = 0');
964 assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE, 'VVV);'); 1024 assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE,
965 assertHasRegion(HighlightRegionType.TOP_LEVEL_VARIABLE, 'VVV = 1'); 1025 'VVV // annotation');
1026 assertHasRegion(
1027 HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE, 'VVV);');
1028 assertHasRegion(
1029 HighlightRegionType.TOP_LEVEL_VARIABLE_REFERENCE, 'VVV = 1');
966 }); 1030 });
967 } 1031 }
968 1032
969 test_TYPE_NAME_DYNAMIC() { 1033 test_TYPE_NAME_DYNAMIC() {
970 addTestFile(''' 1034 addTestFile('''
971 dynamic main() { 1035 dynamic main() {
972 dynamic = 42; 1036 dynamic = 42;
973 } 1037 }
974 '''); 1038 ''');
975 return prepareHighlights().then((_) { 1039 return prepareHighlights().then((_) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 void test_toString() { 1076 void test_toString() {
1013 expect(HighlightRegionType.CLASS.toString(), 'HighlightRegionType.CLASS'); 1077 expect(HighlightRegionType.CLASS.toString(), 'HighlightRegionType.CLASS');
1014 } 1078 }
1015 1079
1016 void test_valueOf_unknown() { 1080 void test_valueOf_unknown() {
1017 expect(() { 1081 expect(() {
1018 new HighlightRegionType('no-such-type'); 1082 new HighlightRegionType('no-such-type');
1019 }, throws); 1083 }, throws);
1020 } 1084 }
1021 } 1085 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698