Chromium Code Reviews| 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 library test.services.refactoring.move_files; | 5 library test.services.refactoring.move_files; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 10 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| 11 import 'package:analyzer/source/package_map_resolver.dart'; | 11 import 'package:analyzer/source/package_map_resolver.dart'; |
| 12 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
| 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 15 | 15 |
| 16 import '../../abstract_context.dart'; | 16 import '../../abstract_context.dart'; |
| 17 import '../../utils.dart'; | 17 import '../../utils.dart'; |
| 18 import 'abstract_refactoring.dart'; | 18 import 'abstract_refactoring.dart'; |
| 19 | 19 |
| 20 main() { | 20 main() { |
| 21 initializeTestEnvironment(); | 21 initializeTestEnvironment(); |
| 22 defineReflectiveTests(MoveFileTest); | 22 defineReflectiveTests(MoveFileTest); |
| 23 } | 23 } |
| 24 | 24 |
| 25 @reflectiveTest | 25 @reflectiveTest |
| 26 class MoveFileTest extends RefactoringTest { | 26 class MoveFileTest extends RefactoringTest { |
| 27 MoveFileRefactoring refactoring; | 27 MoveFileRefactoring refactoring; |
| 28 | 28 |
| 29 /** | |
| 30 * TODO(scheglov) fix search of units | |
| 31 */ | |
| 32 fail_file_importedLibrary_package() async { | |
|
Brian Wilkerson
2016/03/11 21:50:16
Should we create an issue for this?
| |
| 33 // configure packages | |
| 34 testFile = '/packages/my_pkg/aaa/test.dart'; | |
| 35 provider.newFile(testFile, ''); | |
| 36 Map<String, List<Folder>> packageMap = { | |
| 37 'my_pkg': [provider.getResource('/packages/my_pkg')] | |
| 38 }; | |
| 39 context.sourceFactory = new SourceFactory([ | |
| 40 AbstractContextTest.SDK_RESOLVER, | |
| 41 new PackageMapUriResolver(provider, packageMap), | |
| 42 resourceResolver | |
| 43 ]); | |
| 44 // do testing | |
| 45 String pathA = '/project/bin/a.dart'; | |
| 46 addSource( | |
| 47 pathA, | |
| 48 ''' | |
| 49 import 'package:my_pkg/aaa/test.dart'; | |
| 50 '''); | |
| 51 addTestSource(''); | |
| 52 _performAnalysis(); | |
| 53 // perform refactoring | |
| 54 _createRefactoring('/packages/my_pkg/bbb/ccc/new_name.dart'); | |
| 55 await _assertSuccessfulRefactoring(); | |
| 56 assertFileChangeResult( | |
| 57 pathA, | |
| 58 ''' | |
| 59 import 'package:my_pkg/bbb/ccc/new_name.dart'; | |
| 60 '''); | |
| 61 assertNoFileChange(testFile); | |
| 62 } | |
| 63 | |
| 29 test_file_definingUnit() async { | 64 test_file_definingUnit() async { |
| 30 String pathA = '/project/000/1111/a.dart'; | 65 String pathA = '/project/000/1111/a.dart'; |
| 31 String pathB = '/project/000/1111/b.dart'; | 66 String pathB = '/project/000/1111/b.dart'; |
| 32 String pathC = '/project/000/1111/22/c.dart'; | 67 String pathC = '/project/000/1111/22/c.dart'; |
| 33 String pathD = '/project/000/1111/333/d.dart'; | 68 String pathD = '/project/000/1111/333/d.dart'; |
| 34 testFile = '/project/000/1111/test.dart'; | 69 testFile = '/project/000/1111/test.dart'; |
| 35 addSource('/absolute/uri.dart', ''); | 70 addSource('/absolute/uri.dart', ''); |
| 36 addSource(pathA, 'part of lib;'); | 71 addSource(pathA, 'part of lib;'); |
| 37 addSource(pathB, "import 'test.dart';"); | 72 addSource(pathB, "import 'test.dart';"); |
| 38 addSource(pathC, ''); | 73 addSource(pathC, ''); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 _createRefactoring('/project/000/1111/22/new_name.dart'); | 134 _createRefactoring('/project/000/1111/22/new_name.dart'); |
| 100 await _assertSuccessfulRefactoring(); | 135 await _assertSuccessfulRefactoring(); |
| 101 assertFileChangeResult( | 136 assertFileChangeResult( |
| 102 pathA, | 137 pathA, |
| 103 ''' | 138 ''' |
| 104 import '22/new_name.dart'; | 139 import '22/new_name.dart'; |
| 105 '''); | 140 '''); |
| 106 assertNoFileChange(testFile); | 141 assertNoFileChange(testFile); |
| 107 } | 142 } |
| 108 | 143 |
| 109 test_file_importedLibrary_package() async { | |
| 110 // configure packages | |
| 111 testFile = '/packages/my_pkg/aaa/test.dart'; | |
| 112 provider.newFile(testFile, ''); | |
| 113 Map<String, List<Folder>> packageMap = { | |
| 114 'my_pkg': [provider.getResource('/packages/my_pkg')] | |
| 115 }; | |
| 116 context.sourceFactory = new SourceFactory([ | |
| 117 AbstractContextTest.SDK_RESOLVER, | |
| 118 new PackageMapUriResolver(provider, packageMap), | |
| 119 resourceResolver | |
| 120 ]); | |
| 121 // do testing | |
| 122 String pathA = '/project/bin/a.dart'; | |
| 123 addSource( | |
| 124 pathA, | |
| 125 ''' | |
| 126 import 'package:my_pkg/aaa/test.dart'; | |
| 127 '''); | |
| 128 addTestSource(''); | |
| 129 _performAnalysis(); | |
| 130 // perform refactoring | |
| 131 _createRefactoring('/packages/my_pkg/bbb/ccc/new_name.dart'); | |
| 132 await _assertSuccessfulRefactoring(); | |
| 133 assertFileChangeResult( | |
| 134 pathA, | |
| 135 ''' | |
| 136 import 'package:my_pkg/bbb/ccc/new_name.dart'; | |
| 137 '''); | |
| 138 assertNoFileChange(testFile); | |
| 139 } | |
| 140 | |
| 141 test_file_importedLibrary_up() async { | 144 test_file_importedLibrary_up() async { |
| 142 String pathA = '/project/000/1111/a.dart'; | 145 String pathA = '/project/000/1111/a.dart'; |
| 143 testFile = '/project/000/1111/22/test.dart'; | 146 testFile = '/project/000/1111/22/test.dart'; |
| 144 addSource( | 147 addSource( |
| 145 pathA, | 148 pathA, |
| 146 ''' | 149 ''' |
| 147 import '22/test.dart'; | 150 import '22/test.dart'; |
| 148 '''); | 151 '''); |
| 149 addTestSource(''); | 152 addTestSource(''); |
| 150 _performAnalysis(); | 153 _performAnalysis(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 } | 287 } |
| 285 | 288 |
| 286 void _performAnalysis() { | 289 void _performAnalysis() { |
| 287 while (true) { | 290 while (true) { |
| 288 AnalysisResult result = context.performAnalysisTask(); | 291 AnalysisResult result = context.performAnalysisTask(); |
| 289 if (!result.hasMoreWork) { | 292 if (!result.hasMoreWork) { |
| 290 break; | 293 break; |
| 291 } | 294 } |
| 292 for (ChangeNotice notice in result.changeNotices) { | 295 for (ChangeNotice notice in result.changeNotices) { |
| 293 if (notice.source.fullName.startsWith('/project/')) { | 296 if (notice.source.fullName.startsWith('/project/')) { |
| 294 index.index(context, notice.resolvedDartUnit); | 297 index.indexUnit(notice.resolvedDartUnit); |
| 295 } | 298 } |
| 296 } | 299 } |
| 297 } | 300 } |
| 298 } | 301 } |
| 299 } | 302 } |
| OLD | NEW |