| 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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 compareElements(resynthesized, original, desc); | 663 compareElements(resynthesized, original, desc); |
| 664 expect(resynthesized.uri, original.uri); | 664 expect(resynthesized.uri, original.uri); |
| 665 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); | 665 expect(resynthesized.uriOffset, original.uriOffset, reason: desc); |
| 666 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); | 666 expect(resynthesized.uriEnd, original.uriEnd, reason: desc); |
| 667 } | 667 } |
| 668 | 668 |
| 669 void compareVariableElements(VariableElementImpl resynthesized, | 669 void compareVariableElements(VariableElementImpl resynthesized, |
| 670 VariableElementImpl original, String desc) { | 670 VariableElementImpl original, String desc) { |
| 671 compareElements(resynthesized, original, desc); | 671 compareElements(resynthesized, original, desc); |
| 672 compareTypes(resynthesized.type, original.type, desc); | 672 compareTypes(resynthesized.type, original.type, desc); |
| 673 // TODO(scheglov) implement and validate other constant variable types | 673 // TODO(scheglov) enable for any ConstVariableElement |
| 674 if (shouldCompareConstValues && | 674 if (shouldCompareConstValues) { |
| 675 original is ConstTopLevelVariableElementImpl) { | 675 if (original is ConstVariableElement) { |
| 676 compareConstantExpressions(resynthesized.constantInitializer, | 676 compareConstantExpressions(resynthesized.constantInitializer, |
| 677 original.constantInitializer, desc); | 677 original.constantInitializer, desc); |
| 678 } |
| 678 } | 679 } |
| 679 // TODO(paulberry): test initializer | |
| 680 } | 680 } |
| 681 | 681 |
| 682 /** | 682 /** |
| 683 * Serialize the given [library] into a summary. Then create a | 683 * Serialize the given [library] into a summary. Then create a |
| 684 * [_TestSummaryResynthesizer] which can deserialize it, along with any | 684 * [_TestSummaryResynthesizer] which can deserialize it, along with any |
| 685 * references it makes to `dart:core`. | 685 * references it makes to `dart:core`. |
| 686 * | 686 * |
| 687 * Errors will lead to a test failure unless [allowErrors] is `true`. | 687 * Errors will lead to a test failure unless [allowErrors] is `true`. |
| 688 */ | 688 */ |
| 689 _TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library, | 689 _TestSummaryResynthesizer encodeLibrary(LibraryElementImpl library, |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 test_const_length_staticMethod() { | 1326 test_const_length_staticMethod() { |
| 1327 shouldCompareConstValues = true; | 1327 shouldCompareConstValues = true; |
| 1328 checkLibrary(r''' | 1328 checkLibrary(r''' |
| 1329 class C { | 1329 class C { |
| 1330 static int length() => 42; | 1330 static int length() => 42; |
| 1331 } | 1331 } |
| 1332 const v = C.length; | 1332 const v = C.length; |
| 1333 '''); | 1333 '''); |
| 1334 } | 1334 } |
| 1335 | 1335 |
| 1336 test_const_parameterDefaultValue_initializingFormal_functionTyped() { |
| 1337 shouldCompareConstValues = true; |
| 1338 checkLibrary(r''' |
| 1339 class C { |
| 1340 final x; |
| 1341 const C({this.x: foo}); |
| 1342 } |
| 1343 int foo() => 42; |
| 1344 '''); |
| 1345 } |
| 1346 |
| 1347 test_const_parameterDefaultValue_initializingFormal_named() { |
| 1348 shouldCompareConstValues = true; |
| 1349 checkLibrary(r''' |
| 1350 class C { |
| 1351 final x; |
| 1352 const C({this.x: 1 + 2}); |
| 1353 } |
| 1354 '''); |
| 1355 } |
| 1356 |
| 1357 test_const_parameterDefaultValue_initializingFormal_positional() { |
| 1358 shouldCompareConstValues = true; |
| 1359 checkLibrary(r''' |
| 1360 class C { |
| 1361 final x; |
| 1362 const C([this.x = 1 + 2]); |
| 1363 } |
| 1364 '''); |
| 1365 } |
| 1366 |
| 1367 test_const_parameterDefaultValue_normal() { |
| 1368 shouldCompareConstValues = true; |
| 1369 checkLibrary(r''' |
| 1370 class C { |
| 1371 const C.positional([p = 1 + 2]); |
| 1372 const C.named({p: 1 + 2}); |
| 1373 void methodPositional([p = 1 + 2]) {} |
| 1374 void methodNamed({p: 1 + 2}) {} |
| 1375 } |
| 1376 '''); |
| 1377 } |
| 1378 |
| 1336 test_const_reference_staticField() { | 1379 test_const_reference_staticField() { |
| 1337 shouldCompareConstValues = true; | 1380 shouldCompareConstValues = true; |
| 1338 checkLibrary(r''' | 1381 checkLibrary(r''' |
| 1339 class C { | 1382 class C { |
| 1340 static const int F = 42; | 1383 static const int F = 42; |
| 1341 } | 1384 } |
| 1342 const V = C.F; | 1385 const V = C.F; |
| 1343 '''); | 1386 '''); |
| 1344 } | 1387 } |
| 1345 | 1388 |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1796 } | 1839 } |
| 1797 | 1840 |
| 1798 test_field_propagatedType_const_noDep() { | 1841 test_field_propagatedType_const_noDep() { |
| 1799 checkLibrary(''' | 1842 checkLibrary(''' |
| 1800 class C { | 1843 class C { |
| 1801 static const x = 0; | 1844 static const x = 0; |
| 1802 }'''); | 1845 }'''); |
| 1803 } | 1846 } |
| 1804 | 1847 |
| 1805 test_field_propagatedType_final_dep_inLib() { | 1848 test_field_propagatedType_final_dep_inLib() { |
| 1806 addNamedSource('/a.dart', 'final a = 1;'); | 1849 addLibrarySource('/a.dart', 'final a = 1;'); |
| 1807 checkLibrary(''' | 1850 checkLibrary(''' |
| 1808 import "a.dart"; | 1851 import "a.dart"; |
| 1809 class C { | 1852 class C { |
| 1810 final b = a / 2; | 1853 final b = a / 2; |
| 1811 }'''); | 1854 }'''); |
| 1812 } | 1855 } |
| 1813 | 1856 |
| 1814 test_field_propagatedType_final_dep_inPart() { | 1857 test_field_propagatedType_final_dep_inPart() { |
| 1815 addNamedSource('/a.dart', 'part of lib; final a = 1;'); | 1858 addNamedSource('/a.dart', 'part of lib; final a = 1;'); |
| 1816 checkLibrary(''' | 1859 checkLibrary(''' |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2619 fail('Unexpectedly tried to get unlinked summary for $uri'); | 2662 fail('Unexpectedly tried to get unlinked summary for $uri'); |
| 2620 } | 2663 } |
| 2621 return serializedUnit; | 2664 return serializedUnit; |
| 2622 } | 2665 } |
| 2623 | 2666 |
| 2624 @override | 2667 @override |
| 2625 bool hasLibrarySummary(String uri) { | 2668 bool hasLibrarySummary(String uri) { |
| 2626 return true; | 2669 return true; |
| 2627 } | 2670 } |
| 2628 } | 2671 } |
| OLD | NEW |