| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 library test.services.refactoring.move_files; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 11 import 'package:analyzer/src/generated/engine.dart'; |
| 12 import 'package:unittest/unittest.dart'; |
| 13 |
| 14 import '../../reflective_tests.dart'; |
| 15 import 'abstract_refactoring.dart'; |
| 16 |
| 17 |
| 18 main() { |
| 19 groupSep = ' | '; |
| 20 runReflectiveTests(MoveFileTest); |
| 21 } |
| 22 |
| 23 |
| 24 @ReflectiveTestCase() |
| 25 class MoveFileTest extends RefactoringTest { |
| 26 MoveFileRefactoring refactoring; |
| 27 |
| 28 test_definingUnit() { |
| 29 String pathA = '/project/000/1111/a.dart'; |
| 30 String pathB = '/project/000/1111/b.dart'; |
| 31 String pathC = '/project/000/1111/22/c.dart'; |
| 32 String pathD = '/project/000/1111/333/d.dart'; |
| 33 testFile = '/project/000/1111/test.dart'; |
| 34 addSource('/absolute/uri.dart', ''); |
| 35 addSource(pathA, 'part of lib;'); |
| 36 addSource(pathB, "import 'test.dart';"); |
| 37 addSource(pathC, ''); |
| 38 addSource(pathD, ''); |
| 39 addTestSource(''' |
| 40 library lib; |
| 41 import '22/c.dart'; |
| 42 export '333/d.dart'; |
| 43 part 'a.dart'; |
| 44 part '/absolute/uri.dart'; |
| 45 '''); |
| 46 _performAnalysis(); |
| 47 // perform refactoring |
| 48 _createRefactoring('/project/000/1111/22/new_name.dart'); |
| 49 return _assertSuccessfulRefactoring().then((_) { |
| 50 assertNoFileChange(pathA); |
| 51 assertFileChangeResult(pathB, "import '22/new_name.dart';"); |
| 52 assertNoFileChange(pathC); |
| 53 assertFileChangeResult(testFile, ''' |
| 54 library lib; |
| 55 import 'c.dart'; |
| 56 export '../333/d.dart'; |
| 57 part '../a.dart'; |
| 58 part '/absolute/uri.dart'; |
| 59 '''); |
| 60 }); |
| 61 } |
| 62 |
| 63 test_importedLibrary() { |
| 64 String pathA = '/project/000/1111/a.dart'; |
| 65 testFile = '/project/000/1111/sub/folder/test.dart'; |
| 66 addSource(pathA, ''' |
| 67 import 'sub/folder/test.dart'; |
| 68 '''); |
| 69 addTestSource(''); |
| 70 _performAnalysis(); |
| 71 // perform refactoring |
| 72 _createRefactoring('/project/000/new/folder/name/new_name.dart'); |
| 73 return _assertSuccessfulRefactoring().then((_) { |
| 74 assertFileChangeResult(pathA, ''' |
| 75 import '../new/folder/name/new_name.dart'; |
| 76 '''); |
| 77 assertNoFileChange(testFile); |
| 78 }); |
| 79 } |
| 80 |
| 81 test_importedLibrary_down() { |
| 82 String pathA = '/project/000/1111/a.dart'; |
| 83 testFile = '/project/000/1111/test.dart'; |
| 84 addSource(pathA, ''' |
| 85 import 'test.dart'; |
| 86 '''); |
| 87 addTestSource(''); |
| 88 _performAnalysis(); |
| 89 // perform refactoring |
| 90 _createRefactoring('/project/000/1111/22/new_name.dart'); |
| 91 return _assertSuccessfulRefactoring().then((_) { |
| 92 assertFileChangeResult(pathA, ''' |
| 93 import '22/new_name.dart'; |
| 94 '''); |
| 95 assertNoFileChange(testFile); |
| 96 }); |
| 97 } |
| 98 |
| 99 test_importedLibrary_up() { |
| 100 String pathA = '/project/000/1111/a.dart'; |
| 101 testFile = '/project/000/1111/22/test.dart'; |
| 102 addSource(pathA, ''' |
| 103 import '22/test.dart'; |
| 104 '''); |
| 105 addTestSource(''); |
| 106 _performAnalysis(); |
| 107 // perform refactoring |
| 108 _createRefactoring('/project/000/1111/new_name.dart'); |
| 109 return _assertSuccessfulRefactoring().then((_) { |
| 110 assertFileChangeResult(pathA, ''' |
| 111 import 'new_name.dart'; |
| 112 '''); |
| 113 assertNoFileChange(testFile); |
| 114 }); |
| 115 } |
| 116 |
| 117 test_sourcedUnit() { |
| 118 String pathA = '/project/000/1111/a.dart'; |
| 119 testFile = '/project/000/1111/22/test.dart'; |
| 120 addSource(pathA, ''' |
| 121 part '22/test.dart'; |
| 122 '''); |
| 123 addTestSource(''); |
| 124 _performAnalysis(); |
| 125 // perform refactoring |
| 126 _createRefactoring('/project/000/1111/22/new_name.dart'); |
| 127 return _assertSuccessfulRefactoring().then((_) { |
| 128 assertFileChangeResult(pathA, ''' |
| 129 part '22/new_name.dart'; |
| 130 '''); |
| 131 assertNoFileChange(testFile); |
| 132 }); |
| 133 } |
| 134 |
| 135 test_sourcedUnit_multipleLibraries() { |
| 136 String pathA = '/project/000/1111/a.dart'; |
| 137 String pathB = '/project/000/b.dart'; |
| 138 testFile = '/project/000/1111/22/test.dart'; |
| 139 addSource(pathA, ''' |
| 140 part '22/test.dart'; |
| 141 '''); |
| 142 addSource(pathB, ''' |
| 143 part '1111/22/test.dart'; |
| 144 '''); |
| 145 addTestSource(''); |
| 146 _performAnalysis(); |
| 147 // perform refactoring |
| 148 _createRefactoring('/project/000/1111/22/new_name.dart'); |
| 149 return _assertSuccessfulRefactoring().then((_) { |
| 150 assertFileChangeResult(pathA, ''' |
| 151 part '22/new_name.dart'; |
| 152 '''); |
| 153 assertFileChangeResult(pathB, ''' |
| 154 part '1111/22/new_name.dart'; |
| 155 '''); |
| 156 assertNoFileChange(testFile); |
| 157 }); |
| 158 } |
| 159 |
| 160 /** |
| 161 * Checks that all conditions are OK. |
| 162 */ |
| 163 Future _assertSuccessfulRefactoring() { |
| 164 return assertRefactoringConditionsOK().then((_) { |
| 165 return refactoring.createChange().then((SourceChange refactoringChange) { |
| 166 this.refactoringChange = refactoringChange; |
| 167 }); |
| 168 }); |
| 169 } |
| 170 |
| 171 void _createRefactoring(String newName) { |
| 172 refactoring = new MoveFileRefactoring(searchEngine, context, testSource); |
| 173 refactoring.newFile = newName; |
| 174 } |
| 175 |
| 176 void _performAnalysis() { |
| 177 while (true) { |
| 178 AnalysisResult result = context.performAnalysisTask(); |
| 179 if (!result.hasMoreWork) { |
| 180 break; |
| 181 } |
| 182 for (ChangeNotice notice in result.changeNotices) { |
| 183 if (notice.source.fullName.startsWith('/project/')) { |
| 184 index.indexUnit(context, notice.compilationUnit); |
| 185 } |
| 186 } |
| 187 } |
| 188 } |
| 189 } |
| OLD | NEW |