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

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

Issue 1712583003: Serialize and resynthesize labels. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 if (original is! Member) { 570 if (original is! Member) {
571 List<FunctionElement> rFunctions = resynthesized.functions; 571 List<FunctionElement> rFunctions = resynthesized.functions;
572 List<FunctionElement> oFunctions = original.functions; 572 List<FunctionElement> oFunctions = original.functions;
573 expect(rFunctions, hasLength(oFunctions.length)); 573 expect(rFunctions, hasLength(oFunctions.length));
574 for (int i = 0; i < oFunctions.length; i++) { 574 for (int i = 0; i < oFunctions.length; i++) {
575 compareFunctionElements(rFunctions[i], oFunctions[i], 575 compareFunctionElements(rFunctions[i], oFunctions[i],
576 '$desc local function ${oFunctions[i].name}'); 576 '$desc local function ${oFunctions[i].name}');
577 } 577 }
578 } 578 }
579 if (original is! Member) { 579 if (original is! Member) {
580 List<LabelElement> rLabels = resynthesized.labels;
581 List<LabelElement> oLabels = original.labels;
582 expect(rLabels, hasLength(oLabels.length));
583 for (int i = 0; i < oLabels.length; i++) {
584 compareLabelElements(
585 rLabels[i], oLabels[i], '$desc label ${oLabels[i].name}');
586 }
587 }
588 if (original is! Member) {
580 List<LocalVariableElement> rVariables = resynthesized.localVariables; 589 List<LocalVariableElement> rVariables = resynthesized.localVariables;
581 List<LocalVariableElement> oVariables = original.localVariables; 590 List<LocalVariableElement> oVariables = original.localVariables;
582 expect(rVariables, hasLength(oVariables.length)); 591 expect(rVariables, hasLength(oVariables.length));
583 for (int i = 0; i < oVariables.length; i++) { 592 for (int i = 0; i < oVariables.length; i++) {
584 compareVariableElements(rVariables[i], oVariables[i], 593 compareVariableElements(rVariables[i], oVariables[i],
585 '$desc local variable ${oVariables[i].name}'); 594 '$desc local variable ${oVariables[i].name}');
586 } 595 }
587 } 596 }
588 } 597 }
589 598
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 comparePrefixElements( 656 comparePrefixElements(
648 resynthesized.prefix, original.prefix, original.prefix.name); 657 resynthesized.prefix, original.prefix, original.prefix.name);
649 } 658 }
650 expect(resynthesized.combinators.length, original.combinators.length); 659 expect(resynthesized.combinators.length, original.combinators.length);
651 for (int i = 0; i < resynthesized.combinators.length; i++) { 660 for (int i = 0; i < resynthesized.combinators.length; i++) {
652 compareNamespaceCombinators( 661 compareNamespaceCombinators(
653 resynthesized.combinators[i], original.combinators[i]); 662 resynthesized.combinators[i], original.combinators[i]);
654 } 663 }
655 } 664 }
656 665
666 void compareLabelElements(
667 LabelElementImpl resynthesized, LabelElementImpl original, String desc) {
668 expect(resynthesized.isOnSwitchMember, original.isOnSwitchMember,
669 reason: desc);
670 expect(resynthesized.isOnSwitchStatement, original.isOnSwitchStatement,
671 reason: desc);
672 compareElements(resynthesized, original, desc);
673 }
674
657 void compareMetadata(List<ElementAnnotation> resynthesized, 675 void compareMetadata(List<ElementAnnotation> resynthesized,
658 List<ElementAnnotation> original, String desc) { 676 List<ElementAnnotation> original, String desc) {
659 expect(resynthesized, hasLength(original.length), reason: desc); 677 expect(resynthesized, hasLength(original.length), reason: desc);
660 for (int i = 0; i < original.length; i++) { 678 for (int i = 0; i < original.length; i++) {
661 compareElementAnnotations( 679 compareElementAnnotations(
662 resynthesized[i], original[i], '$desc annotation $i'); 680 resynthesized[i], original[i], '$desc annotation $i');
663 } 681 }
664 } 682 }
665 683
666 void compareMethodElements(MethodElementImpl resynthesized, 684 void compareMethodElements(MethodElementImpl resynthesized,
(...skipping 2205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2872 } 2890 }
2873 2891
2874 test_localFunctions_inTopLevelGetter() { 2892 test_localFunctions_inTopLevelGetter() {
2875 checkLibrary(r''' 2893 checkLibrary(r'''
2876 get g { 2894 get g {
2877 f() {} 2895 f() {}
2878 } 2896 }
2879 '''); 2897 ''');
2880 } 2898 }
2881 2899
2900 test_localLabels_inConstructor() {
2901 checkLibrary(r'''
2902 class C {
2903 C() {
2904 aaa: while (true) {}
2905 bbb: switch (42) {
2906 ccc: case 0:
2907 break;
2908 }
2909 }
2910 }
2911 ''');
2912 }
2913
2914 test_localLabels_inMethod() {
2915 checkLibrary(r'''
2916 class C {
2917 m() {
2918 aaa: while (true) {}
2919 bbb: switch (42) {
2920 ccc: case 0:
2921 break;
2922 }
2923 }
2924 }
2925 ''');
2926 }
2927
2928 test_localLabels_inTopLevelFunction() {
2929 checkLibrary(r'''
2930 main() {
2931 aaa: while (true) {}
2932 bbb: switch (42) {
2933 ccc: case 0:
2934 break;
2935 }
2936 }
2937 ''');
2938 }
2939
2882 test_localVariables_inConstructor() { 2940 test_localVariables_inConstructor() {
2883 checkLibrary(r''' 2941 checkLibrary(r'''
2884 class C { 2942 class C {
2885 C() { 2943 C() {
2886 int v; 2944 int v;
2887 f() {} 2945 f() {}
2888 } 2946 }
2889 } 2947 }
2890 '''); 2948 ''');
2891 } 2949 }
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
3699 fail('Unexpectedly tried to get unlinked summary for $uri'); 3757 fail('Unexpectedly tried to get unlinked summary for $uri');
3700 } 3758 }
3701 return serializedUnit; 3759 return serializedUnit;
3702 } 3760 }
3703 3761
3704 @override 3762 @override
3705 bool hasLibrarySummary(String uri) { 3763 bool hasLibrarySummary(String uri) {
3706 return true; 3764 return true;
3707 } 3765 }
3708 } 3766 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698