Skip to content

Commit

Permalink
fix: fixed a test failing in recent versions of the SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
bjansen committed Jun 28, 2023
1 parent 4043261 commit 01a5e2b
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package org.antlr.intellij.plugin.folding;

import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
import org.antlr.intellij.plugin.TestUtils;

import java.lang.reflect.Method;

public class ANTLRv4FoldingBuilderTest extends LightPlatformCodeInsightFixtureTestCase {

public void test_folding_should_not_throw_on_incomplete_prequel() {
// Given
myFixture.configureByText("foo.g4", "grammar foo;\n @\n");

// When
CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(myFixture.getEditor());
buildInitialFoldings();

// Then
FoldRegion[] allFoldRegions = myFixture.getEditor().getFoldingModel().getAllFoldRegions();
Expand All @@ -24,7 +28,7 @@ public void test_should_not_fold_single_line() {
myFixture.configureByText("foo.g4", "grammar foo;\n @members { int i; }\n");

// When
CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(myFixture.getEditor());
buildInitialFoldings();

// Then
FoldRegion[] allFoldRegions = myFixture.getEditor().getFoldingModel().getAllFoldRegions();
Expand All @@ -35,4 +39,13 @@ public void test_should_not_fold_single_line() {
protected void tearDown() throws Exception {
TestUtils.tearDownIgnoringObjectNotDisposedException(() -> super.tearDown());
}

private void buildInitialFoldings() {
try {
Method method = EditorTestUtil.class.getMethod("buildInitialFoldingsInBackground", Editor.class);
method.invoke(null, myFixture.getEditor());
} catch (ReflectiveOperationException e) {
CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(myFixture.getEditor());
}
}
}

0 comments on commit 01a5e2b

Please sign in to comment.