blob: 0fccc9298597ea403540bc87e39a63f53e5840ed [file] [log] [blame]
Alex Lorenzcc557542017-11-14 18:59:01 +00001// RUN: clang-refactor extract -selection=test:%s %s -- -std=c++14 2>&1 | grep -v CHECK | FileCheck %s
Alex Lorenz7fe441b2017-10-24 17:18:45 +00002
3
4void simpleExtractNoCaptures() {
5 int i = /*range=->+0:33*/1 + 2;
6}
7
8// CHECK: 1 '' results:
9// CHECK: static int extracted() {
10// CHECK-NEXT: return 1 + 2;{{$}}
11// CHECK-NEXT: }{{[[:space:]].*}}
12// CHECK-NEXT: void simpleExtractNoCaptures() {
13// CHECK-NEXT: int i = /*range=->+0:33*/extracted();{{$}}
14// CHECK-NEXT: }
15
16void simpleExtractStmtNoCaptures() {
17 /*range astatement=->+1:13*/int a = 1;
18 int b = 2;
19}
20// CHECK: 1 'astatement' results:
21// CHECK: static void extracted() {
22// CHECK-NEXT: int a = 1;
Alex Lorenzebbbb812017-11-03 18:11:22 +000023// CHECK-NEXT: int b = 2;{{$}}
Alex Lorenz7fe441b2017-10-24 17:18:45 +000024// CHECK-NEXT: }{{[[:space:]].*}}
25// CHECK-NEXT: void simpleExtractStmtNoCaptures() {
Alex Lorenzebbbb812017-11-03 18:11:22 +000026// CHECK-NEXT: /*range astatement=->+1:13*/extracted();{{$}}
Alex Lorenz7fe441b2017-10-24 17:18:45 +000027// CHECK-NEXT: }
28
29
30void blankRangeNoExtraction() {
31 int i = /*range blank=*/1 + 2;
32}
33
34// CHECK: 1 'blank' results:
35// CHECK-NEXT: the provided selection does not overlap with the AST nodes of interest
36
37int outOfBodyCodeNoExtraction = /*range out_of_body_expr=->+0:72*/1 + 2;
38
39struct OutOfBodyStuff {
40 int FieldInit = /*range out_of_body_expr=->+0:58*/1 + 2;
41
42 void foo(int x =/*range out_of_body_expr=->+0:58*/1 + 2);
43};
44
Alex Lorenzcc557542017-11-14 18:59:01 +000045auto inFunctionOutOfBody() -> decltype(/*range out_of_body_expr=->+0:79*/1 + 2) {
46 struct OutOfBodyStuff {
47 int FieldInit = /*range out_of_body_expr=->+0:60*/1 + 2;
48
49 void foo(int x =/*range out_of_body_expr=->+0:60*/1 + 2);
50 };
51 enum E {
52 X = /*range out_of_body_expr=->+0:48*/1 + 2
53 };
54 int x = 0;
55 using T = decltype(/*range out_of_body_expr=->+0:61*/x + 3);
56 return x;
57}
58
59// CHECK: 8 'out_of_body_expr' results:
Alex Lorenz7fe441b2017-10-24 17:18:45 +000060// CHECK: the selected code is not a part of a function's / method's body
61
62void simpleExpressionNoExtraction() {
63 int i = /*range simple_expr=->+0:41*/1 + /*range simple_expr=->+0:76*/(2);
64 (void) /*range simple_expr=->+0:40*/i;
65 (void)/*range simple_expr=->+0:47*/"literal";
66 (void)/*range simple_expr=->+0:41*/'c';
67}
68
69// CHECK: 5 'simple_expr' results:
70// CHECK-NEXT: the selected expression is too simple to extract