summaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-10-27 18:19:11 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-10-27 18:19:11 +0000
commit99af5f07de88d6757dedc7ee6a8197fab0fe8c0f (patch)
treeca6a9414b877de2816023fa16fd5188451eb4575 /unittests
parent1c09b76713c0a3521937e035b3ab4edef687e7ee (diff)
[refactor] Describe refactorings in the operation classes
This commit changes the way that the refactoring operation classes are structured: - Users have to call `initiate` instead of constructing an instance of the class. The `initiate` is now supposed to have custom initiation logic, and you don't need to subclass the builtin requirements. - A new `describe` function returns a structure with the id, title and the description of the refactoring operation. The refactoring action classes are now placed into one common place in RefactoringActions.cpp instead of being separate. Differential Revision: https://reviews.llvm.org/D38985 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316780 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Tooling/RefactoringActionRulesTest.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/unittests/Tooling/RefactoringActionRulesTest.cpp b/unittests/Tooling/RefactoringActionRulesTest.cpp
index 132a3a4496..f0b6466fec 100644
--- a/unittests/Tooling/RefactoringActionRulesTest.cpp
+++ b/unittests/Tooling/RefactoringActionRulesTest.cpp
@@ -10,7 +10,8 @@
#include "ReplacementTest.h"
#include "RewriterTestContext.h"
#include "clang/Tooling/Refactoring.h"
-#include "clang/Tooling/Refactoring/RefactoringActionRules.h"
+#include "clang/Tooling/Refactoring/Extract/Extract.h"
+#include "clang/Tooling/Refactoring/RefactoringAction.h"
#include "clang/Tooling/Refactoring/RefactoringDiagnostic.h"
#include "clang/Tooling/Refactoring/Rename/SymbolName.h"
#include "clang/Tooling/Tooling.h"
@@ -63,6 +64,12 @@ TEST_F(RefactoringActionRulesTest, MyFirstRefactoringRule) {
ReplaceAWithB(std::pair<SourceRange, int> Selection)
: Selection(Selection) {}
+ static Expected<ReplaceAWithB>
+ initiate(RefactoringRuleContext &Cotnext,
+ std::pair<SourceRange, int> Selection) {
+ return ReplaceAWithB(Selection);
+ }
+
Expected<AtomicChanges>
createSourceReplacements(RefactoringRuleContext &Context) {
const SourceManager &SM = Context.getSources();
@@ -141,6 +148,11 @@ TEST_F(RefactoringActionRulesTest, MyFirstRefactoringRule) {
TEST_F(RefactoringActionRulesTest, ReturnError) {
class ErrorRule : public SourceChangeRefactoringRule {
public:
+ static Expected<ErrorRule> initiate(RefactoringRuleContext &,
+ SourceRange R) {
+ return ErrorRule(R);
+ }
+
ErrorRule(SourceRange R) {}
Expected<AtomicChanges> createSourceReplacements(RefactoringRuleContext &) {
return llvm::make_error<llvm::StringError>(
@@ -191,6 +203,11 @@ TEST_F(RefactoringActionRulesTest, ReturnSymbolOccurrences) {
public:
FindOccurrences(SourceRange Selection) : Selection(Selection) {}
+ static Expected<FindOccurrences> initiate(RefactoringRuleContext &,
+ SourceRange Selection) {
+ return FindOccurrences(Selection);
+ }
+
Expected<SymbolOccurrences>
findSymbolOccurrences(RefactoringRuleContext &) override {
SymbolOccurrences Occurrences;
@@ -219,4 +236,13 @@ TEST_F(RefactoringActionRulesTest, ReturnSymbolOccurrences) {
SourceRange(Cursor, Cursor.getLocWithOffset(strlen("test"))));
}
+TEST_F(RefactoringActionRulesTest, EditorCommandBinding) {
+ const RefactoringDescriptor &Descriptor = ExtractFunction::describe();
+ EXPECT_EQ(Descriptor.Name, "extract-function");
+ EXPECT_EQ(
+ Descriptor.Description,
+ "(WIP action; use with caution!) Extracts code into a new function");
+ EXPECT_EQ(Descriptor.Title, "Extract Function");
+}
+
} // end anonymous namespace