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

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

Issue 1650833002: Resynthesize type references. (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 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/dart/element/type.dart'; 9 import 'package:analyzer/dart/element/type.dart';
10 import 'package:analyzer/src/dart/element/element.dart'; 10 import 'package:analyzer/src/dart/element/element.dart';
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 compareElements(resynthesized, original, desc); 592 compareElements(resynthesized, original, desc);
593 expect(resynthesized.uri, original.uri); 593 expect(resynthesized.uri, original.uri);
594 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); 594 expect(resynthesized.uriOffset, original.uriOffset, reason: desc);
595 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); 595 expect(resynthesized.uriEnd, original.uriEnd, reason: desc);
596 } 596 }
597 597
598 void compareVariableElements(VariableElementImpl resynthesized, 598 void compareVariableElements(VariableElementImpl resynthesized,
599 VariableElementImpl original, String desc) { 599 VariableElementImpl original, String desc) {
600 compareElements(resynthesized, original, desc); 600 compareElements(resynthesized, original, desc);
601 compareTypes(resynthesized.type, original.type, desc); 601 compareTypes(resynthesized.type, original.type, desc);
602 if (shouldCompareConstValues) { 602 // TODO(scheglov) implement and validate other constant variable types
603 if (shouldCompareConstValues &&
604 original is ConstTopLevelVariableElementImpl) {
603 compareConstantExpressions(resynthesized.constantInitializer, 605 compareConstantExpressions(resynthesized.constantInitializer,
604 original.constantInitializer, desc); 606 original.constantInitializer, desc);
605 } 607 }
606 // TODO(paulberry): test initializer 608 // TODO(paulberry): test initializer
607 } 609 }
608 610
609 /** 611 /**
610 * Serialize the given [library] into a summary. Then create a 612 * Serialize the given [library] into a summary. Then create a
611 * [_TestSummaryResynthesizer] which can deserialize it, along with any 613 * [_TestSummaryResynthesizer] which can deserialize it, along with any
612 * references it makes to `dart:core`. 614 * references it makes to `dart:core`.
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 } 1001 }
1000 1002
1001 test_class_type_parameters_f_bound_simple() { 1003 test_class_type_parameters_f_bound_simple() {
1002 checkLibrary('class C<T extends U, U> {}'); 1004 checkLibrary('class C<T extends U, U> {}');
1003 } 1005 }
1004 1006
1005 test_classes() { 1007 test_classes() {
1006 checkLibrary('class C {} class D {}'); 1008 checkLibrary('class C {} class D {}');
1007 } 1009 }
1008 1010
1011 test_const_reference_type() {
Paul Berry 2016/01/31 13:41:02 There should be a test case for the problem mentio
scheglov 2016/01/31 18:55:29 Done.
1012 shouldCompareConstValues = true;
1013 checkLibrary(r'''
1014 class C {}
1015 enum E {a, b, c}
1016 typedef F(int a, String b);
1017 const vDynamic = dynamic;
1018 const vNull = Null;
1019 const vObject = Object;
1020 const vClass = C;
1021 const vEnum = E;
1022 const vFunctionTypeAlias = F;
1023 ''');
1024 }
1025
1026 test_const_reference_type_imported() {
1027 shouldCompareConstValues = true;
1028 addLibrarySource(
1029 '/a.dart',
1030 r'''
1031 class C {}
1032 enum E {a, b, c}
1033 typedef F(int a, String b);
1034 ''');
1035 checkLibrary(r'''
1036 import 'a.dart';
1037 const vClass = C;
1038 const vEnum = E;
1039 const vFunctionTypeAlias = F;
1040 ''');
1041 }
1042
1043 test_const_reference_type_imported_withPrefix() {
1044 shouldCompareConstValues = true;
1045 addLibrarySource(
1046 '/a.dart',
1047 r'''
1048 class C {}
1049 enum E {a, b, c}
1050 typedef F(int a, String b);
1051 ''');
1052 checkLibrary(r'''
1053 import 'a.dart' as p;
1054 const vClass = p.C;
1055 const vEnum = p.E;
1056 const vFunctionTypeAlias = p.F;
1057 ''');
1058 }
1059
1009 test_const_topLevel_binary() { 1060 test_const_topLevel_binary() {
1010 shouldCompareConstValues = true; 1061 shouldCompareConstValues = true;
1011 checkLibrary(r''' 1062 checkLibrary(r'''
1012 const vEqual = 1 == 2; 1063 const vEqual = 1 == 2;
1013 const vAnd = true && false; 1064 const vAnd = true && false;
1014 const vOr = false || true; 1065 const vOr = false || true;
1015 const vBitXor = 1 ^ 2; 1066 const vBitXor = 1 ^ 2;
1016 const vBitAnd = 1 & 2; 1067 const vBitAnd = 1 & 2;
1017 const vBitOr = 1 | 2; 1068 const vBitOr = 1 | 2;
1018 const vBitShiftLeft = 1 << 2; 1069 const vBitShiftLeft = 1 << 2;
(...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after
2078 fail('Unexpectedly tried to get unlinked summary for $uri'); 2129 fail('Unexpectedly tried to get unlinked summary for $uri');
2079 } 2130 }
2080 return serializedUnit; 2131 return serializedUnit;
2081 } 2132 }
2082 2133
2083 @override 2134 @override
2084 bool hasLibrarySummary(String uri) { 2135 bool hasLibrarySummary(String uri) {
2085 return true; 2136 return true;
2086 } 2137 }
2087 } 2138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698