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

Side by Side Diff: pkg/analyzer/test/src/summary/resynthesize_test.dart

Issue 1573633002: Implement support for Element.documentationComment in summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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.src.serialization.elements_test; 5 library test.src.serialization.elements_test;
6 6
7 import 'package:analyzer/src/generated/element.dart'; 7 import 'package:analyzer/src/generated/element.dart';
8 import 'package:analyzer/src/generated/engine.dart'; 8 import 'package:analyzer/src/generated/engine.dart';
9 import 'package:analyzer/src/generated/source.dart'; 9 import 'package:analyzer/src/generated/source.dart';
10 import 'package:analyzer/src/summary/base.dart'; 10 import 'package:analyzer/src/summary/base.dart';
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // TODO(paulberry): test redirectedConstructor and constantInitializers 191 // TODO(paulberry): test redirectedConstructor and constantInitializers
192 } 192 }
193 193
194 void compareElements( 194 void compareElements(
195 ElementImpl resynthesized, ElementImpl original, String desc) { 195 ElementImpl resynthesized, ElementImpl original, String desc) {
196 expect(resynthesized, isNotNull); 196 expect(resynthesized, isNotNull);
197 expect(resynthesized.kind, original.kind); 197 expect(resynthesized.kind, original.kind);
198 expect(resynthesized.location, original.location, reason: desc); 198 expect(resynthesized.location, original.location, reason: desc);
199 expect(resynthesized.name, original.name); 199 expect(resynthesized.name, original.name);
200 expect(resynthesized.nameOffset, original.nameOffset, reason: desc); 200 expect(resynthesized.nameOffset, original.nameOffset, reason: desc);
201 expect(resynthesized.documentationComment, original.documentationComment,
202 reason: desc);
scheglov 2016/01/08 22:04:45 Do we want to support the (deprecated) `docRange`
Paul Berry 2016/01/08 22:37:47 Good question. I don't know if it's really needed
201 for (Modifier modifier in Modifier.values) { 203 for (Modifier modifier in Modifier.values) {
202 if (modifier == Modifier.MIXIN) { 204 if (modifier == Modifier.MIXIN) {
203 // Skipping for now. TODO(paulberry): fix. 205 // Skipping for now. TODO(paulberry): fix.
204 continue; 206 continue;
205 } 207 }
206 bool got = resynthesized.hasModifier(modifier); 208 bool got = resynthesized.hasModifier(modifier);
207 bool want = original.hasModifier(modifier); 209 bool want = original.hasModifier(modifier);
208 expect(got, want, 210 expect(got, want,
209 reason: 'Mismatch in $desc.$modifier: got $got, want $want'); 211 reason: 'Mismatch in $desc.$modifier: got $got, want $want');
210 } 212 }
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 // Check that no other summaries needed to be resynthesized to resynthesize 526 // Check that no other summaries needed to be resynthesized to resynthesize
525 // the library element. 527 // the library element.
526 expect(resynthesizer.resynthesisCount, 1); 528 expect(resynthesizer.resynthesisCount, 1);
527 return resynthesized; 529 return resynthesized;
528 } 530 }
529 531
530 test_class_alias() { 532 test_class_alias() {
531 checkLibrary('class C = D with E, F; class D {} class E {} class F {}'); 533 checkLibrary('class C = D with E, F; class D {} class E {} class F {}');
532 } 534 }
533 535
536 test_class_alias_documented() {
537 checkLibrary('''
538 // Extra comment so doc comment offset != 0
539 /**
540 * Docs
541 */
542 class C = D with E;
543
544 class D {}
545 class E {}''');
546 }
547
534 test_class_alias_with_forwarding_constructors() { 548 test_class_alias_with_forwarding_constructors() {
535 addLibrarySource( 549 addLibrarySource(
536 '/a.dart', 550 '/a.dart',
537 ''' 551 '''
538 class Base { 552 class Base {
539 Base._priv(); 553 Base._priv();
540 Base(); 554 Base();
541 Base.noArgs(); 555 Base.noArgs();
542 Base.requiredArg(x); 556 Base.requiredArg(x);
543 Base.positionalArg([x]); 557 Base.positionalArg([x]);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 } 672 }
659 673
660 test_class_constructor_params() { 674 test_class_constructor_params() {
661 checkLibrary('class C { C(x, y); }'); 675 checkLibrary('class C { C(x, y); }');
662 } 676 }
663 677
664 test_class_constructors() { 678 test_class_constructors() {
665 checkLibrary('class C { C.foo(); C.bar(); }'); 679 checkLibrary('class C { C.foo(); C.bar(); }');
666 } 680 }
667 681
682 test_class_documented() {
683 checkLibrary('''
684 // Extra comment so doc comment offset != 0
685 /**
686 * Docs
687 */
688 class C {}''');
689 }
690
691 test_class_documented_with_references() {
692 checkLibrary('''
693 /**
694 * Docs referring to [D] and [E]
695 */
696 class C {}
697
698 class D {}
699 class E {}''');
700 }
701
702 test_class_documented_with_windows_line_endings() {
703 checkLibrary('/**\r\n * Docs\r\n */\r\nclass C {}');
704 }
705
668 test_class_field_const() { 706 test_class_field_const() {
669 checkLibrary('class C { static const int i = 0; }'); 707 checkLibrary('class C { static const int i = 0; }');
670 } 708 }
671 709
672 test_class_field_implicit_type() { 710 test_class_field_implicit_type() {
673 checkLibrary('class C { var x; }'); 711 checkLibrary('class C { var x; }');
674 } 712 }
675 713
676 test_class_field_static() { 714 test_class_field_static() {
677 checkLibrary('class C { static int i; }'); 715 checkLibrary('class C { static int i; }');
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 } 804 }
767 805
768 test_class_type_parameters_f_bound_simple() { 806 test_class_type_parameters_f_bound_simple() {
769 checkLibrary('class C<T extends U, U> {}'); 807 checkLibrary('class C<T extends U, U> {}');
770 } 808 }
771 809
772 test_classes() { 810 test_classes() {
773 checkLibrary('class C {} class D {}'); 811 checkLibrary('class C {} class D {}');
774 } 812 }
775 813
814 test_constructor_documented() {
815 checkLibrary('''
816 class C {
817 /**
818 * Docs
819 */
820 C();
821 }''');
822 }
823
776 test_core() { 824 test_core() {
777 String uri = 'dart:core'; 825 String uri = 'dart:core';
778 LibraryElementImpl original = 826 LibraryElementImpl original =
779 resolve2(analysisContext2.sourceFactory.forUri(uri)); 827 resolve2(analysisContext2.sourceFactory.forUri(uri));
780 LibraryElementImpl resynthesized = 828 LibraryElementImpl resynthesized =
781 resynthesizeLibraryElement(uri, original); 829 resynthesizeLibraryElement(uri, original);
782 checkLibraryElements(original, resynthesized); 830 checkLibraryElements(original, resynthesized);
783 } 831 }
784 832
833 test_enum_documented() {
834 checkLibrary('''
835 // Extra comment so doc comment offset != 0
836 /**
837 * Docs
838 */
839 enum E { v }''');
840 }
841
842 test_enum_value_documented() {
843 checkLibrary('''
844 enum E {
845 /**
846 * Docs
847 */
848 v
849 }''');
850 }
851
785 test_enum_values() { 852 test_enum_values() {
786 checkLibrary('enum E { v1, v2 }'); 853 checkLibrary('enum E { v1, v2 }');
787 } 854 }
788 855
789 test_enums() { 856 test_enums() {
790 checkLibrary('enum E1 { v1 } enum E2 { v2 }'); 857 checkLibrary('enum E1 { v1 } enum E2 { v2 }');
791 } 858 }
792 859
793 test_export_hide() { 860 test_export_hide() {
794 addLibrary('dart:async'); 861 addLibrary('dart:async');
795 checkLibrary('export "dart:async" hide Stream, Future;'); 862 checkLibrary('export "dart:async" hide Stream, Future;');
796 } 863 }
797 864
798 test_export_multiple_combinators() { 865 test_export_multiple_combinators() {
799 addLibrary('dart:async'); 866 addLibrary('dart:async');
800 checkLibrary('export "dart:async" hide Stream show Future;'); 867 checkLibrary('export "dart:async" hide Stream show Future;');
801 } 868 }
802 869
803 test_export_show() { 870 test_export_show() {
804 addLibrary('dart:async'); 871 addLibrary('dart:async');
805 checkLibrary('export "dart:async" show Future, Stream;'); 872 checkLibrary('export "dart:async" show Future, Stream;');
806 } 873 }
807 874
808 test_exports() { 875 test_exports() {
809 addLibrarySource('/a.dart', 'library a;'); 876 addLibrarySource('/a.dart', 'library a;');
810 addLibrarySource('/b.dart', 'library b;'); 877 addLibrarySource('/b.dart', 'library b;');
811 checkLibrary('export "a.dart"; export "b.dart";'); 878 checkLibrary('export "a.dart"; export "b.dart";');
812 } 879 }
813 880
881 test_field_documented() {
882 checkLibrary('''
883 class C {
884 /**
885 * Docs
886 */
887 var x;
888 }''');
889 }
890
891 test_function_documented() {
892 checkLibrary('''
893 // Extra comment so doc comment offset != 0
894 /**
895 * Docs
896 */
897 f() {}''');
898 }
899
814 test_function_entry_point() { 900 test_function_entry_point() {
815 checkLibrary('main() {}'); 901 checkLibrary('main() {}');
816 } 902 }
817 903
818 test_function_entry_point_in_export_hidden() { 904 test_function_entry_point_in_export_hidden() {
819 addLibrarySource('/a.dart', 'library a; main() {}'); 905 addLibrarySource('/a.dart', 'library a; main() {}');
820 checkLibrary('export "a.dart" hide main;'); 906 checkLibrary('export "a.dart" hide main;');
821 } 907 }
822 908
823 test_function_entry_point_in_part() { 909 test_function_entry_point_in_part() {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 968
883 test_function_type_parameter_with_function_typed_parameter() { 969 test_function_type_parameter_with_function_typed_parameter() {
884 resetWithOptions(new AnalysisOptionsImpl()..enableGenericMethods = true); 970 resetWithOptions(new AnalysisOptionsImpl()..enableGenericMethods = true);
885 checkLibrary('void f<T, U>(T x(U u)) {}'); 971 checkLibrary('void f<T, U>(T x(U u)) {}');
886 } 972 }
887 973
888 test_functions() { 974 test_functions() {
889 checkLibrary('f() {} g() {}'); 975 checkLibrary('f() {} g() {}');
890 } 976 }
891 977
978 test_getter_documented() {
979 checkLibrary('''
980 // Extra comment so doc comment offset != 0
981 /**
982 * Docs
983 */
984 get x => null;''');
985 }
986
892 test_getter_external() { 987 test_getter_external() {
893 checkLibrary('external int get x;'); 988 checkLibrary('external int get x;');
894 } 989 }
895 990
896 test_getters() { 991 test_getters() {
897 checkLibrary('int get x => null; get y => null;'); 992 checkLibrary('int get x => null; get y => null;');
898 } 993 }
899 994
900 test_import_hide() { 995 test_import_hide() {
901 addLibrary('dart:async'); 996 addLibrary('dart:async');
(...skipping 18 matching lines...) Expand all
920 test_imports() { 1015 test_imports() {
921 addLibrarySource('/a.dart', 'library a; class C {}'); 1016 addLibrarySource('/a.dart', 'library a; class C {}');
922 addLibrarySource('/b.dart', 'library b; class D {}'); 1017 addLibrarySource('/b.dart', 'library b; class D {}');
923 checkLibrary('import "a.dart"; import "b.dart"; C c; D d;'); 1018 checkLibrary('import "a.dart"; import "b.dart"; C c; D d;');
924 } 1019 }
925 1020
926 test_library() { 1021 test_library() {
927 checkLibrary(''); 1022 checkLibrary('');
928 } 1023 }
929 1024
1025 test_library_documented() {
1026 checkLibrary('''
1027 // Extra comment so doc comment offset != 0
1028 /**
1029 * Docs
1030 */
1031 library foo;''');
1032 }
1033
930 test_library_name_with_spaces() { 1034 test_library_name_with_spaces() {
931 checkLibrary('library foo . bar ;'); 1035 checkLibrary('library foo . bar ;');
932 } 1036 }
933 1037
934 test_library_named() { 1038 test_library_named() {
935 checkLibrary('library foo.bar;'); 1039 checkLibrary('library foo.bar;');
936 } 1040 }
937 1041
1042 test_method_documented() {
1043 checkLibrary('''
1044 class C {
1045 /**
1046 * Docs
1047 */
1048 f() {}
1049 }''');
1050 }
1051
938 test_method_parameter_parameters() { 1052 test_method_parameter_parameters() {
939 checkLibrary('class C { f(g(x, y)) {} }'); 1053 checkLibrary('class C { f(g(x, y)) {} }');
940 } 1054 }
941 1055
942 test_method_parameter_parameters_in_generic_class() { 1056 test_method_parameter_parameters_in_generic_class() {
943 checkLibrary('class C<A, B> { f(A g(B x)) {} }'); 1057 checkLibrary('class C<A, B> { f(A g(B x)) {} }');
944 } 1058 }
945 1059
946 test_method_parameter_return_type() { 1060 test_method_parameter_return_type() {
947 checkLibrary('class C { f(int g()) {} }'); 1061 checkLibrary('class C { f(int g()) {} }');
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 test_operator_less_equal() { 1107 test_operator_less_equal() {
994 checkLibrary('class C { bool operator<=(C other) => false; }'); 1108 checkLibrary('class C { bool operator<=(C other) => false; }');
995 } 1109 }
996 1110
997 test_parts() { 1111 test_parts() {
998 addNamedSource('/a.dart', 'part of my.lib;'); 1112 addNamedSource('/a.dart', 'part of my.lib;');
999 addNamedSource('/b.dart', 'part of my.lib;'); 1113 addNamedSource('/b.dart', 'part of my.lib;');
1000 checkLibrary('library my.lib; part "a.dart"; part "b.dart";'); 1114 checkLibrary('library my.lib; part "a.dart"; part "b.dart";');
1001 } 1115 }
1002 1116
1117 test_setter_documented() {
1118 checkLibrary('''
1119 // Extra comment so doc comment offset != 0
1120 /**
1121 * Docs
1122 */
1123 void set x(value) {}''');
1124 }
1125
1003 test_setter_external() { 1126 test_setter_external() {
1004 checkLibrary('external void set x(int value);'); 1127 checkLibrary('external void set x(int value);');
1005 } 1128 }
1006 1129
1007 test_setters() { 1130 test_setters() {
1008 checkLibrary('void set x(int value) {} set y(value) {}'); 1131 checkLibrary('void set x(int value) {} set y(value) {}');
1009 } 1132 }
1010 1133
1011 test_type_arguments_explicit() { 1134 test_type_arguments_explicit() {
1012 checkLibrary('Map<String, int> m;'); 1135 checkLibrary('Map<String, int> m;');
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 } 1258 }
1136 1259
1137 test_type_unresolved() { 1260 test_type_unresolved() {
1138 checkLibrary('C c;', allowErrors: true); 1261 checkLibrary('C c;', allowErrors: true);
1139 } 1262 }
1140 1263
1141 test_type_unresolved_prefixed() { 1264 test_type_unresolved_prefixed() {
1142 checkLibrary('import "dart:core" as core; core.C c;', allowErrors: true); 1265 checkLibrary('import "dart:core" as core; core.C c;', allowErrors: true);
1143 } 1266 }
1144 1267
1268 test_typedef_documented() {
1269 checkLibrary('''
1270 // Extra comment so doc comment offset != 0
1271 /**
1272 * Docs
1273 */
1274 typedef F();''');
1275 }
1276
1145 test_typedef_parameter_parameters() { 1277 test_typedef_parameter_parameters() {
1146 checkLibrary('typedef F(g(x, y));'); 1278 checkLibrary('typedef F(g(x, y));');
1147 } 1279 }
1148 1280
1149 test_typedef_parameter_parameters_in_generic_class() { 1281 test_typedef_parameter_parameters_in_generic_class() {
1150 checkLibrary('typedef F<A, B>(A g(B x));'); 1282 checkLibrary('typedef F<A, B>(A g(B x));');
1151 } 1283 }
1152 1284
1153 test_typedef_parameter_return_type() { 1285 test_typedef_parameter_return_type() {
1154 checkLibrary('typedef F(int g());'); 1286 checkLibrary('typedef F(int g());');
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 } 1331 }
1200 1332
1201 test_typedefs() { 1333 test_typedefs() {
1202 checkLibrary('f() {} g() {}'); 1334 checkLibrary('f() {} g() {}');
1203 } 1335 }
1204 1336
1205 test_variable_const() { 1337 test_variable_const() {
1206 checkLibrary('const int i = 0;'); 1338 checkLibrary('const int i = 0;');
1207 } 1339 }
1208 1340
1341 test_variable_documented() {
1342 checkLibrary('''
1343 // Extra comment so doc comment offset != 0
1344 /**
1345 * Docs
1346 */
1347 var x;''');
1348 }
1349
1209 test_variable_implicit_type() { 1350 test_variable_implicit_type() {
1210 checkLibrary('var x;'); 1351 checkLibrary('var x;');
1211 } 1352 }
1212 1353
1213 test_variables() { 1354 test_variables() {
1214 checkLibrary('int i; int j;'); 1355 checkLibrary('int i; int j;');
1215 } 1356 }
1216 } 1357 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | pkg/analyzer/test/src/summary/summary_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698