24
24
25
25
class RedundantParenthesesCheckTest {
26
26
@ Test
27
- void testNoParenthesesShouldNotAddIssue () {
27
+ void testPrimaryExpressionShouldNotAddIssue () {
28
28
CheckVerifier .newVerifier ()
29
29
.withCheck (new RedundantParenthesesCheck ())
30
30
.onFile (
@@ -37,29 +37,87 @@ void testNoParenthesesShouldNotAddIssue() {
37
37
}
38
38
39
39
@ Test
40
- void testParenthesesShouldNotAddIssue () {
40
+ void testBinaryExpressionShouldNotAddIssue () {
41
41
CheckVerifier .newVerifier ()
42
42
.withCheck (new RedundantParenthesesCheck ())
43
43
.onFile (
44
44
new DelphiTestUnitBuilder ()
45
45
.appendImpl ("function GetInteger: Integer;" )
46
46
.appendImpl ("begin" )
47
- .appendImpl (" Result := (123) ;" )
47
+ .appendImpl (" Result := 1 + 2 ;" )
48
48
.appendImpl ("end;" ))
49
49
.verifyNoIssues ();
50
50
}
51
51
52
52
@ Test
53
- void testRedundantParenthesesShouldAddIssue () {
53
+ void testUnaryExpressionShouldNotAddIssue () {
54
54
CheckVerifier .newVerifier ()
55
55
.withCheck (new RedundantParenthesesCheck ())
56
56
.onFile (
57
57
new DelphiTestUnitBuilder ()
58
58
.appendImpl ("function GetInteger: Integer;" )
59
59
.appendImpl ("begin" )
60
- .appendImpl (" // Fix@[+2:13 to +2:14] <<>>" )
61
- .appendImpl (" // Fix@[+1:17 to +1:18] <<>>" )
62
- .appendImpl (" Result := ((123)); // Noncompliant" )
60
+ .appendImpl (" Result := -123;" )
61
+ .appendImpl ("end;" ))
62
+ .verifyNoIssues ();
63
+ }
64
+
65
+ @ Test
66
+ void testParenthesesOnBinaryExpressionShouldNotAddIssue () {
67
+ CheckVerifier .newVerifier ()
68
+ .withCheck (new RedundantParenthesesCheck ())
69
+ .onFile (
70
+ new DelphiTestUnitBuilder ()
71
+ .appendImpl ("function GetInteger: Integer;" )
72
+ .appendImpl ("begin" )
73
+ .appendImpl (" Result := (1 + 2);" )
74
+ .appendImpl ("end;" ))
75
+ .verifyNoIssues ();
76
+ }
77
+
78
+ @ Test
79
+ void testParenthesesOnUnaryExpressionShouldNotAddIssue () {
80
+ CheckVerifier .newVerifier ()
81
+ .withCheck (new RedundantParenthesesCheck ())
82
+ .onFile (
83
+ new DelphiTestUnitBuilder ()
84
+ .appendImpl ("function GetInteger: Integer;" )
85
+ .appendImpl ("begin" )
86
+ .appendImpl (" Result := (-123);" )
87
+ .appendImpl ("end;" ))
88
+ .verifyNoIssues ();
89
+ }
90
+
91
+ @ Test
92
+ void testParenthesesOnParenthesizedExpressionShouldAddIssue () {
93
+ CheckVerifier .newVerifier ()
94
+ .withCheck (new RedundantParenthesesCheck ())
95
+ .onFile (
96
+ new DelphiTestUnitBuilder ()
97
+ .appendImpl ("function GetInteger: Integer;" )
98
+ .appendImpl ("begin" )
99
+ .appendImpl (" // Fix@[+2:12 to +2:13] <<>>" )
100
+ .appendImpl (" // Fix@[+1:20 to +1:21] <<>>" )
101
+ .appendImpl (" Result := ((1 + 2)); // Noncompliant" )
102
+ .appendImpl ("end;" ))
103
+ .verifyIssues ();
104
+ }
105
+
106
+ @ Test
107
+ void testParenthesesOnPrimaryExpressionShouldAddIssue () {
108
+ CheckVerifier .newVerifier ()
109
+ .withCheck (new RedundantParenthesesCheck ())
110
+ .onFile (
111
+ new DelphiTestUnitBuilder ()
112
+ .appendImpl ("function GetInteger: Integer;" )
113
+ .appendImpl ("begin" )
114
+ .appendImpl (" // Fix qf1@[+6:12 to +6:13] <<>>" )
115
+ .appendImpl (" // Fix qf2@[+5:13 to +5:14] <<>>" )
116
+ .appendImpl (" // Fix qf2@[+4:17 to +4:18] <<>>" )
117
+ .appendImpl (" // Fix qf1@[+3:18 to +3:19] <<>>" )
118
+ .appendImpl (" // Noncompliant@+2" )
119
+ .appendImpl (" // Noncompliant@+1" )
120
+ .appendImpl (" Result := ((123));" )
63
121
.appendImpl ("end;" ))
64
122
.verifyIssues ();
65
123
}
0 commit comments