| // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
| import 'package:test/test.dart'; |
| import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| |
| import 'abstract_rename.dart'; |
| |
| void main() { |
| defineReflectiveSuite(() { |
| defineReflectiveTests(RenameLibraryTest); |
| }); |
| } |
| |
| @reflectiveTest |
| class RenameLibraryTest extends RenameRefactoringTest { |
| Future<void> test_checkNewName() async { |
| await indexTestUnit(''' |
| library my.app; |
| '''); |
| _createRenameRefactoring(); |
| // empty |
| refactoring.newName = ''; |
| assertRefactoringStatus( |
| refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| expectedMessage: 'Library name must not be blank.'); |
| // same name |
| refactoring.newName = 'my.app'; |
| assertRefactoringStatus( |
| refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| expectedMessage: |
| 'The new name must be different than the current name.'); |
| } |
| |
| Future<void> test_createChange() async { |
| addSource('/home/test/lib/part.dart', ''' |
| part of my.app; |
| '''); |
| await indexTestUnit(''' |
| library my.app; |
| part 'part.dart'; |
| '''); |
| // configure refactoring |
| _createRenameRefactoring(); |
| expect(refactoring.refactoringName, 'Rename Library'); |
| expect(refactoring.elementKindName, 'library'); |
| refactoring.newName = 'the.new.name'; |
| // validate change |
| await assertSuccessfulRefactoring(''' |
| library the.new.name; |
| part 'part.dart'; |
| '''); |
| assertFileChangeResult('/home/test/lib/part.dart', ''' |
| part of the.new.name; |
| '''); |
| } |
| |
| Future<void> test_createChange_hasWhitespaces() async { |
| addSource('/home/test/lib/part.dart', ''' |
| part of my . app; |
| '''); |
| await indexTestUnit(''' |
| library my . app; |
| part 'part.dart'; |
| '''); |
| // configure refactoring |
| _createRenameRefactoring(); |
| expect(refactoring.refactoringName, 'Rename Library'); |
| expect(refactoring.elementKindName, 'library'); |
| refactoring.newName = 'the.new.name'; |
| // validate change |
| await assertSuccessfulRefactoring(''' |
| library the.new.name; |
| part 'part.dart'; |
| '''); |
| assertFileChangeResult('/home/test/lib/part.dart', ''' |
| part of the.new.name; |
| '''); |
| } |
| |
| void _createRenameRefactoring() { |
| createRenameRefactoringForElement(testUnitElement.library); |
| } |
| } |