| 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 } | 92 } |
| 93 | 93 |
| 94 /** | 94 /** |
| 95 * Asserts that [refactoring] status is OK. | 95 * Asserts that [refactoring] status is OK. |
| 96 */ | 96 */ |
| 97 void assertRefactoringStatusOK(RefactoringStatus status) { | 97 void assertRefactoringStatusOK(RefactoringStatus status) { |
| 98 assertRefactoringStatus(status, null); | 98 assertRefactoringStatus(status, null); |
| 99 } | 99 } |
| 100 | 100 |
| 101 /** | 101 /** |
| 102 * Checks that all conditions are OK and the result of applying the [Change] |
| 103 * to [testUnit] is [expectedCode]. |
| 104 */ |
| 105 Future assertSuccessfulRefactoring(String expectedCode) { |
| 106 return assertRefactoringConditionsOK().then((_) { |
| 107 return refactoring.createChange().then((SourceChange refactoringChange) { |
| 108 this.refactoringChange = refactoringChange; |
| 109 assertTestChangeResult(expectedCode); |
| 110 }); |
| 111 }); |
| 112 } |
| 113 |
| 114 /** |
| 102 * Asserts that [refactoringChange] contains a [FileEdit] for [testFile], and | 115 * Asserts that [refactoringChange] contains a [FileEdit] for [testFile], and |
| 103 * it results the [expectedCode]. | 116 * it results the [expectedCode]. |
| 104 */ | 117 */ |
| 105 void assertTestChangeResult(String expectedCode) { | 118 void assertTestChangeResult(String expectedCode) { |
| 106 // prepare FileEdit | 119 // prepare FileEdit |
| 107 SourceFileEdit fileEdit = refactoringChange.getFileEdit(testFile); | 120 SourceFileEdit fileEdit = refactoringChange.getFileEdit(testFile); |
| 108 expect(fileEdit, isNotNull); | 121 expect(fileEdit, isNotNull); |
| 109 // validate resulting code | 122 // validate resulting code |
| 110 String actualCode = SourceEdit.applySequence(testCode, fileEdit.edits); | 123 String actualCode = SourceEdit.applySequence(testCode, fileEdit.edits); |
| 111 expect(actualCode, expectedCode); | 124 expect(actualCode, expectedCode); |
| 112 } | 125 } |
| 113 | 126 |
| 114 void indexTestUnit(String code) { | 127 void indexTestUnit(String code) { |
| 115 resolveTestUnit(code); | 128 resolveTestUnit(code); |
| 116 index.indexUnit(context, testUnit); | 129 index.indexUnit(context, testUnit); |
| 117 } | 130 } |
| 118 | 131 |
| 119 void indexUnit(String file, String code) { | 132 void indexUnit(String file, String code) { |
| 120 Source source = addSource(file, code); | 133 Source source = addSource(file, code); |
| 121 CompilationUnit unit = resolveLibraryUnit(source); | 134 CompilationUnit unit = resolveLibraryUnit(source); |
| 122 index.indexUnit(context, unit); | 135 index.indexUnit(context, unit); |
| 123 } | 136 } |
| 124 | 137 |
| 125 void setUp() { | 138 void setUp() { |
| 126 super.setUp(); | 139 super.setUp(); |
| 127 index = createLocalMemoryIndex(); | 140 index = createLocalMemoryIndex(); |
| 128 searchEngine = new SearchEngineImpl(index); | 141 searchEngine = new SearchEngineImpl(index); |
| 129 } | 142 } |
| 130 } | 143 } |
| OLD | NEW |