From e488e920d8429b7bfad593e59d680b3d8b4bda79 Mon Sep 17 00:00:00 2001 From: Roman Golyshev Date: Mon, 19 Aug 2019 18:48:16 +0300 Subject: [PATCH] KT-32366: Add tests for right preview window - also, fix missing test generation in `GenerateTests` bunch files (which was introduced in e54b43ba) --- .../kotlin/generators/tests/GenerateTests.kt | 2 + .../generators/tests/GenerateTests.kt.183 | 12 +++- .../generators/tests/GenerateTests.kt.as33 | 12 +++- .../generators/tests/GenerateTests.kt.as34 | 12 +++- .../generators/tests/GenerateTests.kt.as35 | 12 +++- .../generators/tests/GenerateTests.kt.as36 | 12 +++- .../scratch/ui/KtScratchFileEditorProvider.kt | 3 + .../bigSequentialOutputs.comp.preview | 22 ++++++++ .../rightPanelOutput/bigSequentialOutputs.kts | 20 +++++++ ...pression.longOutput.singleTop.comp.preview | 3 + .../shortExpression.longOutput.singleTop.kts | 2 + ...ression.shortOutput.singleTop.comp.preview | 1 + .../shortExpression.shortOutput.singleTop.kts | 2 + .../scratch/AbstractScratchRunActionTest.kt | 56 ++++++++++++++----- .../ScratchRunActionTestGenerated.java | 28 ++++++++++ .../kotlin/idea/scratch/foldingTestUtils.kt | 13 +++++ .../idea/scratch/foldingTestUtils.kt.as33 | 19 +++++++ 17 files changed, 203 insertions(+), 28 deletions(-) create mode 100644 idea/testData/scratch/rightPanelOutput/bigSequentialOutputs.comp.preview create mode 100644 idea/testData/scratch/rightPanelOutput/bigSequentialOutputs.kts create mode 100644 idea/testData/scratch/rightPanelOutput/shortExpression.longOutput.singleTop.comp.preview create mode 100644 idea/testData/scratch/rightPanelOutput/shortExpression.longOutput.singleTop.kts create mode 100644 idea/testData/scratch/rightPanelOutput/shortExpression.shortOutput.singleTop.comp.preview create mode 100644 idea/testData/scratch/rightPanelOutput/shortExpression.shortOutput.singleTop.kts create mode 100644 idea/tests/org/jetbrains/kotlin/idea/scratch/foldingTestUtils.kt create mode 100644 idea/tests/org/jetbrains/kotlin/idea/scratch/foldingTestUtils.kt.as33 diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index fdf6908e850..c66905ebb14 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -810,6 +810,8 @@ fun main(args: Array) { model("worksheet", extension = "ws.kts", testMethod = "doWorksheetCompilingTest", testClassName = "WorksheetCompiling", recursive = false) model("worksheet", extension = "ws.kts", testMethod = "doWorksheetReplTest", testClassName = "WorksheetRepl", recursive = false) model("worksheet/multiFile", extension = null, testMethod = "doWorksheetMultiFileTest", testClassName = "WorksheetMultiFile", recursive = false) + + model("scratch/rightPanelOutput", extension = "kts", testMethod = "doRightPreviewPanelOutputTest", testClassName = "ScratchRightPanelOutput", recursive = false) } testClass { diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.183 b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.183 index 9d8feb08a34..3398b0bac8d 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.183 +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.183 @@ -817,9 +817,15 @@ fun main(args: Array) { } testClass { - model("scratch", extension = "kts", testMethod = "doCompilingTest", testClassName = "Compiling", recursive = false) - model("scratch", extension = "kts", testMethod = "doReplTest", testClassName = "Repl", recursive = false) - model("scratch/multiFile", extension = null, testMethod = "doMultiFileTest", recursive = false) + model("scratch", extension = "kts", testMethod = "doScratchCompilingTest", testClassName = "ScratchCompiling", recursive = false) + model("scratch", extension = "kts", testMethod = "doScratchReplTest", testClassName = "ScratchRepl", recursive = false) + model("scratch/multiFile", extension = null, testMethod = "doScratchMultiFileTest", testClassName = "ScratchMultiFile", recursive = false) + + model("worksheet", extension = "ws.kts", testMethod = "doWorksheetCompilingTest", testClassName = "WorksheetCompiling", recursive = false) + model("worksheet", extension = "ws.kts", testMethod = "doWorksheetReplTest", testClassName = "WorksheetRepl", recursive = false) + model("worksheet/multiFile", extension = null, testMethod = "doWorksheetMultiFileTest", testClassName = "WorksheetMultiFile", recursive = false) + + model("scratch/rightPanelOutput", extension = "kts", testMethod = "doRightPreviewPanelOutputTest", testClassName = "ScratchRightPanelOutput", recursive = false) } testClass { diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as33 b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as33 index ff5b65cb0b8..cdf901a9141 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as33 +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as33 @@ -783,9 +783,15 @@ fun main(args: Array) { } testClass { - model("scratch", extension = "kts", testMethod = "doCompilingTest", testClassName = "Compiling", recursive = false) - model("scratch", extension = "kts", testMethod = "doReplTest", testClassName = "Repl", recursive = false) - model("scratch/multiFile", extension = null, testMethod = "doMultiFileTest", recursive = false) + model("scratch", extension = "kts", testMethod = "doScratchCompilingTest", testClassName = "ScratchCompiling", recursive = false) + model("scratch", extension = "kts", testMethod = "doScratchReplTest", testClassName = "ScratchRepl", recursive = false) + model("scratch/multiFile", extension = null, testMethod = "doScratchMultiFileTest", testClassName = "ScratchMultiFile", recursive = false) + + model("worksheet", extension = "ws.kts", testMethod = "doWorksheetCompilingTest", testClassName = "WorksheetCompiling", recursive = false) + model("worksheet", extension = "ws.kts", testMethod = "doWorksheetReplTest", testClassName = "WorksheetRepl", recursive = false) + model("worksheet/multiFile", extension = null, testMethod = "doWorksheetMultiFileTest", testClassName = "WorksheetMultiFile", recursive = false) + + model("scratch/rightPanelOutput", extension = "kts", testMethod = "doRightPreviewPanelOutputTest", testClassName = "ScratchRightPanelOutput", recursive = false) } testClass { diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as34 b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as34 index e4f1b74a49e..2ba53a3b2b7 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as34 +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as34 @@ -787,9 +787,15 @@ fun main(args: Array) { } testClass { - model("scratch", extension = "kts", testMethod = "doCompilingTest", testClassName = "Compiling", recursive = false) - model("scratch", extension = "kts", testMethod = "doReplTest", testClassName = "Repl", recursive = false) - model("scratch/multiFile", extension = null, testMethod = "doMultiFileTest", recursive = false) + model("scratch", extension = "kts", testMethod = "doScratchCompilingTest", testClassName = "ScratchCompiling", recursive = false) + model("scratch", extension = "kts", testMethod = "doScratchReplTest", testClassName = "ScratchRepl", recursive = false) + model("scratch/multiFile", extension = null, testMethod = "doScratchMultiFileTest", testClassName = "ScratchMultiFile", recursive = false) + + model("worksheet", extension = "ws.kts", testMethod = "doWorksheetCompilingTest", testClassName = "WorksheetCompiling", recursive = false) + model("worksheet", extension = "ws.kts", testMethod = "doWorksheetReplTest", testClassName = "WorksheetRepl", recursive = false) + model("worksheet/multiFile", extension = null, testMethod = "doWorksheetMultiFileTest", testClassName = "WorksheetMultiFile", recursive = false) + + model("scratch/rightPanelOutput", extension = "kts", testMethod = "doRightPreviewPanelOutputTest", testClassName = "ScratchRightPanelOutput", recursive = false) } testClass { diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as35 b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as35 index ff5b65cb0b8..cdf901a9141 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as35 +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as35 @@ -783,9 +783,15 @@ fun main(args: Array) { } testClass { - model("scratch", extension = "kts", testMethod = "doCompilingTest", testClassName = "Compiling", recursive = false) - model("scratch", extension = "kts", testMethod = "doReplTest", testClassName = "Repl", recursive = false) - model("scratch/multiFile", extension = null, testMethod = "doMultiFileTest", recursive = false) + model("scratch", extension = "kts", testMethod = "doScratchCompilingTest", testClassName = "ScratchCompiling", recursive = false) + model("scratch", extension = "kts", testMethod = "doScratchReplTest", testClassName = "ScratchRepl", recursive = false) + model("scratch/multiFile", extension = null, testMethod = "doScratchMultiFileTest", testClassName = "ScratchMultiFile", recursive = false) + + model("worksheet", extension = "ws.kts", testMethod = "doWorksheetCompilingTest", testClassName = "WorksheetCompiling", recursive = false) + model("worksheet", extension = "ws.kts", testMethod = "doWorksheetReplTest", testClassName = "WorksheetRepl", recursive = false) + model("worksheet/multiFile", extension = null, testMethod = "doWorksheetMultiFileTest", testClassName = "WorksheetMultiFile", recursive = false) + + model("scratch/rightPanelOutput", extension = "kts", testMethod = "doRightPreviewPanelOutputTest", testClassName = "ScratchRightPanelOutput", recursive = false) } testClass { diff --git a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as36 b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as36 index ff5b65cb0b8..cdf901a9141 100644 --- a/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as36 +++ b/generators/tests/org/jetbrains/kotlin/generators/tests/GenerateTests.kt.as36 @@ -783,9 +783,15 @@ fun main(args: Array) { } testClass { - model("scratch", extension = "kts", testMethod = "doCompilingTest", testClassName = "Compiling", recursive = false) - model("scratch", extension = "kts", testMethod = "doReplTest", testClassName = "Repl", recursive = false) - model("scratch/multiFile", extension = null, testMethod = "doMultiFileTest", recursive = false) + model("scratch", extension = "kts", testMethod = "doScratchCompilingTest", testClassName = "ScratchCompiling", recursive = false) + model("scratch", extension = "kts", testMethod = "doScratchReplTest", testClassName = "ScratchRepl", recursive = false) + model("scratch/multiFile", extension = null, testMethod = "doScratchMultiFileTest", testClassName = "ScratchMultiFile", recursive = false) + + model("worksheet", extension = "ws.kts", testMethod = "doWorksheetCompilingTest", testClassName = "WorksheetCompiling", recursive = false) + model("worksheet", extension = "ws.kts", testMethod = "doWorksheetReplTest", testClassName = "WorksheetRepl", recursive = false) + model("worksheet/multiFile", extension = null, testMethod = "doWorksheetMultiFileTest", testClassName = "WorksheetMultiFile", recursive = false) + + model("scratch/rightPanelOutput", extension = "kts", testMethod = "doRightPreviewPanelOutputTest", testClassName = "ScratchRightPanelOutput", recursive = false) } testClass { diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/KtScratchFileEditorProvider.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/KtScratchFileEditorProvider.kt index 9962a749d4d..9a89debeab5 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/KtScratchFileEditorProvider.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/scratch/ui/KtScratchFileEditorProvider.kt @@ -119,6 +119,9 @@ class KtScratchFileEditorWithPreview private constructor( layout = if (isPreviewEnabled) Layout.SHOW_EDITOR_AND_PREVIEW else Layout.SHOW_EDITOR } + @TestOnly + fun getPreviewEditor(): TextEditor = previewTextEditor + companion object { fun create(scratchFile: ScratchFile): KtScratchFileEditorWithPreview { val textEditorProvider = TextEditorProvider.getInstance() diff --git a/idea/testData/scratch/rightPanelOutput/bigSequentialOutputs.comp.preview b/idea/testData/scratch/rightPanelOutput/bigSequentialOutputs.comp.preview new file mode 100644 index 00000000000..f0fe9b7125c --- /dev/null +++ b/idea/testData/scratch/rightPanelOutput/bigSequentialOutputs.comp.preview @@ -0,0 +1,22 @@ +Hello world + +Hello world + + + +Hello world +Hello world +Hello world + +Hello world +Hello world +Hello world +Hello world + +Hello world +Hello world +Hello world + +Hello world +Hello world +Hello world \ No newline at end of file diff --git a/idea/testData/scratch/rightPanelOutput/bigSequentialOutputs.kts b/idea/testData/scratch/rightPanelOutput/bigSequentialOutputs.kts new file mode 100644 index 00000000000..161b971eca5 --- /dev/null +++ b/idea/testData/scratch/rightPanelOutput/bigSequentialOutputs.kts @@ -0,0 +1,20 @@ +// PREVIEW_ENABLED: TRUE +println("Hello world") + +for (x in 1..1) { + println("Hello world") +} + +for (x in 1..3) { + println("Hello world") +} + +for (x in 1..4) { + println("Hello world") +} + +println(List(3) { "Hello world" }.joinToString(separator = "\n")) + +println( + List(3) { "Hello world" }.joinToString(separator = "\n") +) \ No newline at end of file diff --git a/idea/testData/scratch/rightPanelOutput/shortExpression.longOutput.singleTop.comp.preview b/idea/testData/scratch/rightPanelOutput/shortExpression.longOutput.singleTop.comp.preview new file mode 100644 index 00000000000..3c9d52d12d4 --- /dev/null +++ b/idea/testData/scratch/rightPanelOutput/shortExpression.longOutput.singleTop.comp.preview @@ -0,0 +1,3 @@ +First string +Second string +Third string \ No newline at end of file diff --git a/idea/testData/scratch/rightPanelOutput/shortExpression.longOutput.singleTop.kts b/idea/testData/scratch/rightPanelOutput/shortExpression.longOutput.singleTop.kts new file mode 100644 index 00000000000..9572eac0a64 --- /dev/null +++ b/idea/testData/scratch/rightPanelOutput/shortExpression.longOutput.singleTop.kts @@ -0,0 +1,2 @@ +// PREVIEW_ENABLED: TRUE +println("First string\nSecond string\nThird string") \ No newline at end of file diff --git a/idea/testData/scratch/rightPanelOutput/shortExpression.shortOutput.singleTop.comp.preview b/idea/testData/scratch/rightPanelOutput/shortExpression.shortOutput.singleTop.comp.preview new file mode 100644 index 00000000000..d858dd9bf20 --- /dev/null +++ b/idea/testData/scratch/rightPanelOutput/shortExpression.shortOutput.singleTop.comp.preview @@ -0,0 +1 @@ +Single string \ No newline at end of file diff --git a/idea/testData/scratch/rightPanelOutput/shortExpression.shortOutput.singleTop.kts b/idea/testData/scratch/rightPanelOutput/shortExpression.shortOutput.singleTop.kts new file mode 100644 index 00000000000..96b7fed5ecb --- /dev/null +++ b/idea/testData/scratch/rightPanelOutput/shortExpression.shortOutput.singleTop.kts @@ -0,0 +1,2 @@ +// PREVIEW_ENABLED: TRUE +println("Single string") \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt index 42a30211bb2..d80d2f051a8 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/scratch/AbstractScratchRunActionTest.kt @@ -45,20 +45,24 @@ import java.io.File abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() { + fun doRightPreviewPanelOutputTest(fileName: String) { + doRightPreviewPanelOutputTest(fileName = fileName, isRepl = false) + } + fun doWorksheetReplTest(fileName: String) { - doTest(fileName = fileName, isRepl = true, isWorksheet = true) + doInlayOutputTest(fileName = fileName, isRepl = true, isWorksheet = true) } fun doScratchReplTest(fileName: String) { - doTest(fileName = fileName, isRepl = true, isWorksheet = false) + doInlayOutputTest(fileName = fileName, isRepl = true, isWorksheet = false) } fun doWorksheetCompilingTest(fileName: String) { - doTest(fileName = fileName, isRepl = false, isWorksheet = true) + doInlayOutputTest(fileName = fileName, isRepl = false, isWorksheet = true) } fun doScratchCompilingTest(fileName: String) { - doTest(fileName = fileName, isRepl = false, isWorksheet = false) + doInlayOutputTest(fileName = fileName, isRepl = false, isWorksheet = false) } fun doWorksheetMultiFileTest(dirName: String) { @@ -97,18 +101,36 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() { PsiTestUtil.setCompilerOutputPath(myFixture.module, outputDir.path, false) val mainFileName = "$dirName/${getTestName(true)}.$mainFileExtension" - doTest(mainFileName, isRepl = false, isWorksheet = isWorksheet) + doInlayOutputTest(mainFileName, isRepl = false, isWorksheet = isWorksheet) launchAction(ClearScratchAction()) - doTest(mainFileName, isRepl = true, isWorksheet = isWorksheet) + doInlayOutputTest(mainFileName, isRepl = true, isWorksheet = isWorksheet) ModuleRootModificationUtil.updateModel(myFixture.module) { model -> model.getModuleExtension(CompilerModuleExtension::class.java).inheritCompilerOutputPath(true) } } - fun doTest(fileName: String, isRepl: Boolean, isWorksheet: Boolean) { + private fun doInlayOutputTest(fileName: String, isRepl: Boolean, isWorksheet: Boolean) { + configureAndLaunchScratch(fileName = fileName, isRepl = isRepl, isWorksheet = isWorksheet) + + val actualOutput = getFileTextWithInlays() + + val expectedFile = getExpectedFile(fileName, isRepl, suffix = "after") + KotlinTestUtils.assertEqualsToFile(expectedFile, actualOutput) + } + + private fun doRightPreviewPanelOutputTest(fileName: String, isRepl: Boolean) { + configureAndLaunchScratch(fileName = fileName, isRepl = isRepl, isWorksheet = false) + + val previewTextWithFoldings = getPreviewTextWithFoldings() + + val expectedFile = getExpectedFile(fileName, isRepl, suffix = "preview") + KotlinTestUtils.assertEqualsToFile(expectedFile, previewTextWithFoldings) + } + + private fun configureAndLaunchScratch(fileName: String, isRepl: Boolean, isWorksheet: Boolean) { val sourceFile = File(testDataPath, fileName) val fileText = sourceFile.readText().inlinePropertiesValues(isRepl) @@ -122,16 +144,16 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() { launchScratch() waitUntilScratchFinishes() + } - val actualOutput = getFileTextWithInlays() - + private fun getExpectedFile(fileName: String, isRepl: Boolean, suffix: String): File { val expectedFileName = if (isRepl) { - fileName.replace(".kts", ".repl.after") + fileName.replace(".kts", ".repl.$suffix") } else { - fileName.replace(".kts", ".comp.after") + fileName.replace(".kts", ".comp.$suffix") } - val expectedFile = File(testDataPath, expectedFileName) - KotlinTestUtils.assertEqualsToFile(expectedFile, actualOutput) + + return File(testDataPath, expectedFileName) } protected fun String.inlinePropertiesValues( @@ -158,6 +180,14 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() { return actualOutput.toString().trim() } + private fun getPreviewTextWithFoldings(): String { + val scratchFileEditor = getScratchEditorForSelectedFile(myManager, myFixture.file.virtualFile) + ?: error("Couldn't find scratch panel") + + val previewEditor = scratchFileEditor.getPreviewEditor() + return getFoldingData(previewEditor.editor, withCollapseStatus = false) + } + protected fun getInlays(start: Int = 0, end: Int = myFixture.file.textLength): List { val inlineElementsInRange = myFixture.editor.inlayModel.getInlays(start, end) return inlineElementsInRange.map { it.renderer as InlayScratchFileRenderer } diff --git a/idea/tests/org/jetbrains/kotlin/idea/scratch/ScratchRunActionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/scratch/ScratchRunActionTestGenerated.java index 3ddb446b270..852173852af 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/scratch/ScratchRunActionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/scratch/ScratchRunActionTestGenerated.java @@ -276,4 +276,32 @@ public class ScratchRunActionTestGenerated extends AbstractScratchRunActionTest runTest("idea/testData/worksheet/multiFile/javaDepScriptRuntime/"); } } + + @TestMetadata("idea/testData/scratch/rightPanelOutput") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ScratchRightPanelOutput extends AbstractScratchRunActionTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doRightPreviewPanelOutputTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInScratchRightPanelOutput() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/scratch/rightPanelOutput"), Pattern.compile("^(.+)\\.kts$"), TargetBackend.ANY, false); + } + + @TestMetadata("bigSequentialOutputs.kts") + public void testBigSequentialOutputs() throws Exception { + runTest("idea/testData/scratch/rightPanelOutput/bigSequentialOutputs.kts"); + } + + @TestMetadata("shortExpression.longOutput.singleTop.kts") + public void testShortExpression_longOutput_singleTop() throws Exception { + runTest("idea/testData/scratch/rightPanelOutput/shortExpression.longOutput.singleTop.kts"); + } + + @TestMetadata("shortExpression.shortOutput.singleTop.kts") + public void testShortExpression_shortOutput_singleTop() throws Exception { + runTest("idea/testData/scratch/rightPanelOutput/shortExpression.shortOutput.singleTop.kts"); + } + } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/scratch/foldingTestUtils.kt b/idea/tests/org/jetbrains/kotlin/idea/scratch/foldingTestUtils.kt new file mode 100644 index 00000000000..33baa2f8f90 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/scratch/foldingTestUtils.kt @@ -0,0 +1,13 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.scratch + +import com.intellij.openapi.editor.Editor +import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl + +fun getFoldingData(editor: Editor, withCollapseStatus: Boolean): String { + return CodeInsightTestFixtureImpl.getFoldingData(editor, withCollapseStatus) +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/scratch/foldingTestUtils.kt.as33 b/idea/tests/org/jetbrains/kotlin/idea/scratch/foldingTestUtils.kt.as33 new file mode 100644 index 00000000000..7ac0f2186be --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/scratch/foldingTestUtils.kt.as33 @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.idea.scratch + +import com.intellij.openapi.editor.Editor +import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl + +fun getFoldingData(topEditor: Editor, withCollapseStatus: Boolean): String { + return CodeInsightTestFixtureImpl.getTagsFromSegments( + topEditor.document.text, + topEditor.foldingModel.allFoldRegions.asList(), + "fold" + ) { foldRegion -> + """text='${foldRegion.placeholderText}'${if (withCollapseStatus) """ expand='${foldRegion.isExpanded}'""" else ""}""" + } +}