mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 19:10:05 +00:00
Check that selection offset/length is valid in Extract Local refactoring.
R=brianwilkerson@google.com Bug: https://github.com/dart-lang/sdk/issues/34475 Change-Id: Id2b44494a8464000180a8ca93cfcc770b256f59f Reviewed-on: https://dart-review.googlesource.com/76063 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
7ad1e5da99
commit
2d53894e3f
|
@ -227,6 +227,15 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl
|
|||
* location of this [Expression] in AST allows extracting.
|
||||
*/
|
||||
RefactoringStatus _checkSelection() {
|
||||
if (selectionOffset <= 0) {
|
||||
return new RefactoringStatus.fatal(
|
||||
'The selection offset must be greater than zero.');
|
||||
}
|
||||
if (selectionOffset + selectionLength >= resolveResult.content.length) {
|
||||
return new RefactoringStatus.fatal(
|
||||
'The selection end offset must be less then the length of the file.');
|
||||
}
|
||||
|
||||
String selectionStr;
|
||||
// exclude whitespaces
|
||||
{
|
||||
|
|
|
@ -52,6 +52,28 @@ main() {
|
|||
expectedMessage: "The name 'res' is already used in the scope.");
|
||||
}
|
||||
|
||||
test_checkInitialCondition_false_outOfRange_length() async {
|
||||
await indexTestUnit('''
|
||||
main() {
|
||||
print(1 + 2);
|
||||
}
|
||||
''');
|
||||
_createRefactoring(0, 1 << 20);
|
||||
RefactoringStatus status = await refactoring.checkAllConditions();
|
||||
assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL);
|
||||
}
|
||||
|
||||
test_checkInitialCondition_outOfRange_offset() async {
|
||||
await indexTestUnit('''
|
||||
main() {
|
||||
print(1 + 2);
|
||||
}
|
||||
''');
|
||||
_createRefactoring(-10, 20);
|
||||
RefactoringStatus status = await refactoring.checkAllConditions();
|
||||
assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL);
|
||||
}
|
||||
|
||||
test_checkInitialConditions_assignmentLeftHandSize() async {
|
||||
await indexTestUnit('''
|
||||
main() {
|
||||
|
@ -68,8 +90,7 @@ main() {
|
|||
|
||||
test_checkInitialConditions_namePartOfDeclaration_function() async {
|
||||
await indexTestUnit('''
|
||||
main() {
|
||||
}
|
||||
void main() {}
|
||||
''');
|
||||
_createRefactoringWithSuffix('main', '()');
|
||||
// check conditions
|
||||
|
@ -695,6 +716,24 @@ main() {
|
|||
expect(refactoring.names, unorderedEquals(['helloBob', 'bob']));
|
||||
}
|
||||
|
||||
test_isAvailable_false_notPartOfFunction() async {
|
||||
await indexTestUnit('''
|
||||
var v = 1 + 2;
|
||||
''');
|
||||
_createRefactoringForString('1 + 2');
|
||||
expect(refactoring.isAvailable(), isFalse);
|
||||
}
|
||||
|
||||
test_isAvailable_true() async {
|
||||
await indexTestUnit('''
|
||||
main() {
|
||||
print(1 + 2);
|
||||
}
|
||||
''');
|
||||
_createRefactoringForString('1 + 2');
|
||||
expect(refactoring.isAvailable(), isTrue);
|
||||
}
|
||||
|
||||
test_occurrences_differentVariable() async {
|
||||
await indexTestUnit('''
|
||||
main() {
|
||||
|
|
Loading…
Reference in a new issue