Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 } | 234 } |
| 235 if (o == null) { | 235 if (o == null) { |
| 236 expect(r, isNull, reason: desc); | 236 expect(r, isNull, reason: desc); |
| 237 } else { | 237 } else { |
| 238 expect(r, isNotNull, reason: desc); | 238 expect(r, isNotNull, reason: desc); |
| 239 compareTypes(r.staticType, o.staticType, desc); | 239 compareTypes(r.staticType, o.staticType, desc); |
| 240 if (o is ParenthesizedExpression) { | 240 if (o is ParenthesizedExpression) { |
| 241 // We don't resynthesize parenthesis, so just ignore it. | 241 // We don't resynthesize parenthesis, so just ignore it. |
| 242 compareConstantExpressions(r, o.expression, desc); | 242 compareConstantExpressions(r, o.expression, desc); |
| 243 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { | 243 } else if (o is SimpleIdentifier && r is SimpleIdentifier) { |
| 244 expect(r.name, o.name); | 244 expect(r.name, o.name); |
|
Paul Berry
2016/02/01 16:11:40
Leave a comment here explaining why we shouldn't c
| |
| 245 compareTypes(r.staticType, o.staticType, desc); | |
| 246 compareElements(r.staticElement, o.staticElement, desc); | 245 compareElements(r.staticElement, o.staticElement, desc); |
| 247 } else if (o is PrefixedIdentifier) { | 246 } else if (o is PrefixedIdentifier) { |
| 248 // We don't resynthesize prefixed identifiers. | 247 // We don't resynthesize prefixed identifiers. |
| 249 // We use simple identifiers with correct elements and types. | 248 // We use simple identifiers with correct elements and types. |
| 250 compareConstantExpressions(r as SimpleIdentifier, o.identifier, desc); | 249 compareConstantExpressions(r as SimpleIdentifier, o.identifier, desc); |
| 251 } else if (o is NullLiteral) { | 250 } else if (o is NullLiteral) { |
| 252 expect(r, new isInstanceOf<NullLiteral>(), reason: desc); | 251 expect(r, new isInstanceOf<NullLiteral>(), reason: desc); |
| 253 } else if (o is BooleanLiteral && r is BooleanLiteral) { | 252 } else if (o is BooleanLiteral && r is BooleanLiteral) { |
| 254 expect(r.value, o.value, reason: desc); | 253 expect(r.value, o.value, reason: desc); |
| 255 } else if (o is IntegerLiteral && r is IntegerLiteral) { | 254 } else if (o is IntegerLiteral && r is IntegerLiteral) { |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 592 compareElements(resynthesized, original, desc); | 591 compareElements(resynthesized, original, desc); |
| 593 expect(resynthesized.uri, original.uri); | 592 expect(resynthesized.uri, original.uri); |
| 594 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); | 593 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); |
| 595 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); | 594 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); |
| 596 } | 595 } |
| 597 | 596 |
| 598 void compareVariableElements(VariableElementImpl resynthesized, | 597 void compareVariableElements(VariableElementImpl resynthesized, |
| 599 VariableElementImpl original, String desc) { | 598 VariableElementImpl original, String desc) { |
| 600 compareElements(resynthesized, original, desc); | 599 compareElements(resynthesized, original, desc); |
| 601 compareTypes(resynthesized.type, original.type, desc); | 600 compareTypes(resynthesized.type, original.type, desc); |
| 602 if (shouldCompareConstValues) { | 601 // TODO(scheglov) implement and validate other constant variable types |
| 602 if (shouldCompareConstValues && | |
| 603 original is ConstTopLevelVariableElementImpl) { | |
| 603 compareConstantExpressions(resynthesized.constantInitializer, | 604 compareConstantExpressions(resynthesized.constantInitializer, |
| 604 original.constantInitializer, desc); | 605 original.constantInitializer, desc); |
| 605 } | 606 } |
| 606 // TODO(paulberry): test initializer | 607 // TODO(paulberry): test initializer |
| 607 } | 608 } |
| 608 | 609 |
| 609 /** | 610 /** |
| 610 * Serialize the given [library] into a summary. Then create a | 611 * Serialize the given [library] into a summary. Then create a |
| 611 * [_TestSummaryResynthesizer] which can deserialize it, along with any | 612 * [_TestSummaryResynthesizer] which can deserialize it, along with any |
| 612 * references it makes to `dart:core`. | 613 * references it makes to `dart:core`. |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 999 } | 1000 } |
| 1000 | 1001 |
| 1001 test_class_type_parameters_f_bound_simple() { | 1002 test_class_type_parameters_f_bound_simple() { |
| 1002 checkLibrary('class C<T extends U, U> {}'); | 1003 checkLibrary('class C<T extends U, U> {}'); |
| 1003 } | 1004 } |
| 1004 | 1005 |
| 1005 test_classes() { | 1006 test_classes() { |
| 1006 checkLibrary('class C {} class D {}'); | 1007 checkLibrary('class C {} class D {}'); |
| 1007 } | 1008 } |
| 1008 | 1009 |
| 1010 test_const_reference_type() { | |
| 1011 shouldCompareConstValues = true; | |
| 1012 checkLibrary(r''' | |
| 1013 class C {} | |
| 1014 class D<T> {} | |
| 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 vGenericClass = D; | |
| 1022 const vEnum = E; | |
| 1023 const vFunctionTypeAlias = F; | |
| 1024 '''); | |
| 1025 } | |
| 1026 | |
| 1027 test_const_reference_type_imported() { | |
| 1028 shouldCompareConstValues = true; | |
| 1029 addLibrarySource( | |
| 1030 '/a.dart', | |
| 1031 r''' | |
| 1032 class C {} | |
| 1033 enum E {a, b, c} | |
| 1034 typedef F(int a, String b); | |
| 1035 '''); | |
| 1036 checkLibrary(r''' | |
| 1037 import 'a.dart'; | |
| 1038 const vClass = C; | |
| 1039 const vEnum = E; | |
| 1040 const vFunctionTypeAlias = F; | |
| 1041 '''); | |
| 1042 } | |
| 1043 | |
| 1044 test_const_reference_type_imported_withPrefix() { | |
| 1045 shouldCompareConstValues = true; | |
| 1046 addLibrarySource( | |
| 1047 '/a.dart', | |
| 1048 r''' | |
| 1049 class C {} | |
| 1050 enum E {a, b, c} | |
| 1051 typedef F(int a, String b); | |
| 1052 '''); | |
| 1053 checkLibrary(r''' | |
| 1054 import 'a.dart' as p; | |
| 1055 const vClass = p.C; | |
| 1056 const vEnum = p.E; | |
| 1057 const vFunctionTypeAlias = p.F; | |
| 1058 '''); | |
| 1059 } | |
| 1060 | |
| 1009 test_const_topLevel_binary() { | 1061 test_const_topLevel_binary() { |
| 1010 shouldCompareConstValues = true; | 1062 shouldCompareConstValues = true; |
| 1011 checkLibrary(r''' | 1063 checkLibrary(r''' |
| 1012 const vEqual = 1 == 2; | 1064 const vEqual = 1 == 2; |
| 1013 const vAnd = true && false; | 1065 const vAnd = true && false; |
| 1014 const vOr = false || true; | 1066 const vOr = false || true; |
| 1015 const vBitXor = 1 ^ 2; | 1067 const vBitXor = 1 ^ 2; |
| 1016 const vBitAnd = 1 & 2; | 1068 const vBitAnd = 1 & 2; |
| 1017 const vBitOr = 1 | 2; | 1069 const vBitOr = 1 | 2; |
| 1018 const vBitShiftLeft = 1 << 2; | 1070 const vBitShiftLeft = 1 << 2; |
| (...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2078 fail('Unexpectedly tried to get unlinked summary for $uri'); | 2130 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 2079 } | 2131 } |
| 2080 return serializedUnit; | 2132 return serializedUnit; |
| 2081 } | 2133 } |
| 2082 | 2134 |
| 2083 @override | 2135 @override |
| 2084 bool hasLibrarySummary(String uri) { | 2136 bool hasLibrarySummary(String uri) { |
| 2085 return true; | 2137 return true; |
| 2086 } | 2138 } |
| 2087 } | 2139 } |
| OLD | NEW |