| 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/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/dart/element/type.dart'; | 8 import 'package:analyzer/dart/element/type.dart'; |
| 9 import 'package:analyzer/src/dart/element/element.dart'; | 9 import 'package:analyzer/src/dart/element/element.dart'; |
| 10 import 'package:analyzer/src/dart/element/type.dart'; | 10 import 'package:analyzer/src/dart/element/type.dart'; |
| 11 import 'package:analyzer/src/generated/constant.dart'; |
| 11 import 'package:analyzer/src/generated/element_handle.dart'; | 12 import 'package:analyzer/src/generated/element_handle.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 13 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/resolver.dart' | 14 import 'package:analyzer/src/generated/resolver.dart' |
| 14 show Namespace, TypeProvider; | 15 show Namespace, TypeProvider; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 16 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:analyzer/src/summary/format.dart'; | 17 import 'package:analyzer/src/summary/format.dart'; |
| 17 import 'package:analyzer/src/summary/resynthesize.dart'; | 18 import 'package:analyzer/src/summary/resynthesize.dart'; |
| 18 import 'package:analyzer/src/summary/summarize_elements.dart'; | 19 import 'package:analyzer/src/summary/summarize_elements.dart'; |
| 19 import 'package:unittest/unittest.dart'; | 20 import 'package:unittest/unittest.dart'; |
| 20 | 21 |
| 21 import '../../generated/resolver_test.dart'; | 22 import '../../generated/resolver_test.dart'; |
| 22 import '../../reflective_tests.dart'; | 23 import '../../reflective_tests.dart'; |
| 23 | 24 |
| 24 main() { | 25 main() { |
| 25 groupSep = ' | '; | 26 groupSep = ' | '; |
| 26 runReflectiveTests(ResynthTest); | 27 runReflectiveTests(ResynthTest); |
| 27 } | 28 } |
| 28 | 29 |
| 29 @reflectiveTest | 30 @reflectiveTest |
| 30 class ResynthTest extends ResolverTestCase { | 31 class ResynthTest extends ResolverTestCase { |
| 31 Set<Source> otherLibrarySources = new Set<Source>(); | 32 Set<Source> otherLibrarySources = new Set<Source>(); |
| 33 bool shouldCompareConstValues = false; |
| 32 | 34 |
| 33 /** | 35 /** |
| 34 * Determine the analysis options that should be used for this test. | 36 * Determine the analysis options that should be used for this test. |
| 35 */ | 37 */ |
| 36 AnalysisOptionsImpl get options => | 38 AnalysisOptionsImpl get options => |
| 37 new AnalysisOptionsImpl()..enableGenericMethods = true; | 39 new AnalysisOptionsImpl()..enableGenericMethods = true; |
| 38 | 40 |
| 39 void addLibrary(String uri) { | 41 void addLibrary(String uri) { |
| 40 otherLibrarySources.add(analysisContext2.sourceFactory.forUri(uri)); | 42 otherLibrarySources.add(analysisContext2.sourceFactory.forUri(uri)); |
| 41 } | 43 } |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 comparePropertyAccessorElements(resynthesized.accessors[i], | 196 comparePropertyAccessorElements(resynthesized.accessors[i], |
| 195 original.accessors[i], 'getter ${original.accessors[i].name}'); | 197 original.accessors[i], 'getter ${original.accessors[i].name}'); |
| 196 } else { | 198 } else { |
| 197 comparePropertyAccessorElements(resynthesized.accessors[i], | 199 comparePropertyAccessorElements(resynthesized.accessors[i], |
| 198 original.accessors[i], 'setter ${original.accessors[i].name}'); | 200 original.accessors[i], 'setter ${original.accessors[i].name}'); |
| 199 } | 201 } |
| 200 } | 202 } |
| 201 // TODO(paulberry): test metadata and offsetToElementMap. | 203 // TODO(paulberry): test metadata and offsetToElementMap. |
| 202 } | 204 } |
| 203 | 205 |
| 206 void compareConstantValues( |
| 207 DartObject resynthesized, DartObject original, String desc) { |
| 208 if (original == null) { |
| 209 expect(resynthesized, isNull, reason: desc); |
| 210 } else { |
| 211 expect(resynthesized, isNotNull, reason: desc); |
| 212 compareTypes(resynthesized.type, original.type, desc); |
| 213 expect(resynthesized.hasKnownValue, original.hasKnownValue, reason: desc); |
| 214 if (original.isNull) { |
| 215 expect(resynthesized.isNull, isTrue, reason: desc); |
| 216 } else if (original.toBoolValue() != null) { |
| 217 expect(resynthesized.toBoolValue(), original.toBoolValue(), |
| 218 reason: desc); |
| 219 } else if (original.toIntValue() != null) { |
| 220 expect(resynthesized.toIntValue(), original.toIntValue(), reason: desc); |
| 221 } else if (original.toDoubleValue() != null) { |
| 222 expect(resynthesized.toDoubleValue(), original.toDoubleValue(), |
| 223 reason: desc); |
| 224 } else if (original.toListValue() != null) { |
| 225 fail('Not implemented'); |
| 226 } else if (original.toMapValue() != null) { |
| 227 fail('Not implemented'); |
| 228 } else if (original.toStringValue() != null) { |
| 229 expect(resynthesized.toStringValue(), original.toStringValue(), |
| 230 reason: desc); |
| 231 } else if (original.toSymbolValue() != null) { |
| 232 fail('Not implemented'); |
| 233 } else if (original.toTypeValue() != null) { |
| 234 fail('Not implemented'); |
| 235 } |
| 236 // TODO(scheglov) implement |
| 237 } |
| 238 } |
| 239 |
| 204 void compareConstructorElements(ConstructorElementImpl resynthesized, | 240 void compareConstructorElements(ConstructorElementImpl resynthesized, |
| 205 ConstructorElementImpl original, String desc) { | 241 ConstructorElementImpl original, String desc) { |
| 206 compareExecutableElements(resynthesized, original, desc); | 242 compareExecutableElements(resynthesized, original, desc); |
| 207 // TODO(paulberry): test redirectedConstructor and constantInitializers | 243 // TODO(paulberry): test redirectedConstructor and constantInitializers |
| 208 } | 244 } |
| 209 | 245 |
| 210 void compareElements(Element resynthesized, Element original, String desc) { | 246 void compareElements(Element resynthesized, Element original, String desc) { |
| 211 expect(resynthesized, isNotNull); | 247 expect(resynthesized, isNotNull); |
| 212 expect(resynthesized.kind, original.kind); | 248 expect(resynthesized.kind, original.kind); |
| 213 expect(resynthesized.location, original.location, reason: desc); | 249 expect(resynthesized.location, original.location, reason: desc); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 compareElements(resynthesized, original, desc); | 538 compareElements(resynthesized, original, desc); |
| 503 expect(resynthesized.uri, original.uri); | 539 expect(resynthesized.uri, original.uri); |
| 504 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); | 540 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); |
| 505 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); | 541 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); |
| 506 } | 542 } |
| 507 | 543 |
| 508 void compareVariableElements(VariableElementImpl resynthesized, | 544 void compareVariableElements(VariableElementImpl resynthesized, |
| 509 VariableElementImpl original, String desc) { | 545 VariableElementImpl original, String desc) { |
| 510 compareElements(resynthesized, original, desc); | 546 compareElements(resynthesized, original, desc); |
| 511 compareTypes(resynthesized.type, original.type, desc); | 547 compareTypes(resynthesized.type, original.type, desc); |
| 548 if (shouldCompareConstValues) { |
| 549 compareConstantValues( |
| 550 resynthesized.constantValue, original.constantValue, desc); |
| 551 } |
| 512 // TODO(paulberry): test initializer | 552 // TODO(paulberry): test initializer |
| 513 } | 553 } |
| 514 | 554 |
| 515 /** | 555 /** |
| 516 * Serialize the given [library] into a summary. Then create a | 556 * Serialize the given [library] into a summary. Then create a |
| 517 * [_TestSummaryResynthesizer] which can deserialize it, along with any | 557 * [_TestSummaryResynthesizer] which can deserialize it, along with any |
| 518 * references it makes to `dart:core`. | 558 * references it makes to `dart:core`. |
| 519 * | 559 * |
| 520 * Errors will lead to a test failure unless [allowErrors] is `true`. | 560 * Errors will lead to a test failure unless [allowErrors] is `true`. |
| 521 */ | 561 */ |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 } | 945 } |
| 906 | 946 |
| 907 test_class_type_parameters_f_bound_simple() { | 947 test_class_type_parameters_f_bound_simple() { |
| 908 checkLibrary('class C<T extends U, U> {}'); | 948 checkLibrary('class C<T extends U, U> {}'); |
| 909 } | 949 } |
| 910 | 950 |
| 911 test_classes() { | 951 test_classes() { |
| 912 checkLibrary('class C {} class D {}'); | 952 checkLibrary('class C {} class D {}'); |
| 913 } | 953 } |
| 914 | 954 |
| 955 test_const_topLevel_literal() { |
| 956 shouldCompareConstValues = true; |
| 957 checkLibrary(r''' |
| 958 const vNull = null; |
| 959 const vBoolFalse = false; |
| 960 const vBoolTrue = true; |
| 961 const vInt = 1; |
| 962 const vDouble = 2.3; |
| 963 const vString = 'abc'; |
| 964 const vStringConcat = 'aaa' 'bbb'; |
| 965 const vStringInterpolation = 'aaa ${true} ${42} bbb'; |
| 966 '''); |
| 967 } |
| 968 |
| 915 test_constructor_documented() { | 969 test_constructor_documented() { |
| 916 checkLibrary(''' | 970 checkLibrary(''' |
| 917 class C { | 971 class C { |
| 918 /** | 972 /** |
| 919 * Docs | 973 * Docs |
| 920 */ | 974 */ |
| 921 C(); | 975 C(); |
| 922 }'''); | 976 }'''); |
| 923 } | 977 } |
| 924 | 978 |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1852 fail('Unexpectedly tried to get unlinked summary for $uri'); | 1906 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 1853 } | 1907 } |
| 1854 return serializedUnit; | 1908 return serializedUnit; |
| 1855 } | 1909 } |
| 1856 | 1910 |
| 1857 @override | 1911 @override |
| 1858 bool hasLibrarySummary(String uri) { | 1912 bool hasLibrarySummary(String uri) { |
| 1859 return true; | 1913 return true; |
| 1860 } | 1914 } |
| 1861 } | 1915 } |
| OLD | NEW |