Skip to content

Commit c126026

Browse files
author
IgnatSergeev
committed
Add refactoring actions tests
1 parent 31444e8 commit c126026

File tree

5 files changed

+195
-0
lines changed

5 files changed

+195
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: clang-refactor redundand-if -location=test:%s %s -- 2>&1 | grep -v CHECK | FileCheck %s
2+
3+
void bodyLocation() {
4+
if (false) {
5+
int thenVar;
6+
/*loc body_loc=*/
7+
}
8+
}
9+
10+
// CHECK: 1 'body_loc' results:
11+
// CHECK: void bodyLocation() {
12+
// CHECK-NEXT: {{^ }}
13+
// CHECK-NEXT: }
14+
15+
void ifFalse() {
16+
if (/*loc false=*/false) {
17+
int thenVar;
18+
} else {
19+
int elseVar;
20+
}
21+
}
22+
23+
// CHECK: 1 'false' results:
24+
// CHECK: void ifFalse() {
25+
// CHECK-NEXT: {
26+
// CHECK-NEXT: int elseVar;
27+
// CHECK-NEXT: }
28+
// CHECK-NEXT: }
29+
30+
void ifFalseNoElse() {
31+
if (/*loc false_no_else=*/false) {
32+
int thenVar;
33+
}
34+
}
35+
36+
// CHECK: 1 'false_no_else' results:
37+
// CHECK: void ifFalseNoElse() {
38+
// CHECK-NEXT: {{^ }}
39+
// CHECK-NEXT: }
40+
41+
void noMatchingLocation() {
42+
/*loc no_matching_location=*/
43+
if (false) {
44+
int thenVar;
45+
}
46+
}
47+
48+
// CHECK: 1 'no_matching_location' results:
49+
// CHECK-NEXT: refactoring action can't be initiated without a matching location
50+
51+
void ifTrue() {
52+
if (/*loc true=*/true) {
53+
int thenVar;
54+
} else {
55+
int elseVar;
56+
}
57+
}
58+
59+
// CHECK: 1 'true' results:
60+
// CHECK: void ifTrue() {
61+
// CHECK-NEXT: {
62+
// CHECK-NEXT: int thenVar;
63+
// CHECK-NEXT: }
64+
// CHECK-NEXT: }
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// RUN: clang-refactor redundand-while -location=test:%s %s -- 2>&1 | grep -v CHECK | FileCheck %s
2+
3+
void bodyLocation() {
4+
while (false) {
5+
int thenVar;
6+
/*loc body_loc=*/
7+
}
8+
}
9+
10+
// CHECK: 1 'body_loc' results:
11+
// CHECK: void bodyLocation() {
12+
// CHECK-NEXT: {{^ }}
13+
// CHECK-NEXT: }
14+
15+
void conditionLoc() {
16+
while (/*loc false=*/false) {
17+
int thenVar;
18+
}
19+
}
20+
21+
// CHECK: 1 'false' results:
22+
// CHECK: void conditionLoc() {
23+
// CHECK-NEXT: {{^ }}
24+
// CHECK-NEXT: }
25+
26+
void noMatchingLocation() {
27+
/*loc no_matching_location=*/
28+
while (false) {
29+
int thenVar;
30+
}
31+
}
32+
33+
// CHECK: 1 'no_matching_location' results:
34+
// CHECK-NEXT: refactoring action can't be initiated without a matching location
35+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// RUN: clang-refactor simplify-expr -location=test:%s %s -- 2>&1 | grep -v CHECK | FileCheck %s
2+
3+
bool foo = true;
4+
bool bar = false /*loc and_false_lhs=*/ && foo;
5+
6+
// CHECK: 1 'and_false_lhs' results:
7+
// CHECK: bool bar = false;
8+
9+
bool foo2 = true;
10+
bool bar2 = foo2 /*loc and_false_rhs=*/ && false;
11+
12+
// CHECK: 1 'and_false_rhs' results:
13+
// CHECK: bool bar2 = false;
14+
15+
bool foo3 = true;
16+
bool bar3 = true /*loc and_true_lhs=*/ && foo3;
17+
18+
// CHECK: 1 'and_true_lhs' results:
19+
// CHECK: bool bar3 = foo3;
20+
21+
bool foo4 = true;
22+
bool bar4 = foo4 /*loc and_true_rhs=*/ && true;
23+
24+
// CHECK: 1 'and_true_rhs' results:
25+
// CHECK: bool bar4 = foo4;
26+
27+
bool foo5 = true;
28+
bool bar5 = /*loc no_matching_location=*/ true || foo5;
29+
30+
// CHECK: 1 'no_matching_location' results:
31+
// CHECK-NEXT: refactoring action can't be initiated without a matching location
32+
33+
bool foo6 = true;
34+
bool bar6 = false /*loc or_false_lhs=*/ || foo6;
35+
36+
// CHECK: 1 'or_false_lhs' results:
37+
// CHECK: bool bar6 = foo6;
38+
39+
bool foo7 = true;
40+
bool bar7 = foo7 /*loc or_false_rhs=*/ || false;
41+
42+
// CHECK: 1 'or_false_rhs' results:
43+
// CHECK: bool bar7 = foo7;
44+
45+
bool foo8 = true;
46+
bool bar8 = true /*loc or_true_lhs=*/ || foo8;
47+
48+
// CHECK: 1 'or_true_lhs' results:
49+
// CHECK: bool bar8 = true;
50+
//
51+
bool foo9 = true;
52+
bool bar9 = foo9 /*loc or_true_rhs=*/ || true;
53+
54+
// CHECK: 1 'or_true_rhs' results:
55+
// CHECK: bool bar9 = true;
56+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: clang-refactor unused-field -location=test:%s %s -- 2>&1 | grep -v CHECK | FileCheck %s
2+
3+
struct Bar {
4+
/*loc used=*/int member;
5+
/*loc unused=*/int unusedMember;
6+
};
7+
8+
void foo() {
9+
Bar a;
10+
a.member = 1;
11+
}
12+
13+
// CHECK: 1 'unused' results:
14+
// CHECK: struct Bar {
15+
// CHECK-NEXT: /*loc used=*/int member;
16+
// CHECK-NEXT: /*loc unused=*/
17+
// CHECK-NEXT: };
18+
19+
// CHECK: 1 'used' results:
20+
// CHECK-NEXT: refactoring action can't be initiated without a matching location
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: clang-refactor unused-method -location=test:%s %s -- 2>&1 | grep -v CHECK | FileCheck %s
2+
3+
struct Bar {
4+
/*loc used=*/void used() {}
5+
/*loc unused=*/void unused() {}
6+
};
7+
8+
void foo() {
9+
Bar a;
10+
a.used();
11+
}
12+
13+
// CHECK: 1 'unused' results:
14+
// CHECK: struct Bar {
15+
// CHECK-NEXT: /*loc used=*/void used() {}
16+
// CHECK-NEXT: /*loc unused=*/
17+
// CHECK-NEXT: };
18+
19+
// CHECK: 1 'used' results:
20+
// CHECK-NEXT: refactoring action can't be initiated without a matching location

0 commit comments

Comments
 (0)