| 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_context.dart'; |
| 15 import 'package:analysis_testing/abstract_single_unit.dart'; | 16 import 'package:analysis_testing/abstract_single_unit.dart'; |
| 16 import 'package:analysis_testing/reflective_tests.dart'; | 17 import 'package:analysis_testing/reflective_tests.dart'; |
| 18 import 'package:analyzer/file_system/file_system.dart'; |
| 19 import 'package:analyzer/source/package_map_resolver.dart'; |
| 17 import 'package:analyzer/src/generated/error.dart'; | 20 import 'package:analyzer/src/generated/error.dart'; |
| 21 import 'package:analyzer/src/generated/source.dart'; |
| 18 import 'package:unittest/unittest.dart'; | 22 import 'package:unittest/unittest.dart'; |
| 19 | 23 |
| 20 | 24 |
| 21 main() { | 25 main() { |
| 22 groupSep = ' | '; | 26 groupSep = ' | '; |
| 23 runReflectiveTests(FixProcessorTest); | 27 runReflectiveTests(FixProcessorTest); |
| 24 } | 28 } |
| 25 | 29 |
| 26 | 30 |
| 27 @ReflectiveTestCase() | 31 @ReflectiveTestCase() |
| (...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 print(0) | 855 print(0) |
| 852 } | 856 } |
| 853 '''); | 857 '''); |
| 854 assertHasFix(FixKind.INSERT_SEMICOLON, ''' | 858 assertHasFix(FixKind.INSERT_SEMICOLON, ''' |
| 855 main() { | 859 main() { |
| 856 print(0); | 860 print(0); |
| 857 } | 861 } |
| 858 '''); | 862 '''); |
| 859 } | 863 } |
| 860 | 864 |
| 861 void test_importLibraryPrefix_withType() { | 865 void test_importLibraryPackage_withType() { |
| 866 provider.newFile('/packages/my_pkg/lib/my_lib.dart', ''' |
| 867 library my_lib; |
| 868 class Test {} |
| 869 '''); |
| 870 { |
| 871 Folder myPkgFolder = provider.getResource('/packages/my_pkg/lib'); |
| 872 UriResolver pkgResolver = new PackageMapUriResolver(provider, { |
| 873 'my_pkg': [myPkgFolder] |
| 874 }); |
| 875 context.sourceFactory = new SourceFactory( |
| 876 [AbstractContextTest.SDK_RESOLVER, resourceResolver, pkgResolver]); |
| 877 } |
| 878 // force 'my_pkg' resolution |
| 879 addSource('/tmp/other.dart', "import 'package:my_pkg/my_lib.dart';"); |
| 880 // try to find a fix |
| 862 _indexTestUnit(''' | 881 _indexTestUnit(''' |
| 863 import 'dart:async' as pref; | |
| 864 main() { | 882 main() { |
| 865 pref.Stream s = null; | 883 Test test = null; |
| 866 Future f = null; | |
| 867 } | 884 } |
| 868 '''); | 885 '''); |
| 869 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, ''' | 886 performAllAnalysisTasks(); |
| 870 import 'dart:async' as pref; | 887 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' |
| 888 import 'package:my_pkg/my_lib.dart'; |
| 889 |
| 871 main() { | 890 main() { |
| 872 pref.Stream s = null; | 891 Test test = null; |
| 873 pref.Future f = null; | |
| 874 } | 892 } |
| 875 '''); | 893 '''); |
| 876 } | 894 } |
| 877 | 895 |
| 878 void test_importLibraryPrefix_withTopLevelVariable() { | 896 void test_importLibraryPrefix_withTopLevelVariable() { |
| 879 _indexTestUnit(''' | 897 _indexTestUnit(''' |
| 880 import 'dart:math' as pref; | 898 import 'dart:math' as pref; |
| 881 main() { | 899 main() { |
| 882 print(pref.E); | 900 print(pref.E); |
| 883 print(PI); | 901 print(PI); |
| 884 } | 902 } |
| 885 '''); | 903 '''); |
| 886 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, ''' | 904 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, ''' |
| 887 import 'dart:math' as pref; | 905 import 'dart:math' as pref; |
| 888 main() { | 906 main() { |
| 889 print(pref.E); | 907 print(pref.E); |
| 890 print(pref.PI); | 908 print(pref.PI); |
| 891 } | 909 } |
| 892 '''); | 910 '''); |
| 893 } | 911 } |
| 894 | 912 |
| 913 void test_importLibraryPrefix_withType() { |
| 914 _indexTestUnit(''' |
| 915 import 'dart:async' as pref; |
| 916 main() { |
| 917 pref.Stream s = null; |
| 918 Future f = null; |
| 919 } |
| 920 '''); |
| 921 assertHasFix(FixKind.IMPORT_LIBRARY_PREFIX, ''' |
| 922 import 'dart:async' as pref; |
| 923 main() { |
| 924 pref.Stream s = null; |
| 925 pref.Future f = null; |
| 926 } |
| 927 '''); |
| 928 } |
| 929 |
| 895 void test_importLibraryProject_withFunction() { | 930 void test_importLibraryProject_withFunction() { |
| 896 addSource('/lib.dart', ''' | 931 addSource('/lib.dart', ''' |
| 897 library lib; | 932 library lib; |
| 898 myFunction() {} | 933 myFunction() {} |
| 899 '''); | 934 '''); |
| 900 _indexTestUnit(''' | 935 _indexTestUnit(''' |
| 901 main() { | 936 main() { |
| 902 myFunction(); | 937 myFunction(); |
| 903 } | 938 } |
| 904 '''); | 939 '''); |
| 905 performAllAnalysisTasks(); | 940 performAllAnalysisTasks(); |
| 906 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' | 941 assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' |
| 907 import 'lib.dart'; | 942 import 'lib.dart'; |
| 908 | 943 |
| 909 main() { | 944 main() { |
| 910 myFunction(); | 945 myFunction(); |
| 911 } | 946 } |
| 912 '''); | 947 '''); |
| 913 } | 948 } |
| 914 | 949 |
| 915 void test_importLibraryPackage_withType() { | |
| 916 // TODO(scheglov) move PackageMapUriResolver into analyzer and implement | |
| 917 provider.newFile('/packages/my_pkg/lib/my_lib.dart', ''' | |
| 918 //library my_lib; | |
| 919 //class Test {} | |
| 920 //'''); | |
| 921 // testFile = '/project/test.dart'; | |
| 922 // addSource('/tmp/other.dart', "import 'package:my_pkg/my_lib.dart';"); | |
| 923 // _indexTestUnit(''' | |
| 924 //main() { | |
| 925 // Test test = null; | |
| 926 //} | |
| 927 //'''); | |
| 928 // performAllAnalysisTasks(); | |
| 929 // assertHasFix(FixKind.IMPORT_LIBRARY_PROJECT, ''' | |
| 930 //import 'package:my_pkg/my_lib.dart'; | |
| 931 // | |
| 932 //main() { | |
| 933 // Test test = null; | |
| 934 //} | |
| 935 //'''); | |
| 936 } | |
| 937 | |
| 938 void test_importLibraryProject_withTopLevelVariable() { | 950 void test_importLibraryProject_withTopLevelVariable() { |
| 939 addSource('/lib.dart', ''' | 951 addSource('/lib.dart', ''' |
| 940 library lib; | 952 library lib; |
| 941 int MY_VAR = 42; | 953 int MY_VAR = 42; |
| 942 '''); | 954 '''); |
| 943 _indexTestUnit(''' | 955 _indexTestUnit(''' |
| 944 main() { | 956 main() { |
| 945 print(MY_VAR); | 957 print(MY_VAR); |
| 946 } | 958 } |
| 947 '''); | 959 '''); |
| (...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1855 positions.add(new Position(testFile, offset, length)); | 1867 positions.add(new Position(testFile, offset, length)); |
| 1856 } | 1868 } |
| 1857 return positions; | 1869 return positions; |
| 1858 } | 1870 } |
| 1859 | 1871 |
| 1860 void _indexTestUnit(String code) { | 1872 void _indexTestUnit(String code) { |
| 1861 resolveTestUnit(code); | 1873 resolveTestUnit(code); |
| 1862 index.indexUnit(context, testUnit); | 1874 index.indexUnit(context, testUnit); |
| 1863 } | 1875 } |
| 1864 } | 1876 } |
| OLD | NEW |