1 // RUN: clang-refactor extract -selection=test:%s %s -- -std=c++14 2>&1 | grep -v CHECK | FileCheck %s
2
3
simpleExtractNoCaptures()4 void 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
simpleExtractStmtNoCaptures()16 void 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;
23 // CHECK-NEXT: int b = 2;{{$}}
24 // CHECK-NEXT: }{{[[:space:]].*}}
25 // CHECK-NEXT: void simpleExtractStmtNoCaptures() {
26 // CHECK-NEXT: /*range astatement=->+1:13*/extracted();{{$}}
27 // CHECK-NEXT: }
28
29
blankRangeNoExtraction()30 void 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
37 int outOfBodyCodeNoExtraction = /*range out_of_body_expr=->+0:72*/1 + 2;
38
39 struct 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
inFunctionOutOfBody()45 auto 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:
60 // CHECK: the selected code is not a part of a function's / method's body
61
simpleExpressionNoExtraction()62 void 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
71