Skip to content

Commit

Permalink
Add test for #1951
Browse files Browse the repository at this point in the history
- fixes #1951
  • Loading branch information
jjohnstn committed Jan 29, 2025
1 parent 5b69fb7 commit 2f5c9fc
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20502,6 +20502,57 @@ void foo(int i) {
assertRefactoringResultAsExpected(new ICompilationUnit[] {cu1}, new String[] {expected1}, null);
}

@Test
public void testAddParenthesesIssue1951() throws Exception {
IPackageFragment pack1= fSourceFolder.createPackageFragment("test1", false, null);
String sample= """
package test1;
public class E {
void foo(int i) {
if (i == 0 || i == 1 /* i is 0 or 1 */)
System.out.println(i); // if comment
\s
while (i > 0 && i < 10 /* i gt 0 and lt 10 */)
System.out.println(1); // while comment
\s
boolean b= i != -1 && i > 10 && i < 100 || i > 20;
\s
do
++i; // do comment
while (i > 5 && b || i < 100 && i > 90);
}
}
""";
ICompilationUnit cu1= pack1.createCompilationUnit("E.java", sample, false, null);

enable(CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS);
enable(CleanUpConstants.CONTROL_STATEMENTS_USE_BLOCKS_ALWAYS);

sample= """
package test1;
public class E {
void foo(int i) {
if (i == 0 || i == 1 /* i is 0 or 1 */) {
System.out.println(i); // if comment
}
\s
while (i > 0 && i < 10 /* i gt 0 and lt 10 */) {
System.out.println(1); // while comment
}
\s
boolean b= i != -1 && i > 10 && i < 100 || i > 20;
\s
do {
++i; // do comment
} while (i > 5 && b || i < 100 && i > 90);
}
}
""";
String expected1= sample;

assertRefactoringResultAsExpected(new ICompilationUnit[] {cu1}, new String[] {expected1}, null);
}

@Test
public void testRemoveParentheses01() throws Exception {

Expand Down

0 comments on commit 2f5c9fc

Please sign in to comment.