-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
963 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
....text.tests/src/org/eclipse/jdt/text/tests/folding/CustomFoldingRegionNewFoldingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Daniel Schmid and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Daniel Schmid - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.jdt.text.tests.folding; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import org.eclipse.core.runtime.CoreException; | ||
|
||
import org.eclipse.jface.preference.IPreferenceStore; | ||
|
||
import org.eclipse.jface.text.IRegion; | ||
|
||
import org.eclipse.jdt.ui.PreferenceConstants; | ||
|
||
import org.eclipse.jdt.internal.ui.JavaPlugin; | ||
|
||
public class CustomFoldingRegionNewFoldingTest extends CustomFoldingRegionTest { | ||
|
||
@Before | ||
@Override | ||
public void setUp() throws CoreException { | ||
super.setUp(); | ||
IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); | ||
store.setValue(PreferenceConstants.EDITOR_NEW_FOLDING_ENABLED, true); | ||
} | ||
|
||
|
||
@After | ||
@Override | ||
public void tearDown() throws CoreException { | ||
super.tearDown(); | ||
IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore(); | ||
store.setToDefault(PreferenceConstants.EDITOR_NEW_FOLDING_ENABLED); | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCustomFoldingRegionsInMethod() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
public class Test { | ||
void a(){ | ||
// region | ||
// endregion | ||
} | ||
} | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(2, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 2, 5); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 5); | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCustomFoldingRegionsMultipleLevels() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
// region outside class | ||
public class Test { | ||
// region outside method | ||
void a(){ | ||
// endregion should be ignored | ||
// region inside method | ||
System.out.println("Hello World"); | ||
// endregion inside method | ||
} | ||
// endregion outside method | ||
} | ||
// endregion outside class | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(4, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 1, 12);//outside class | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 10);//outside method | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 4, 8);//void a() | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 6, 8);//inside method | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCustomFoldingRegionsUsingSpecialCommentTypes() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
public class Test { | ||
void a(){ | ||
/* region multiline | ||
*/ | ||
/** region javadoc */ | ||
/** endregion javadoc */ | ||
/* endregion multiline | ||
*/ | ||
} | ||
} | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(5, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 9);//void a() | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 4, 5);// multiline (comment) | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 4, 9);// multiline (folding region) | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 6, 7);// javadoc | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 8, 9);// multiline (last comment) | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCustomRegionsWithLocalClass() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
public class Test { | ||
void a(){ | ||
// region | ||
int i; | ||
// endregion | ||
class Inner{ | ||
} | ||
} | ||
} | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(2, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 10);//void a() | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 4, 7);//region | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCustomRegionsAroundFieldAndMethod() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
public class Test { | ||
// region | ||
int a; | ||
void b(){ | ||
} | ||
// endregion | ||
} | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(2, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 9);//region | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 6, 7);//void b() | ||
} | ||
|
||
@Test | ||
@Override | ||
public void testCommentsInEmptyBlocks() throws Exception { | ||
String str= """ | ||
package org.example.test; | ||
public class Test { | ||
void a(){ | ||
{/* region 1*/} | ||
System.out.println("Hello World"); | ||
{/* endregion 1*/} | ||
} | ||
} | ||
"""; | ||
List<IRegion> projectionRanges= getProjectionRangesOfFile(str); | ||
assertEquals(2, projectionRanges.size()); | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 2, 5);//void a() | ||
FoldingTestUtils.assertContainsRegionUsingStartAndEndLine(projectionRanges, str, 3, 5);//region 1 | ||
} | ||
|
||
} |
Oops, something went wrong.