Skip to content

Commit 77f5017

Browse files
committed
Merge remote-tracking branch 'origin/R4_35_maintenance' into BETA_JAVA24
2 parents 2a7a21f + 05a59dd commit 77f5017

File tree

1 file changed

+45
-12
lines changed
  • org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/folding

1 file changed

+45
-12
lines changed

org.eclipse.jdt.text.tests/src/org/eclipse/jdt/text/tests/folding/FoldingTest.java

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,18 @@
1313
*******************************************************************************/
1414
package org.eclipse.jdt.text.tests.folding;
1515

16+
import static org.junit.Assume.assumeTrue;
17+
1618
import java.util.List;
1719

1820
import org.junit.After;
1921
import org.junit.Before;
2022
import org.junit.Rule;
2123
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.junit.runners.Parameterized;
26+
import org.junit.runners.Parameterized.Parameter;
27+
import org.junit.runners.Parameterized.Parameters;
2228

2329
import org.eclipse.jdt.testplugin.JavaProjectHelper;
2430

@@ -37,6 +43,7 @@
3743

3844
import org.eclipse.jdt.internal.ui.JavaPlugin;
3945

46+
@RunWith(Parameterized.class)
4047
public class FoldingTest {
4148
@Rule
4249
public ProjectTestSetup projectSetup= new ProjectTestSetup();
@@ -47,6 +54,14 @@ public class FoldingTest {
4754

4855
private IPackageFragment packageFragment;
4956

57+
@Parameters(name = "New folding active: {0}")
58+
public static Object[] data() {
59+
return new Object[] { true, false };
60+
}
61+
62+
@Parameter
63+
public boolean newFoldingActive;
64+
5065
@Before
5166
public void setUp() throws CoreException {
5267
jProject= projectSetup.getProject();
@@ -56,12 +71,13 @@ public void setUp() throws CoreException {
5671
}
5772
packageFragment= sourceFolder.createPackageFragment("org.example.test", false, null);
5873
IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
59-
store.setValue(PreferenceConstants.EDITOR_NEW_FOLDING_ENABLED, true);
60-
}
74+
store.setValue(PreferenceConstants.EDITOR_NEW_FOLDING_ENABLED, newFoldingActive);
75+
}
6176

6277
@After
6378
public void tearDown() throws CoreException {
6479
JavaProjectHelper.delete(jProject);
80+
JavaPlugin.getDefault().getPreferenceStore().setToDefault(PreferenceConstants.EDITOR_NEW_FOLDING_ENABLED);
6581
}
6682

6783
@Test
@@ -242,15 +258,17 @@ void b() { //here should be an annotation
242258
}
243259
}
244260
""";
245-
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 6);
261+
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, newFoldingActive ? 6 : 5);
246262

247263
List<IRegion> regions= FoldingTestUtils.getProjectionRangesOfFile(packageFragment, "TestFolding.java", str);
248264
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 1, 3); // 1. Javadoc
249265
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 4, 6); // 2. Javadoc
250266
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 7, 9); // 3. Javadoc
251267
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 12, 14); // 4. Javadoc
252268
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 15, 19); // Methode b()
253-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 16, 18); // 5. Javadoc
269+
if (newFoldingActive) {
270+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 16, 18); // 5. Javadoc
271+
}
254272
}
255273

256274
@Test
@@ -270,22 +288,26 @@ class SomeClass {}
270288
public void testMethodDeclarationFoldingWithSameLineStart() throws Exception {
271289
String str= """
272290
package org.example.test;
273-
public class Q {
274-
void a() {
275-
int i = 0;
276-
}void b() {
291+
class X {
292+
/* //here should be an annotation
293+
* a b
294+
*/
295+
void a() { //here should be an annotation
277296
278-
}
297+
} void b() { //here should be an annotation
298+
}
279299
}
280300
""";
281-
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 2);
301+
FoldingTestUtils.assertCodeHasRegions(packageFragment, "TestFolding.java", str, 3);
282302
List<IRegion> regions= FoldingTestUtils.getProjectionRangesOfFile(packageFragment, "TestFolding.java", str);
283-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 3); // 1. Method
284-
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 4, 5); // 2. Method
303+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 2, 4); // JavaDoc
304+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 5, 6); // 1. Method
305+
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(regions, str, 7, 7); // 2. Method
285306
}
286307

287308
@Test
288309
public void testIfStatementFolding() throws Exception {
310+
assumeTrue("Only doable with the new folding", newFoldingActive);
289311
String str= """
290312
package org.example.test;
291313
public class D {
@@ -303,6 +325,7 @@ void x() { //here should be an annotation
303325

304326
@Test
305327
public void testTryStatementFolding() throws Exception {
328+
assumeTrue("Only doable with the new folding", newFoldingActive);
306329
String str= """
307330
package org.example.test;
308331
public class E {
@@ -324,6 +347,7 @@ void x() { //here should be an annotation
324347

325348
@Test
326349
public void testWhileStatementFolding() throws Exception {
350+
assumeTrue("Only doable with the new folding", newFoldingActive);
327351
String str= """
328352
package org.example.test;
329353
public class F {
@@ -341,6 +365,7 @@ void x() { //here should be an annotation
341365

342366
@Test
343367
public void testForStatementFolding() throws Exception {
368+
assumeTrue("Only doable with the new folding", newFoldingActive);
344369
String str= """
345370
package org.example.test;
346371
public class G {
@@ -358,6 +383,7 @@ void x() { //here should be an annotation
358383

359384
@Test
360385
public void testEnhancedForStatementFolding() throws Exception {
386+
assumeTrue("Only doable with the new folding", newFoldingActive);
361387
String str= """
362388
package org.example.test;
363389
public class H {
@@ -375,6 +401,7 @@ void x() { //here should be an annotation
375401

376402
@Test
377403
public void testDoStatementFolding() throws Exception {
404+
assumeTrue("Only doable with the new folding", newFoldingActive);
378405
String str= """
379406
package org.example.test;
380407
public class I {
@@ -393,6 +420,7 @@ void x() { //here should be an annotation
393420

394421
@Test
395422
public void testSynchronizedStatementFolding() throws Exception {
423+
assumeTrue("Only doable with the new folding", newFoldingActive);
396424
String str= """
397425
package org.example.test;
398426
public class K {
@@ -410,6 +438,7 @@ void x() { //here should be an annotation
410438

411439
@Test
412440
public void testLambdaExpressionFolding() throws Exception {
441+
assumeTrue("Only doable with the new folding", newFoldingActive);
413442
String str= """
414443
package org.example.test;
415444
import java.util.function.Supplier;
@@ -429,6 +458,8 @@ void x() { //here should be an annotation
429458

430459
@Test
431460
public void testAnonymousClassDeclarationFolding() throws Exception {
461+
// FIXME this test should work for both foldings. See https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2022
462+
assumeTrue("Currently broken for the 'old' folding. See https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/2022", newFoldingActive);
432463
String str= """
433464
package org.example.test;
434465
public class M {
@@ -447,6 +478,7 @@ void y() { //here should be an annotation
447478

448479
@Test
449480
public void testEnumDeclarationFolding() throws Exception {
481+
assumeTrue("Only doable with the new folding", newFoldingActive);
450482
String str= """
451483
package org.example.test;
452484
public enum N { //here should be an annotation
@@ -475,6 +507,7 @@ public class O {
475507

476508
@Test
477509
public void testNestedFolding() throws Exception {
510+
assumeTrue("Only doable with the new folding", newFoldingActive);
478511
String str= """
479512
package org.example.test;
480513
public class P {

0 commit comments

Comments
 (0)