| 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.rename; | 5 library test.services.refactoring.rename; |
| 6 | 6 |
| 7 import 'dart:async'; | |
| 8 | |
| 9 import 'package:analysis_server/src/protocol.dart' hide Element; | 7 import 'package:analysis_server/src/protocol.dart' hide Element; |
| 10 import 'package:analysis_server/src/services/correction/namespace.dart'; | 8 import 'package:analysis_server/src/services/correction/namespace.dart'; |
| 11 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 9 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 12 import 'package:analyzer/file_system/file_system.dart'; | 10 import 'package:analyzer/file_system/file_system.dart'; |
| 13 import 'package:analyzer/src/generated/ast.dart'; | 11 import 'package:analyzer/src/generated/ast.dart'; |
| 14 import 'package:analyzer/src/generated/element.dart'; | 12 import 'package:analyzer/src/generated/element.dart'; |
| 15 import 'package:analyzer/src/generated/source.dart'; | 13 import 'package:analyzer/src/generated/source.dart'; |
| 16 import 'package:unittest/unittest.dart'; | 14 import 'package:unittest/unittest.dart'; |
| 17 | 15 |
| 18 import 'abstract_refactoring.dart'; | 16 import 'abstract_refactoring.dart'; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 for (String potentialId in refactoring.potentialEditIds) { | 61 for (String potentialId in refactoring.potentialEditIds) { |
| 64 SourceEdit edit = findEditById(potentialId); | 62 SourceEdit edit = findEditById(potentialId); |
| 65 expect(edit, isNotNull); | 63 expect(edit, isNotNull); |
| 66 expectedOffsets.remove(edit.offset); | 64 expectedOffsets.remove(edit.offset); |
| 67 } | 65 } |
| 68 // all potential offsets are marked as such | 66 // all potential offsets are marked as such |
| 69 expect(expectedOffsets, isEmpty); | 67 expect(expectedOffsets, isEmpty); |
| 70 } | 68 } |
| 71 | 69 |
| 72 /** | 70 /** |
| 73 * Checks that all conditions are OK and the result of applying the [Change] | |
| 74 * to [testUnit] is [expectedCode]. | |
| 75 */ | |
| 76 Future assertSuccessfulRename(String expectedCode) { | |
| 77 return assertRefactoringConditionsOK().then((_) { | |
| 78 return refactoring.createChange().then((SourceChange refactoringChange) { | |
| 79 this.refactoringChange = refactoringChange; | |
| 80 assertTestChangeResult(expectedCode); | |
| 81 }); | |
| 82 }); | |
| 83 } | |
| 84 | |
| 85 /** | |
| 86 * Creates a new [RenameRefactoring] in [refactoring] for the [Element] of | 71 * Creates a new [RenameRefactoring] in [refactoring] for the [Element] of |
| 87 * the [SimpleIdentifier] at the given [search] pattern. | 72 * the [SimpleIdentifier] at the given [search] pattern. |
| 88 */ | 73 */ |
| 89 void createRenameRefactoringAtString(String search) { | 74 void createRenameRefactoringAtString(String search) { |
| 90 SimpleIdentifier identifier = findIdentifier(search); | 75 SimpleIdentifier identifier = findIdentifier(search); |
| 91 Element element = identifier.bestElement; | 76 Element element = identifier.bestElement; |
| 92 if (element is PrefixElement) { | 77 if (element is PrefixElement) { |
| 93 element = getImportElement(identifier); | 78 element = getImportElement(identifier); |
| 94 } | 79 } |
| 95 createRenameRefactoringForElement(element); | 80 createRenameRefactoringForElement(element); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // void assertChangeResult(Change change, Source source, String expected) | 117 // void assertChangeResult(Change change, Source source, String expected) |
| 133 // { | 118 // { |
| 134 // SourceChange sourceChange = getSourceChange(compositeChange, source); | 119 // SourceChange sourceChange = getSourceChange(compositeChange, source); |
| 135 // assertNotNull("No change for: " + source.toString(), sourceChange); | 120 // assertNotNull("No change for: " + source.toString(), sourceChange); |
| 136 // String sourceResult = getChangeResult(context, source, sourceChange); | 121 // String sourceResult = getChangeResult(context, source, sourceChange); |
| 137 // assertEquals(expected, sourceResult); | 122 // assertEquals(expected, sourceResult); |
| 138 //// AnalysisContext context = getAnalysisContext(); | 123 //// AnalysisContext context = getAnalysisContext(); |
| 139 //// assertChangeResult(context, compositeChange, source, expected); | 124 //// assertChangeResult(context, compositeChange, source, expected); |
| 140 // } | 125 // } |
| 141 } | 126 } |
| OLD | NEW |