2424
2525class RedundantParenthesesCheckTest {
2626 @ Test
27- void testNoParenthesesShouldNotAddIssue () {
27+ void testPrimaryExpressionShouldNotAddIssue () {
2828 CheckVerifier .newVerifier ()
2929 .withCheck (new RedundantParenthesesCheck ())
3030 .onFile (
@@ -37,29 +37,87 @@ void testNoParenthesesShouldNotAddIssue() {
3737 }
3838
3939 @ Test
40- void testParenthesesShouldNotAddIssue () {
40+ void testBinaryExpressionShouldNotAddIssue () {
4141 CheckVerifier .newVerifier ()
4242 .withCheck (new RedundantParenthesesCheck ())
4343 .onFile (
4444 new DelphiTestUnitBuilder ()
4545 .appendImpl ("function GetInteger: Integer;" )
4646 .appendImpl ("begin" )
47- .appendImpl (" Result := (123) ;" )
47+ .appendImpl (" Result := 1 + 2 ;" )
4848 .appendImpl ("end;" ))
4949 .verifyNoIssues ();
5050 }
5151
5252 @ Test
53- void testRedundantParenthesesShouldAddIssue () {
53+ void testUnaryExpressionShouldNotAddIssue () {
5454 CheckVerifier .newVerifier ()
5555 .withCheck (new RedundantParenthesesCheck ())
5656 .onFile (
5757 new DelphiTestUnitBuilder ()
5858 .appendImpl ("function GetInteger: Integer;" )
5959 .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));" )
63121 .appendImpl ("end;" ))
64122 .verifyIssues ();
65123 }
0 commit comments