1 // RUN: clang-refactor extract -selection=test:%s %s -- -std=c++11 -fcxx-exceptions | grep -v CHECK | FileCheck %s
3 struct Rectangle
{ int width
, height
; };
5 void extractStatement(const Rectangle
&r
) {
6 /*range adeclstmt=->+0:59*/int area
= r
.width
* r
.height
;
8 // CHECK: 1 'adeclstmt' results:
9 // CHECK: static void extracted() {
10 // CHECK-NEXT: int area = r.width * r.height;{{$}}
11 // CHECK-NEXT: }{{[[:space:]].*}}
12 // CHECK-NEXT: void extractStatement(const Rectangle &r) {
13 // CHECK-NEXT: /*range adeclstmt=->+0:59*/extracted();{{$}}
16 void extractStatementNoSemiIf(const Rectangle
&r
) {
17 /*range bextractif=->+2:4*/if (r
.width
) {
21 // CHECK: 1 'bextractif' results:
22 // CHECK: static void extracted() {
23 // CHECK-NEXT: if (r.width) {
24 // CHECK-NEXT: int x = r.height;
26 // CHECK-NEXT: }{{[[:space:]].*}}
27 // CHECK-NEXT: void extractStatementNoSemiIf(const Rectangle &r) {
28 // CHECK-NEXT: /*range bextractif=->+2:4*/extracted();{{$}}
31 void extractStatementDontExtraneousSemi(const Rectangle
&r
) {
32 /*range cextractif=->+2:4*/if (r
.width
) {
35 } //^ This semicolon shouldn't be extracted.
36 // CHECK: 1 'cextractif' results:
37 // CHECK: static void extracted() {
38 // CHECK-NEXT: if (r.width) {
39 // CHECK-NEXT: int x = r.height;
41 // CHECK-NEXT: }{{[[:space:]].*}}
42 // CHECK-NEXT: void extractStatementDontExtraneousSemi(const Rectangle &r) {
43 // CHECK-NEXT: extracted(); ;{{$}}
46 void extractStatementNotSemiSwitch() {
47 /*range dextract=->+5:4*/switch (2) {
54 // CHECK: 1 'dextract' results:
55 // CHECK: static void extracted() {
56 // CHECK-NEXT: switch (2) {
57 // CHECK-NEXT: case 1:
59 // CHECK-NEXT: case 2:
62 // CHECK-NEXT: }{{[[:space:]].*}}
63 // CHECK-NEXT: void extractStatementNotSemiSwitch() {
64 // CHECK-NEXT: extracted();{{$}}
68 void extractStatementNotSemiWhile() {
69 /*range eextract=->+2:4*/while (true) {
73 // CHECK: 1 'eextract' results:
74 // CHECK: static void extracted() {
75 // CHECK-NEXT: while (true) {
76 // CHECK-NEXT: int x = 0;
78 // CHECK-NEXT: }{{[[:space:]].*}}
79 // CHECK-NEXT: void extractStatementNotSemiWhile() {
80 // CHECK-NEXT: extracted();{{$}}
83 void extractStatementNotSemiFor() {
84 /*range fextract=->+1:4*/for (int i
= 0; i
< 10; ++i
) {
87 // CHECK: 1 'fextract' results:
88 // CHECK: static void extracted() {
89 // CHECK-NEXT: for (int i = 0; i < 10; ++i) {
91 // CHECK-NEXT: }{{[[:space:]].*}}
92 // CHECK-NEXT: void extractStatementNotSemiFor() {
93 // CHECK-NEXT: extracted();{{$}}
97 int *begin() { return 0; }
98 int *end() { return 0; }
101 void extractStatementNotSemiRangedFor(XS xs
) {
102 /*range gextract=->+1:4*/for (int i
: xs
) {
105 // CHECK: 1 'gextract' results:
106 // CHECK: static void extracted() {
107 // CHECK-NEXT: for (int i : xs) {
108 // CHECK-NEXT: }{{$}}
109 // CHECK-NEXT: }{{[[:space:]].*}}
110 // CHECK-NEXT: void extractStatementNotSemiRangedFor(XS xs) {
111 // CHECK-NEXT: extracted();{{$}}
114 void extractStatementNotSemiRangedTryCatch() {
115 /*range hextract=->+3:4*/try { int x
= 0; }
116 catch (const int &i
) {
120 // CHECK: 1 'hextract' results:
121 // CHECK: static void extracted() {
122 // CHECK-NEXT: try { int x = 0; }
123 // CHECK-NEXT: catch (const int &i) {
124 // CHECK-NEXT: int y = i;
125 // CHECK-NEXT: }{{$}}
126 // CHECK-NEXT: }{{[[:space:]].*}}
127 // CHECK-NEXT: void extractStatementNotSemiRangedTryCatch() {
128 // CHECK-NEXT: extracted();{{$}}
131 void extractCantFindSemicolon() {
132 /*range iextract=->+1:17*/do {
134 // Add a semicolon in both the extracted and original function as we don't
135 // want to extract the semicolon below.
138 // CHECK: 1 'iextract' results:
139 // CHECK: static void extracted() {
141 // CHECK-NEXT: } while (true);{{$}}
142 // CHECK-NEXT: }{{[[:space:]].*}}
143 // CHECK-NEXT: void extractCantFindSemicolon() {
144 // CHECK-NEXT: extracted();{{$}}
150 void extractFindSemicolon() {
151 /*range jextract=->+1:17*/do {
152 } while (true) /*grab*/ ;
154 // CHECK: 1 'jextract' results:
155 // CHECK: static void extracted() {
157 // CHECK-NEXT: } while (true) /*grab*/ ;{{$}}
158 // CHECK-NEXT: }{{[[:space:]].*}}
159 // CHECK-NEXT: void extractFindSemicolon() {
160 // CHECK-NEXT: extracted();{{$}}
165 void careForNonCompoundSemicolons1() {
166 /*range kextract=->+1:11*/if (true)
169 // CHECK: 1 'kextract' results:
170 // CHECK: static void extracted() {
171 // CHECK-NEXT: if (true)
172 // CHECK-NEXT: call();{{$}}
173 // CHECK-NEXT: }{{[[:space:]].*}}
174 // CHECK-NEXT: void careForNonCompoundSemicolons1() {
175 // CHECK-NEXT: extracted();{{$}}
178 void careForNonCompoundSemicolons2() {
179 /*range lextract=->+3:1*/for (int i
= 0; i
< 10; ++i
)
182 // end right here111!
184 // CHECK: 1 'lextract' results:
185 // CHECK: static void extracted() {
186 // CHECK-NEXT: for (int i = 0; i < 10; ++i)
187 // CHECK-NEXT: while (i != 0)
188 // CHECK-NEXT: ;{{$}}
189 // CHECK-NEXT: }{{[[:space:]].*}}
190 // CHECK-NEXT: void careForNonCompoundSemicolons2() {
191 // CHECK-NEXT: extracted();{{$}}
195 void careForSwitchSemicolon() {
196 /*range mextract=->+0:53*/switch(0) default: break;
198 // CHECK: 1 'mextract' results:
199 // CHECK: static void extracted() {
200 // CHECK-NEXT: switch(0) default: break;{{$}}
201 // CHECK-NEXT: }{{[[:space:]].*}}
202 // CHECK-NEXT: void careForSwitchSemicolon() {
203 // CHECK-NEXT: extracted();{{$}}
206 void extractStatementNotSemiDecl() {
207 /*range nextract=->+0:38*/int x
= 5;
209 // CHECK: 1 'nextract' results:
210 // CHECK: static void extracted() {
211 // CHECK-NEXT: int x = 5;{{$}}
212 // CHECK-NEXT: }{{[[:space:]].*}}
213 // CHECK-NEXT: void extractStatementNotSemiDecl() {
214 // CHECK-NEXT: extracted();{{$}}