| 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_library; | 5 library test.services.refactoring.rename_library; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 8 import 'package:analyzer/src/generated/source.dart'; | 8 import 'package:analyzer/src/generated/source.dart'; |
| 9 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
| 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 11 | 11 |
| 12 import 'abstract_rename.dart'; | 12 import 'abstract_rename.dart'; |
| 13 | 13 |
| 14 main() { | 14 main() { |
| 15 defineReflectiveSuite(() { | 15 defineReflectiveSuite(() { |
| 16 defineReflectiveTests(RenameLibraryTest); | 16 defineReflectiveTests(RenameLibraryTest); |
| 17 }); | 17 }); |
| 18 } | 18 } |
| 19 | 19 |
| 20 @reflectiveTest | 20 @reflectiveTest |
| 21 class RenameLibraryTest extends RenameRefactoringTest { | 21 class RenameLibraryTest extends RenameRefactoringTest { |
| 22 void test_checkNewName() { | 22 test_checkNewName() async { |
| 23 indexTestUnit(''' | 23 await indexTestUnit(''' |
| 24 library my.app; | 24 library my.app; |
| 25 '''); | 25 '''); |
| 26 _createRenameRefactoring(); | 26 _createRenameRefactoring(); |
| 27 // null | 27 // null |
| 28 refactoring.newName = null; | 28 refactoring.newName = null; |
| 29 assertRefactoringStatus( | 29 assertRefactoringStatus( |
| 30 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 30 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| 31 expectedMessage: "Library name must not be null."); | 31 expectedMessage: "Library name must not be null."); |
| 32 // empty | 32 // empty |
| 33 refactoring.newName = ''; | 33 refactoring.newName = ''; |
| 34 assertRefactoringStatus( | 34 assertRefactoringStatus( |
| 35 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 35 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| 36 expectedMessage: "Library name must not be blank."); | 36 expectedMessage: "Library name must not be blank."); |
| 37 // same name | 37 // same name |
| 38 refactoring.newName = 'my.app'; | 38 refactoring.newName = 'my.app'; |
| 39 assertRefactoringStatus( | 39 assertRefactoringStatus( |
| 40 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 40 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| 41 expectedMessage: | 41 expectedMessage: |
| 42 "The new name must be different than the current name."); | 42 "The new name must be different than the current name."); |
| 43 } | 43 } |
| 44 | 44 |
| 45 test_createChange() async { | 45 test_createChange() async { |
| 46 Source unitSource = addSource( | 46 Source unitSource = addSource( |
| 47 '/part.dart', | 47 '/part.dart', |
| 48 ''' | 48 ''' |
| 49 part of my.app; | 49 part of my.app; |
| 50 '''); | 50 '''); |
| 51 indexTestUnit(''' | 51 await indexTestUnit(''' |
| 52 library my.app; | 52 library my.app; |
| 53 part 'part.dart'; | 53 part 'part.dart'; |
| 54 '''); | 54 '''); |
| 55 index.indexUnit(context.resolveCompilationUnit2(unitSource, testSource)); | 55 index.indexUnit(context.resolveCompilationUnit2(unitSource, testSource)); |
| 56 // configure refactoring | 56 // configure refactoring |
| 57 _createRenameRefactoring(); | 57 _createRenameRefactoring(); |
| 58 expect(refactoring.refactoringName, 'Rename Library'); | 58 expect(refactoring.refactoringName, 'Rename Library'); |
| 59 expect(refactoring.elementKindName, 'library'); | 59 expect(refactoring.elementKindName, 'library'); |
| 60 refactoring.newName = 'the.new.name'; | 60 refactoring.newName = 'the.new.name'; |
| 61 // validate change | 61 // validate change |
| 62 await assertSuccessfulRefactoring(''' | 62 await assertSuccessfulRefactoring(''' |
| 63 library the.new.name; | 63 library the.new.name; |
| 64 part 'part.dart'; | 64 part 'part.dart'; |
| 65 '''); | 65 '''); |
| 66 assertFileChangeResult( | 66 assertFileChangeResult( |
| 67 '/part.dart', | 67 '/part.dart', |
| 68 ''' | 68 ''' |
| 69 part of the.new.name; | 69 part of the.new.name; |
| 70 '''); | 70 '''); |
| 71 } | 71 } |
| 72 | 72 |
| 73 test_createChange_hasWhitespaces() async { | 73 test_createChange_hasWhitespaces() async { |
| 74 Source unitSource = addSource( | 74 Source unitSource = addSource( |
| 75 '/part.dart', | 75 '/part.dart', |
| 76 ''' | 76 ''' |
| 77 part of my . app; | 77 part of my . app; |
| 78 '''); | 78 '''); |
| 79 indexTestUnit(''' | 79 await indexTestUnit(''' |
| 80 library my . app; | 80 library my . app; |
| 81 part 'part.dart'; | 81 part 'part.dart'; |
| 82 '''); | 82 '''); |
| 83 index.indexUnit(context.resolveCompilationUnit2(unitSource, testSource)); | 83 index.indexUnit(context.resolveCompilationUnit2(unitSource, testSource)); |
| 84 // configure refactoring | 84 // configure refactoring |
| 85 _createRenameRefactoring(); | 85 _createRenameRefactoring(); |
| 86 expect(refactoring.refactoringName, 'Rename Library'); | 86 expect(refactoring.refactoringName, 'Rename Library'); |
| 87 expect(refactoring.elementKindName, 'library'); | 87 expect(refactoring.elementKindName, 'library'); |
| 88 refactoring.newName = 'the.new.name'; | 88 refactoring.newName = 'the.new.name'; |
| 89 // validate change | 89 // validate change |
| 90 await assertSuccessfulRefactoring(''' | 90 await assertSuccessfulRefactoring(''' |
| 91 library the.new.name; | 91 library the.new.name; |
| 92 part 'part.dart'; | 92 part 'part.dart'; |
| 93 '''); | 93 '''); |
| 94 assertFileChangeResult( | 94 assertFileChangeResult( |
| 95 '/part.dart', | 95 '/part.dart', |
| 96 ''' | 96 ''' |
| 97 part of the.new.name; | 97 part of the.new.name; |
| 98 '''); | 98 '''); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void _createRenameRefactoring() { | 101 void _createRenameRefactoring() { |
| 102 createRenameRefactoringForElement(testUnitElement.library); | 102 createRenameRefactoringForElement(testUnitElement.library); |
| 103 } | 103 } |
| 104 } | 104 } |
| OLD | NEW |