| 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; | 5 library test.services.refactoring; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/protocol.dart'; | 9 import 'package:analysis_server/src/protocol.dart'; |
| 10 import 'package:analysis_server/src/services/correction/status.dart'; | 10 import 'package:analysis_server/src/services/correction/status.dart'; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 * with the given [path]. | 67 * with the given [path]. |
| 68 */ | 68 */ |
| 69 void assertNoFileChange(String path) { | 69 void assertNoFileChange(String path) { |
| 70 SourceFileEdit fileEdit = refactoringChange.getFileEdit(path); | 70 SourceFileEdit fileEdit = refactoringChange.getFileEdit(path); |
| 71 expect(fileEdit, isNull); | 71 expect(fileEdit, isNull); |
| 72 } | 72 } |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Asserts that [refactoring] initial/final conditions status is OK. | 75 * Asserts that [refactoring] initial/final conditions status is OK. |
| 76 */ | 76 */ |
| 77 Future assertRefactoringConditionsOK() { | 77 Future assertRefactoringConditionsOK() async { |
| 78 return refactoring.checkInitialConditions().then((status) { | 78 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 79 assertRefactoringStatusOK(status); | 79 assertRefactoringStatusOK(status); |
| 80 return refactoring.checkFinalConditions().then((status) { | 80 status = await refactoring.checkFinalConditions(); |
| 81 assertRefactoringStatusOK(status); | 81 assertRefactoringStatusOK(status); |
| 82 }); | |
| 83 }); | |
| 84 } | 82 } |
| 85 | 83 |
| 86 /** | 84 /** |
| 87 * Asserts that [refactoring] final conditions status is OK. | 85 * Asserts that [refactoring] final conditions status is OK. |
| 88 */ | 86 */ |
| 89 Future assertRefactoringFinalConditionsOK() { | 87 Future assertRefactoringFinalConditionsOK() async { |
| 90 return refactoring.checkFinalConditions().then((status) { | 88 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 91 assertRefactoringStatusOK(status); | 89 assertRefactoringStatusOK(status); |
| 92 }); | |
| 93 } | 90 } |
| 94 | 91 |
| 95 /** | 92 /** |
| 96 * Asserts that [status] has expected severity and message. | 93 * Asserts that [status] has expected severity and message. |
| 97 */ | 94 */ |
| 98 void assertRefactoringStatus(RefactoringStatus status, | 95 void assertRefactoringStatus(RefactoringStatus status, |
| 99 RefactoringProblemSeverity expectedSeverity, {String expectedMessage, | 96 RefactoringProblemSeverity expectedSeverity, {String expectedMessage, |
| 100 SourceRange expectedContextRange, String expectedContextSearch}) { | 97 SourceRange expectedContextRange, String expectedContextSearch}) { |
| 101 expect(status.severity, expectedSeverity, reason: status.toString()); | 98 expect(status.severity, expectedSeverity, reason: status.toString()); |
| 102 if (expectedSeverity != null) { | 99 if (expectedSeverity != null) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 122 * Asserts that [refactoring] status is OK. | 119 * Asserts that [refactoring] status is OK. |
| 123 */ | 120 */ |
| 124 void assertRefactoringStatusOK(RefactoringStatus status) { | 121 void assertRefactoringStatusOK(RefactoringStatus status) { |
| 125 assertRefactoringStatus(status, null); | 122 assertRefactoringStatus(status, null); |
| 126 } | 123 } |
| 127 | 124 |
| 128 /** | 125 /** |
| 129 * Checks that all conditions of [refactoring] are OK and the result of | 126 * Checks that all conditions of [refactoring] are OK and the result of |
| 130 * applying the [Change] to [testUnit] is [expectedCode]. | 127 * applying the [Change] to [testUnit] is [expectedCode]. |
| 131 */ | 128 */ |
| 132 Future assertSuccessfulRefactoring(String expectedCode) { | 129 Future assertSuccessfulRefactoring(String expectedCode) async { |
| 133 return assertRefactoringConditionsOK().then((_) { | 130 await assertRefactoringConditionsOK(); |
| 134 return refactoring.createChange().then((SourceChange change) { | 131 SourceChange change = await refactoring.createChange(); |
| 135 this.refactoringChange = change; | 132 this.refactoringChange = change; |
| 136 assertTestChangeResult(expectedCode); | 133 assertTestChangeResult(expectedCode); |
| 137 }); | |
| 138 }); | |
| 139 } | 134 } |
| 140 | 135 |
| 141 /** | 136 /** |
| 142 * Asserts that [refactoringChange] contains a [FileEdit] for [testFile], and | 137 * Asserts that [refactoringChange] contains a [FileEdit] for [testFile], and |
| 143 * it results the [expectedCode]. | 138 * it results the [expectedCode]. |
| 144 */ | 139 */ |
| 145 void assertTestChangeResult(String expectedCode) { | 140 void assertTestChangeResult(String expectedCode) { |
| 146 // prepare FileEdit | 141 // prepare FileEdit |
| 147 SourceFileEdit fileEdit = refactoringChange.getFileEdit(testFile); | 142 SourceFileEdit fileEdit = refactoringChange.getFileEdit(testFile); |
| 148 expect(fileEdit, isNotNull); | 143 expect(fileEdit, isNotNull); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 161 CompilationUnit unit = resolveLibraryUnit(source); | 156 CompilationUnit unit = resolveLibraryUnit(source); |
| 162 index.indexUnit(context, unit); | 157 index.indexUnit(context, unit); |
| 163 } | 158 } |
| 164 | 159 |
| 165 void setUp() { | 160 void setUp() { |
| 166 super.setUp(); | 161 super.setUp(); |
| 167 index = createLocalMemoryIndex(); | 162 index = createLocalMemoryIndex(); |
| 168 searchEngine = new SearchEngineImpl(index); | 163 searchEngine = new SearchEngineImpl(index); |
| 169 } | 164 } |
| 170 } | 165 } |
| OLD | NEW |