summaryrefslogtreecommitdiff
path: root/test/Refactor
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2017-10-24 17:18:45 +0000
committerAlex Lorenz <arphaman@gmail.com>2017-10-24 17:18:45 +0000
commit58538f115416ae2ce6cc4cfa794d243bade5458d (patch)
treeec24dbb374fbc882e2168b3e71efa4ff0e9921fa /test/Refactor
parent53710bdec511dfcfb69ee4d234b7f579b4955101 (diff)
[refactor] Initial outline of implementation of "extract function" refactoring
This commit adds an initial, skeleton outline of the "extract function" refactoring. The extracted function doesn't capture variables / rewrite code yet, it just basically does a simple copy-paste. The following initiation rules are specified: - extraction can only be done for executable code in a function/method/block. This means that you can't extract a global variable initialize into a function right now. - simple literals and references are not extractable. This commit also adds support for full source ranges to clang-refactor's test mode. Differential Revision: https://reviews.llvm.org/D38982 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@316465 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Refactor')
-rw-r--r--test/Refactor/Extract/ExtractExprIntoFunction.cpp56
-rw-r--r--test/Refactor/LocalRename/Field.cpp8
-rw-r--r--test/Refactor/LocalRename/NoSymbolSelectedError.cpp4
-rw-r--r--test/Refactor/tool-test-support.c5
4 files changed, 68 insertions, 5 deletions
diff --git a/test/Refactor/Extract/ExtractExprIntoFunction.cpp b/test/Refactor/Extract/ExtractExprIntoFunction.cpp
new file mode 100644
index 0000000000..be610fc303
--- /dev/null
+++ b/test/Refactor/Extract/ExtractExprIntoFunction.cpp
@@ -0,0 +1,56 @@
+// RUN: clang-refactor extract -selection=test:%s %s -- -std=c++11 2>&1 | grep -v CHECK | FileCheck %s
+
+
+void simpleExtractNoCaptures() {
+ int i = /*range=->+0:33*/1 + 2;
+}
+
+// CHECK: 1 '' results:
+// CHECK: static int extracted() {
+// CHECK-NEXT: return 1 + 2;{{$}}
+// CHECK-NEXT: }{{[[:space:]].*}}
+// CHECK-NEXT: void simpleExtractNoCaptures() {
+// CHECK-NEXT: int i = /*range=->+0:33*/extracted();{{$}}
+// CHECK-NEXT: }
+
+void simpleExtractStmtNoCaptures() {
+ /*range astatement=->+1:13*/int a = 1;
+ int b = 2;
+}
+// CHECK: 1 'astatement' results:
+// CHECK: static void extracted() {
+// CHECK-NEXT: int a = 1;
+// CHECK-NEXT: int b = 2;;{{$}}
+// CHECK-NEXT: }{{[[:space:]].*}}
+// CHECK-NEXT: void simpleExtractStmtNoCaptures() {
+// CHECK-NEXT: /*range astatement=->+1:13*/extracted(){{$}}
+// CHECK-NEXT: }
+
+
+void blankRangeNoExtraction() {
+ int i = /*range blank=*/1 + 2;
+}
+
+// CHECK: 1 'blank' results:
+// CHECK-NEXT: the provided selection does not overlap with the AST nodes of interest
+
+int outOfBodyCodeNoExtraction = /*range out_of_body_expr=->+0:72*/1 + 2;
+
+struct OutOfBodyStuff {
+ int FieldInit = /*range out_of_body_expr=->+0:58*/1 + 2;
+
+ void foo(int x =/*range out_of_body_expr=->+0:58*/1 + 2);
+};
+
+// CHECK: 3 'out_of_body_expr' results:
+// CHECK: the selected code is not a part of a function's / method's body
+
+void simpleExpressionNoExtraction() {
+ int i = /*range simple_expr=->+0:41*/1 + /*range simple_expr=->+0:76*/(2);
+ (void) /*range simple_expr=->+0:40*/i;
+ (void)/*range simple_expr=->+0:47*/"literal";
+ (void)/*range simple_expr=->+0:41*/'c';
+}
+
+// CHECK: 5 'simple_expr' results:
+// CHECK-NEXT: the selected expression is too simple to extract
diff --git a/test/Refactor/LocalRename/Field.cpp b/test/Refactor/LocalRename/Field.cpp
index 83ca2e5748..e674401b96 100644
--- a/test/Refactor/LocalRename/Field.cpp
+++ b/test/Refactor/LocalRename/Field.cpp
@@ -1,9 +1,11 @@
-// RUN: clang-refactor local-rename -selection=test:%s -new-name=Bar %s -- | FileCheck %s
+// RUN: clang-refactor local-rename -selection=test:%s -new-name=Bar %s -- | grep -v CHECK | FileCheck %s
class Baz {
- int /*range=*/Foo; // CHECK: int /*range=*/Bar;
+ int /*range=*/Foo;
+ // CHECK: int /*range=*/Bar;
public:
Baz();
};
-Baz::Baz() : /*range=*/Foo(0) {} // CHECK: Baz::Baz() : /*range=*/Bar(0) {};
+Baz::Baz() : /*range=*/Foo(0) {}
+// CHECK: Baz::Baz() : /*range=*/Bar(0) {}
diff --git a/test/Refactor/LocalRename/NoSymbolSelectedError.cpp b/test/Refactor/LocalRename/NoSymbolSelectedError.cpp
index b6e96e11b7..98de61a45f 100644
--- a/test/Refactor/LocalRename/NoSymbolSelectedError.cpp
+++ b/test/Refactor/LocalRename/NoSymbolSelectedError.cpp
@@ -1,5 +1,5 @@
-// RUN: not clang-refactor local-rename -selection=%s:4:1 -new-name=Bar %s -- 2>&1 | FileCheck %s
-// RUN: clang-refactor local-rename -selection=test:%s -new-name=Bar %s -- 2>&1 | FileCheck --check-prefix=TESTCHECK %s
+// RUN: not clang-refactor local-rename -selection=%s:4:1 -new-name=Bar %s -- 2>&1 | grep -v CHECK | FileCheck %s
+// RUN: clang-refactor local-rename -selection=test:%s -new-name=Bar %s -- 2>&1 | grep -v CHECK | FileCheck --check-prefix=TESTCHECK %s
class Baz { // CHECK: [[@LINE]]:1: error: there is no symbol at the given location
};
diff --git a/test/Refactor/tool-test-support.c b/test/Refactor/tool-test-support.c
index a20825518c..0e073f6e1c 100644
--- a/test/Refactor/tool-test-support.c
+++ b/test/Refactor/tool-test-support.c
@@ -10,10 +10,13 @@
/*range named =+0*/int test5;
+/*range =->+0:22*/int test6;
+
// CHECK: Test selection group '':
// CHECK-NEXT: 105-105
// CHECK-NEXT: 158-158
// CHECK-NEXT: 197-197
+// CHECK-NEXT: 248-251
// CHECK-NEXT: Test selection group 'named':
// CHECK-NEXT: 132-132
// CHECK-NEXT: 218-218
@@ -29,6 +32,8 @@
// CHECK: invoking action 'local-rename':
// CHECK-NEXT: -selection={{.*}}tool-test-support.c:9:29
+// CHECK: invoking action 'local-rename':
+// CHECK-NEXT: -selection={{.*}}tool-test-support.c:13:19 -> {{.*}}tool-test-support.c:13:22
// The following invocations are in the 'named' group, and they follow
// the default invocation even if some of their ranges occur prior to the