| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library test.services.correction.fix; | 8 library test.services.correction.fix; |
| 9 | 9 |
| 10 import 'package:analysis_services/correction/change.dart'; | 10 import 'package:analysis_services/correction/change.dart'; |
| 11 import 'package:analysis_services/correction/fix.dart'; | 11 import 'package:analysis_services/correction/fix.dart'; |
| 12 import 'package:analysis_services/index/index.dart'; | 12 import 'package:analysis_services/index/index.dart'; |
| 13 import 'package:analysis_services/index/local_memory_index.dart'; | 13 import 'package:analysis_services/index/local_memory_index.dart'; |
| 14 import 'package:analysis_services/src/search/search_engine.dart'; | 14 import 'package:analysis_services/src/search/search_engine.dart'; |
| 15 import 'package:analysis_testing/abstract_single_unit.dart'; | 15 import 'package:analysis_testing/abstract_single_unit.dart'; |
| 16 import 'package:analysis_testing/reflective_tests.dart'; | 16 import 'package:analysis_testing/reflective_tests.dart'; |
| 17 import 'package:analyzer/src/generated/error.dart'; | 17 import 'package:analyzer/src/generated/error.dart'; |
| 18 import 'package:unittest/unittest.dart'; | 18 import 'package:unittest/unittest.dart'; |
| 19 import 'package:analyzer/src/generated/source.dart'; |
| 19 | 20 |
| 20 | 21 |
| 21 main() { | 22 main() { |
| 22 groupSep = ' | '; | 23 groupSep = ' | '; |
| 23 runReflectiveTests(FixProcessorTest); | 24 runReflectiveTests(FixProcessorTest); |
| 24 } | 25 } |
| 25 | 26 |
| 26 | 27 |
| 27 @ReflectiveTestCase() | 28 @ReflectiveTestCase() |
| 28 class FixProcessorTest extends AbstractSingleUnitTest { | 29 class FixProcessorTest extends AbstractSingleUnitTest { |
| (...skipping 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 print(0) | 852 print(0) |
| 852 } | 853 } |
| 853 '''); | 854 '''); |
| 854 assertHasFix(FixKind.INSERT_SEMICOLON, ''' | 855 assertHasFix(FixKind.INSERT_SEMICOLON, ''' |
| 855 main() { | 856 main() { |
| 856 print(0); | 857 print(0); |
| 857 } | 858 } |
| 858 '''); | 859 '''); |
| 859 } | 860 } |
| 860 | 861 |
| 862 void test_importLibraryPrefix_withType() { |
| 863 _indexTestUnit(''' |
| 864 import 'dart:async' as pref; |
| 865 main() { |
| 866 pref.Stream s = null; |
| 867 Future f = null; |
| 868 } |
| 869 '''); |
| 870 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, ''' |
| 871 import 'dart:async' as pref; |
| 872 main() { |
| 873 pref.Stream s = null; |
| 874 pref.Future f = null; |
| 875 } |
| 876 '''); |
| 877 } |
| 878 |
| 879 void test_importLibraryPrefix_withTopLevelVariable() { |
| 880 _indexTestUnit(''' |
| 881 import 'dart:math' as pref; |
| 882 main() { |
| 883 print(pref.E); |
| 884 print(PI); |
| 885 } |
| 886 '''); |
| 887 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, ''' |
| 888 import 'dart:math' as pref; |
| 889 main() { |
| 890 print(pref.E); |
| 891 print(pref.PI); |
| 892 } |
| 893 '''); |
| 894 } |
| 895 |
| 896 void test_importLibraryProject_withFunction() { |
| 897 addSource('/lib.dart', ''' |
| 898 library lib; |
| 899 myFunction() {} |
| 900 '''); |
| 901 _indexTestUnit(''' |
| 902 main() { |
| 903 myFunction(); |
| 904 } |
| 905 '''); |
| 906 performAllAnalysisTasks(); |
| 907 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' |
| 908 import 'lib.dart'; |
| 909 |
| 910 main() { |
| 911 myFunction(); |
| 912 } |
| 913 '''); |
| 914 } |
| 915 |
| 916 void test_importLibraryPackage_withType() { |
| 917 // TODO(scheglov) move PackageMapUriResolver into analyzer and implement |
| 918 provider.newFile('/packages/my_pkg/lib/my_lib.dart', ''' |
| 919 //library my_lib; |
| 920 //class Test {} |
| 921 //'''); |
| 922 // testFile = '/project/test.dart'; |
| 923 // addSource('/tmp/other.dart', "import 'package:my_pkg/my_lib.dart';"); |
| 924 // _indexTestUnit(''' |
| 925 //main() { |
| 926 // Test test = null; |
| 927 //} |
| 928 //'''); |
| 929 // performAllAnalysisTasks(); |
| 930 // assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' |
| 931 //import 'package:my_pkg/my_lib.dart'; |
| 932 // |
| 933 //main() { |
| 934 // Test test = null; |
| 935 //} |
| 936 //'''); |
| 937 } |
| 938 |
| 939 void test_importLibraryProject_withTopLevelVariable() { |
| 940 addSource('/lib.dart', ''' |
| 941 library lib; |
| 942 int MY_VAR = 42; |
| 943 '''); |
| 944 _indexTestUnit(''' |
| 945 main() { |
| 946 print(MY_VAR); |
| 947 } |
| 948 '''); |
| 949 performAllAnalysisTasks(); |
| 950 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' |
| 951 import 'lib.dart'; |
| 952 |
| 953 main() { |
| 954 print(MY_VAR); |
| 955 } |
| 956 '''); |
| 957 } |
| 958 |
| 959 void test_importLibraryProject_withType_inParentFolder() { |
| 960 testFile = '/project/bin/test.dart'; |
| 961 addSource('/project/lib.dart', ''' |
| 962 library lib; |
| 963 class Test {} |
| 964 '''); |
| 965 _indexTestUnit(''' |
| 966 main() { |
| 967 Test t = null; |
| 968 } |
| 969 '''); |
| 970 performAllAnalysisTasks(); |
| 971 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' |
| 972 import '../lib.dart'; |
| 973 |
| 974 main() { |
| 975 Test t = null; |
| 976 } |
| 977 '''); |
| 978 } |
| 979 |
| 980 void test_importLibraryProject_withType_inRelativeFolder() { |
| 981 testFile = '/project/bin/test.dart'; |
| 982 addSource('/project/lib/sub/folder/lib.dart', ''' |
| 983 library lib; |
| 984 class Test {} |
| 985 '''); |
| 986 _indexTestUnit(''' |
| 987 main() { |
| 988 Test t = null; |
| 989 } |
| 990 '''); |
| 991 performAllAnalysisTasks(); |
| 992 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' |
| 993 import '../lib/sub/folder/lib.dart'; |
| 994 |
| 995 main() { |
| 996 Test t = null; |
| 997 } |
| 998 '''); |
| 999 } |
| 1000 |
| 1001 void test_importLibraryProject_withType_inSameFolder() { |
| 1002 testFile = '/project/bin/test.dart'; |
| 1003 addSource('/project/bin/lib.dart', ''' |
| 1004 library lib; |
| 1005 class Test {} |
| 1006 '''); |
| 1007 _indexTestUnit(''' |
| 1008 main() { |
| 1009 Test t = null; |
| 1010 } |
| 1011 '''); |
| 1012 performAllAnalysisTasks(); |
| 1013 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' |
| 1014 import 'lib.dart'; |
| 1015 |
| 1016 main() { |
| 1017 Test t = null; |
| 1018 } |
| 1019 '''); |
| 1020 } |
| 1021 |
| 1022 void test_importLibrarySdk_withTopLevelVariable() { |
| 1023 _ensureSdkMathLibraryResolved(); |
| 1024 _indexTestUnit(''' |
| 1025 main() { |
| 1026 print(PI); |
| 1027 } |
| 1028 '''); |
| 1029 performAllAnalysisTasks(); |
| 1030 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' |
| 1031 import 'dart:math'; |
| 1032 |
| 1033 main() { |
| 1034 print(PI); |
| 1035 } |
| 1036 '''); |
| 1037 } |
| 1038 |
| 1039 void test_importLibrarySdk_withType_invocationTarget() { |
| 1040 _ensureSdkAsyncLibraryResolved(); |
| 1041 _indexTestUnit(''' |
| 1042 main() { |
| 1043 Future.wait(null); |
| 1044 } |
| 1045 '''); |
| 1046 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' |
| 1047 import 'dart:async'; |
| 1048 |
| 1049 main() { |
| 1050 Future.wait(null); |
| 1051 } |
| 1052 '''); |
| 1053 } |
| 1054 |
| 1055 void test_importLibrarySdk_withType_typeAnnotation() { |
| 1056 _ensureSdkAsyncLibraryResolved(); |
| 1057 _indexTestUnit(''' |
| 1058 main() { |
| 1059 Future f = null; |
| 1060 } |
| 1061 '''); |
| 1062 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' |
| 1063 import 'dart:async'; |
| 1064 |
| 1065 main() { |
| 1066 Future f = null; |
| 1067 } |
| 1068 '''); |
| 1069 } |
| 1070 |
| 1071 void test_importLibrarySdk_withType_typeAnnotation_PrefixedIdentifier() { |
| 1072 _ensureSdkAsyncLibraryResolved(); |
| 1073 _indexTestUnit(''' |
| 1074 main() { |
| 1075 Future.wait; |
| 1076 } |
| 1077 '''); |
| 1078 assertHasFix(FixKind.IMPORT_LIBRARY_SDK, ''' |
| 1079 import 'dart:async'; |
| 1080 |
| 1081 main() { |
| 1082 Future.wait; |
| 1083 } |
| 1084 '''); |
| 1085 } |
| 1086 |
| 1087 void test_importLibraryShow() { |
| 1088 _indexTestUnit(''' |
| 1089 import 'dart:async' show Stream; |
| 1090 main() { |
| 1091 Stream s = null; |
| 1092 Future f = null; |
| 1093 } |
| 1094 '''); |
| 1095 assertHasFix(FixKind.IMPORT_LIBRARY_SHOW, ''' |
| 1096 import 'dart:async' show Future, Stream; |
| 1097 main() { |
| 1098 Stream s = null; |
| 1099 Future f = null; |
| 1100 } |
| 1101 '''); |
| 1102 } |
| 1103 |
| 861 void test_isNotNull() { | 1104 void test_isNotNull() { |
| 862 _indexTestUnit(''' | 1105 _indexTestUnit(''' |
| 863 main(p) { | 1106 main(p) { |
| 864 p is! Null; | 1107 p is! Null; |
| 865 } | 1108 } |
| 866 '''); | 1109 '''); |
| 867 assertHasFix(FixKind.USE_NOT_EQ_NULL, ''' | 1110 assertHasFix(FixKind.USE_NOT_EQ_NULL, ''' |
| 868 main(p) { | 1111 main(p) { |
| 869 p != null; | 1112 p != null; |
| 870 } | 1113 } |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1572 List<LinkedPositionGroup> groups = change.linkedPositionGroups; | 1815 List<LinkedPositionGroup> groups = change.linkedPositionGroups; |
| 1573 for (LinkedPositionGroup group in groups) { | 1816 for (LinkedPositionGroup group in groups) { |
| 1574 if (group.id == groupId) { | 1817 if (group.id == groupId) { |
| 1575 expect(group.proposals, expected); | 1818 expect(group.proposals, expected); |
| 1576 return; | 1819 return; |
| 1577 } | 1820 } |
| 1578 } | 1821 } |
| 1579 fail('No group with ID=$groupId foind in\n${groups.join('\n')}'); | 1822 fail('No group with ID=$groupId foind in\n${groups.join('\n')}'); |
| 1580 } | 1823 } |
| 1581 | 1824 |
| 1825 /** |
| 1826 * We search for elements only already resolved lbiraries, and we use |
| 1827 * `dart:async` elements in tests. |
| 1828 */ |
| 1829 void _ensureSdkAsyncLibraryResolved() { |
| 1830 resolveLibraryUnit(addSource('/other.dart', 'import "dart:async";')); |
| 1831 } |
| 1832 |
| 1833 /** |
| 1834 * We search for elements only already resolved lbiraries, and we use |
| 1835 * `dart:async` elements in tests. |
| 1836 */ |
| 1837 void _ensureSdkMathLibraryResolved() { |
| 1838 resolveLibraryUnit(addSource('/other.dart', 'import "dart:math";')); |
| 1839 } |
| 1840 |
| 1582 AnalysisError _findErrorToFix() { | 1841 AnalysisError _findErrorToFix() { |
| 1583 List<AnalysisError> errors = context.computeErrors(testSource); | 1842 List<AnalysisError> errors = context.computeErrors(testSource); |
| 1584 expect( | 1843 expect( |
| 1585 errors, | 1844 errors, |
| 1586 hasLength(1), | 1845 hasLength(1), |
| 1587 reason: 'Exactly 1 error expected, but ${errors.length} found:\n' + | 1846 reason: 'Exactly 1 error expected, but ${errors.length} found:\n' + |
| 1588 errors.join('\n')); | 1847 errors.join('\n')); |
| 1589 return errors[0]; | 1848 return errors[0]; |
| 1590 } | 1849 } |
| 1591 | 1850 |
| 1592 List<Position> _findResultPositions(List<String> searchStrings) { | 1851 List<Position> _findResultPositions(List<String> searchStrings) { |
| 1593 List<Position> positions = <Position>[]; | 1852 List<Position> positions = <Position>[]; |
| 1594 for (String search in searchStrings) { | 1853 for (String search in searchStrings) { |
| 1595 int offset = resultCode.indexOf(search); | 1854 int offset = resultCode.indexOf(search); |
| 1596 int length = getLeadingIdentifierLength(search); | 1855 int length = getLeadingIdentifierLength(search); |
| 1597 positions.add(new Position(testFile, offset, length)); | 1856 positions.add(new Position(testFile, offset, length)); |
| 1598 } | 1857 } |
| 1599 return positions; | 1858 return positions; |
| 1600 } | 1859 } |
| 1601 | 1860 |
| 1602 void _indexTestUnit(String code) { | 1861 void _indexTestUnit(String code) { |
| 1603 resolveTestUnit(code); | 1862 resolveTestUnit(code); |
| 1604 index.indexUnit(context, testUnit); | 1863 index.indexUnit(context, testUnit); |
| 1605 } | 1864 } |
| 1606 } | 1865 } |
| OLD | NEW |