Configuration: move scratch tests to separate module

This commit is contained in:
Natalia Selezneva
2019-10-03 09:39:35 +03:00
parent f2f97a9991
commit 17dcdb59de
103 changed files with 174 additions and 78 deletions
+50
View File
@@ -0,0 +1,50 @@
plugins {
kotlin("jvm")
id("jps-compatible")
}
dependencies {
testRuntime(intellijDep())
testRuntime(intellijRuntimeAnnotations())
testCompile(project(":compiler:backend"))
testCompile(project(":idea:idea-jvm"))
testCompile(project(":kotlin-test:kotlin-test-junit"))
testCompile(projectTests(":compiler:tests-common"))
testCompile(projectTests(":idea:idea-test-framework")) { isTransitive = false }
testCompile(projectTests(":idea"))
testCompile(commonDep("junit:junit"))
testRuntime(project(":allopen-ide-plugin")) { isTransitive = false }
testRuntime(project(":kotlin-allopen-compiler-plugin"))
testRuntime(project(":noarg-ide-plugin")) { isTransitive = false }
testRuntime(project(":kotlin-noarg-compiler-plugin"))
testRuntime(project(":plugins:annotation-based-compiler-plugins-ide-support")) { isTransitive = false }
testRuntime(project(":kotlin-scripting-idea")) { isTransitive = false }
testRuntime(project(":kotlin-scripting-compiler"))
testRuntime(project(":kotlin-scripting-compiler-impl"))
testRuntime(project(":sam-with-receiver-ide-plugin")) { isTransitive = false }
testRuntime(project(":kotlinx-serialization-compiler-plugin"))
testRuntime(project(":kotlinx-serialization-ide-plugin")) { isTransitive = false }
Platform[192].orHigher {
testCompileOnly(intellijPluginDep("java"))
testRuntime(intellijPluginDep("java"))
}
testRuntime(project(":kotlin-reflect"))
testCompileOnly(intellijDep())
}
sourceSets {
"main" { none() }
"test" { projectDefault() }
}
projectTest {
dependsOn(":dist")
workingDir = rootDir
}
testsJar()
@@ -0,0 +1,361 @@
/*
* 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.ide.scratch.ScratchFileService
import com.intellij.ide.scratch.ScratchRootType
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.CompilerModuleExtension
import com.intellij.openapi.roots.ModuleRootModificationUtil
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess
import com.intellij.testFramework.FileEditorManagerTestCase
import com.intellij.testFramework.MapDataContext
import com.intellij.testFramework.PsiTestUtil
import com.intellij.testFramework.TestActionEvent
import com.intellij.util.ui.UIUtil
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.idea.actions.KOTLIN_WORKSHEET_EXTENSION
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
import org.jetbrains.kotlin.idea.highlighter.KotlinHighlightingUtil
import org.jetbrains.kotlin.idea.scratch.actions.ClearScratchAction
import org.jetbrains.kotlin.idea.scratch.actions.RunScratchAction
import org.jetbrains.kotlin.idea.scratch.actions.ScratchCompilationSupport
import org.jetbrains.kotlin.idea.scratch.output.InlayScratchFileRenderer
import org.jetbrains.kotlin.idea.scratch.output.getInlays
import org.jetbrains.kotlin.idea.scratch.ui.KtScratchFileEditorWithPreview
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.parsing.KotlinParserDefinition.Companion.STD_SCRIPT_SUFFIX
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.MockLibraryUtil
import org.jetbrains.kotlin.utils.PathUtil
import org.junit.Assert
import java.io.File
abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() {
fun doRightPreviewPanelOutputTest(fileName: String) {
doRightPreviewPanelOutputTest(fileName = fileName, isRepl = false)
}
fun doWorksheetReplTest(fileName: String) {
doInlayOutputTest(fileName = fileName, isRepl = true, isWorksheet = true)
}
fun doScratchReplTest(fileName: String) {
doInlayOutputTest(fileName = fileName, isRepl = true, isWorksheet = false)
}
fun doWorksheetCompilingTest(fileName: String) {
doInlayOutputTest(fileName = fileName, isRepl = false, isWorksheet = true)
}
fun doScratchCompilingTest(fileName: String) {
doInlayOutputTest(fileName = fileName, isRepl = false, isWorksheet = false)
}
fun doWorksheetMultiFileTest(dirName: String) {
doMultiFileTest(dirName, isWorksheet = true)
}
fun doScratchMultiFileTest(dirName: String) {
doMultiFileTest(dirName, isWorksheet = false)
}
private fun doMultiFileTest(dirName: String, isWorksheet: Boolean) {
val mainFileExtension = if (isWorksheet) KOTLIN_WORKSHEET_EXTENSION else STD_SCRIPT_SUFFIX
val javaFiles = arrayListOf<File>()
val kotlinFiles = arrayListOf<File>()
val baseDir = File(testDataPath, dirName)
baseDir.walk().forEach {
if (it.isFile) {
if (it.extension == "java") javaFiles.add(it)
if (it.extension == "kt") kotlinFiles.add(it)
}
}
val testDataPathFile = File(myFixture.testDataPath)
javaFiles.forEach { myFixture.copyFileToProject(FileUtil.getRelativePath(testDataPathFile, it)!!, FileUtil.getRelativePath(baseDir, it)!!) }
kotlinFiles.forEach { myFixture.copyFileToProject(FileUtil.getRelativePath(testDataPathFile, it)!!, FileUtil.getRelativePath(baseDir, it)!!) }
val outputDir = createTempDir(dirName)
if (javaFiles.isNotEmpty()) {
val options = listOf("-d", outputDir.path)
KotlinTestUtils.compileJavaFiles(javaFiles, options)
}
MockLibraryUtil.compileKotlin(baseDir.path, outputDir)
PsiTestUtil.setCompilerOutputPath(myFixture.module, outputDir.path, false)
val mainFileName = "$dirName/${getTestName(true)}.$mainFileExtension"
doInlayOutputTest(mainFileName, isRepl = false, isWorksheet = isWorksheet)
launchAction(ClearScratchAction())
doInlayOutputTest(mainFileName, isRepl = true, isWorksheet = isWorksheet)
ModuleRootModificationUtil.updateModel(myFixture.module) { model ->
model.getModuleExtension(CompilerModuleExtension::class.java).inheritCompilerOutputPath(true)
}
}
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)
if (isWorksheet) {
configureWorksheetByText(sourceFile.name, fileText)
} else {
configureScratchByText(sourceFile.name, fileText)
}
if (!KotlinHighlightingUtil.shouldHighlight(myFixture.file)) error("Highlighting for scratch file is switched off")
launchScratch()
waitUntilScratchFinishes(isRepl)
}
private fun getExpectedFile(fileName: String, isRepl: Boolean, suffix: String): File {
val expectedFileName = if (isRepl) {
fileName.replace(".kts", ".repl.$suffix")
} else {
fileName.replace(".kts", ".comp.$suffix")
}
return File(testDataPath, expectedFileName)
}
protected fun String.inlinePropertiesValues(
isRepl: Boolean = false,
isInteractiveMode: Boolean = false
): String {
return replace("~REPL_MODE~", isRepl.toString()).replace("~INTERACTIVE_MODE~", isInteractiveMode.toString())
}
protected fun getFileTextWithInlays(): String {
val doc = myFixture.getDocument(myFixture.file) ?: error("Document for ${myFixture.file.name} is null")
val actualOutput = StringBuilder(myFixture.file.text)
for (line in doc.lineCount - 1 downTo 0) {
getInlays(doc.getLineStartOffset(line), doc.getLineEndOffset(line))
.forEach { inlay ->
val str = inlay.toString()
val offset = doc.getLineEndOffset(line)
actualOutput.insert(
offset,
"${str.takeWhile { it.isWhitespace() }}// ${str.trim()}"
)
}
}
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<InlayScratchFileRenderer> {
val inlineElementsInRange = myFixture.editor.inlayModel.getInlays(start, end)
return inlineElementsInRange.map { it.renderer as InlayScratchFileRenderer }
}
protected fun configureScratchByText(name: String, text: String): ScratchFile {
val scratchVirtualFile = ScratchRootType.getInstance().createScratchFile(
project,
name,
KotlinLanguage.INSTANCE,
text,
ScratchFileService.Option.create_if_missing
) ?: error("Couldn't create scratch file")
myFixture.openFileInEditor(scratchVirtualFile)
ScriptConfigurationManager.updateScriptDependenciesSynchronously(myFixture.file, project)
val scratchFileEditor = getScratchEditorForSelectedFile(myManager, myFixture.file.virtualFile)
?: error("Couldn't find scratch file")
configureOptions(scratchFileEditor, text, myFixture.module)
return scratchFileEditor.scratchFile
}
protected fun configureWorksheetByText(name: String, text: String): ScratchFile {
val worksheetFile = myFixture.configureByText(name, text).virtualFile
ScriptConfigurationManager.updateScriptDependenciesSynchronously(myFixture.file, project)
val scratchFileEditor = getScratchEditorForSelectedFile(myManager, myFixture.file.virtualFile)
?: error("Couldn't find scratch panel")
// We want to check that correct module is selected automatically,
// that's why we set `module` to null so it wouldn't be changed
configureOptions(scratchFileEditor, text, null)
return scratchFileEditor.scratchFile
}
protected fun launchScratch() {
val action = RunScratchAction()
launchAction(action)
}
protected fun launchAction(action: AnAction) {
val e = getActionEvent(myFixture.file.virtualFile, action)
action.beforeActionPerformedUpdate(e)
Assert.assertTrue(e.presentation.isEnabled && e.presentation.isVisible)
action.actionPerformed(e)
}
protected fun waitUntilScratchFinishes(shouldStopRepl: Boolean = true) {
UIUtil.dispatchAllInvocationEvents()
val start = System.currentTimeMillis()
// wait until output is displayed in editor or for 1 minute
while (ScratchCompilationSupport.isAnyInProgress() && (System.currentTimeMillis() - start) < 60000) {
Thread.sleep(100)
}
if (shouldStopRepl) stopReplProcess()
UIUtil.dispatchAllInvocationEvents()
}
protected fun stopReplProcess() {
if (myFixture.file != null) {
val scratchFile = getScratchEditorForSelectedFile(myManager, myFixture.file.virtualFile)?.scratchFile
?: error("Couldn't find scratch panel")
scratchFile.replScratchExecutor?.stopAndWait()
}
UIUtil.dispatchAllInvocationEvents()
}
private fun getActionEvent(virtualFile: VirtualFile, action: AnAction): TestActionEvent {
val context = MapDataContext()
context.put(CommonDataKeys.VIRTUAL_FILE_ARRAY, arrayOf(virtualFile))
context.put(CommonDataKeys.PROJECT, project)
context.put(CommonDataKeys.EDITOR, myFixture.editor)
return TestActionEvent(context, action)
}
protected fun testScratchText(): String {
return File(testDataPath, "idea/scripting-support/testData/scratch/custom/test_scratch.kts").readText()
}
override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory()
override fun getProjectDescriptor(): com.intellij.testFramework.LightProjectDescriptor {
val testName = getTestName(false)
return when {
testName.endsWith("WithKotlinTest") -> INSTANCE_WITH_KOTLIN_TEST
testName.endsWith("NoRuntime") -> INSTANCE_WITHOUT_RUNTIME
testName.endsWith("ScriptRuntime") -> INSTANCE_WITH_SCRIPT_RUNTIME
else -> KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE_FULL_JDK
}
}
override fun setUp() {
super.setUp()
VfsRootAccess.allowRootAccess(KotlinTestUtils.getHomeDirectory())
PluginTestCaseBase.addJdk(myFixture.projectDisposable) { PluginTestCaseBase.fullJdk() }
}
override fun tearDown() {
super.tearDown()
VfsRootAccess.disallowRootAccess(KotlinTestUtils.getHomeDirectory())
ScratchFileService.getInstance().scratchesMapping.mappings.forEach { file, _ ->
runWriteAction { file.delete(this) }
}
}
companion object {
private val INSTANCE_WITH_KOTLIN_TEST = object : KotlinWithJdkAndRuntimeLightProjectDescriptor(
arrayListOf(
ForTestCompileRuntime.runtimeJarForTests(),
PathUtil.kotlinPathsForDistDirectory.kotlinTestPath
)
) {
override fun getSdk() = PluginTestCaseBase.fullJdk()
}
private val INSTANCE_WITHOUT_RUNTIME = object : KotlinLightProjectDescriptor() {
override fun getSdk() = PluginTestCaseBase.fullJdk()
}
private val INSTANCE_WITH_SCRIPT_RUNTIME = object : KotlinWithJdkAndRuntimeLightProjectDescriptor(
arrayListOf(
ForTestCompileRuntime.runtimeJarForTests(),
ForTestCompileRuntime.scriptRuntimeJarForTests()
)
) {
override fun getSdk() = PluginTestCaseBase.fullJdk()
}
fun configureOptions(
scratchFileEditor: KtScratchFileEditorWithPreview,
fileText: String,
module: Module?
) {
val scratchFile = scratchFileEditor.scratchFile
if (InTextDirectivesUtils.getPrefixedBoolean(fileText, "// INTERACTIVE_MODE: ") != true) {
scratchFile.saveOptions { copy(isInteractiveMode = false) }
}
if (InTextDirectivesUtils.getPrefixedBoolean(fileText, "// REPL_MODE: ") == true) {
scratchFile.saveOptions { copy(isRepl = true) }
}
if (module != null && !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_MODULE")) {
scratchFile.setModule(module)
}
val isPreviewEnabled = InTextDirectivesUtils.getPrefixedBoolean(fileText, "// PREVIEW_ENABLED: ") == true
scratchFileEditor.setPreviewEnabled(isPreviewEnabled)
}
}
}
@@ -0,0 +1,73 @@
/*
* 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.roots.ModuleRootModificationUtil
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable
import com.intellij.openapi.roots.libraries.Library
import org.jetbrains.kotlin.idea.run.createLibraryWithLongPaths
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner
import org.junit.runner.RunWith
@RunWith(JUnit3WithIdeaConfigurationRunner::class)
class CustomScratchRunActionTest : AbstractScratchRunActionTest() {
fun testLongCommandLineWithRepl() {
assertEquals(
"""|// REPL_MODE: true
|// INTERACTIVE_MODE: false
|1 // RESULT: res0: kotlin.Int = 1""".trimMargin(),
getOutput(true)
)
}
fun testLongCommandLine() {
assertEquals(
"""|// REPL_MODE: false
|// INTERACTIVE_MODE: false
|1 // RESULT: 1""".trimMargin(),
getOutput(false)
)
}
private fun getOutput(isRepl: Boolean): String {
val fileText = testScratchText().inlinePropertiesValues(isRepl)
configureScratchByText("scratch_1.kts", fileText)
launchScratch()
waitUntilScratchFinishes(isRepl)
return getFileTextWithInlays()
}
private val library: Library by lazy {
createLibraryWithLongPaths(project)
}
override fun setUp() {
super.setUp()
ModuleRootModificationUtil.addDependency(myFixture.module, library)
}
override fun tearDown() {
removeLibraryWithLongPaths()
super.tearDown()
}
private fun removeLibraryWithLongPaths() {
runWriteAction {
val modifiableModel = ProjectLibraryTable.getInstance(project).modifiableModel
try {
modifiableModel.removeLibrary(library)
} finally {
modifiableModel.commit()
}
}
}
}
@@ -0,0 +1,76 @@
/*
* 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.codeInsight.daemon.LineMarkerInfo
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl
import com.intellij.ide.scratch.ScratchFileService
import com.intellij.ide.scratch.ScratchRootType
import com.intellij.openapi.editor.Document
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.util.io.FileUtil
import com.intellij.psi.PsiDocumentManager
import com.intellij.testFramework.ExpectedHighlightingData
import com.intellij.testFramework.FileEditorManagerTestCase
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.idea.codeInsight.AbstractLineMarkersTest
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
import org.jetbrains.kotlin.idea.scratch.AbstractScratchRunActionTest.Companion.configureOptions
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.psi.KtFile
import java.io.File
abstract class AbstractScratchLineMarkersTest : FileEditorManagerTestCase() {
fun doScratchTest(path: String) {
val fileText = FileUtil.loadFile(File(path))
val scratchVirtualFile = ScratchRootType.getInstance().createScratchFile(
project,
"scratch.kts",
KotlinLanguage.INSTANCE,
fileText,
ScratchFileService.Option.create_if_missing
) ?: error("Couldn't create scratch file")
myFixture.openFileInEditor(scratchVirtualFile)
ScriptConfigurationManager.updateScriptDependenciesSynchronously(myFixture.file, project)
val scratchFileEditor = getScratchEditorForSelectedFile(FileEditorManager.getInstance(project), myFixture.file.virtualFile)
?: error("Couldn't find scratch panel")
configureOptions(scratchFileEditor, fileText, null)
val project = myFixture.project
val document = myFixture.editor.document
val data = ExpectedHighlightingData(document, false, false, false, myFixture.file)
data.init()
PsiDocumentManager.getInstance(project).commitAllDocuments()
val markers = doAndCheckHighlighting(document, data, File(path))
AbstractLineMarkersTest.assertNavigationElements(myFixture.project, myFixture.file as KtFile, markers)
}
override fun tearDown() {
super.tearDown()
ScratchFileService.getInstance().scratchesMapping.mappings.forEach { file, _ ->
runWriteAction { file.delete(this) }
}
}
private fun doAndCheckHighlighting(
documentToAnalyze: Document, expectedHighlighting: ExpectedHighlightingData, expectedFile: File
): List<LineMarkerInfo<*>> {
myFixture.doHighlighting()
return AbstractLineMarkersTest.checkHighlighting(myFixture.project, documentToAnalyze, expectedHighlighting, expectedFile)
}
}
@@ -0,0 +1,96 @@
/*
* 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.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/scripting-support/testData/scratch/lineMarker")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class ScratchLineMarkersTestGenerated extends AbstractScratchLineMarkersTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doScratchTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInLineMarker() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/scripting-support/testData/scratch/lineMarker"), Pattern.compile("^(.+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("binaryExpression.kts")
public void testBinaryExpression() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/binaryExpression.kts");
}
@TestMetadata("binaryExpression2.kts")
public void testBinaryExpression2() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/binaryExpression2.kts");
}
@TestMetadata("constantExpression.kts")
public void testConstantExpression() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/constantExpression.kts");
}
@TestMetadata("for.kts")
public void testFor() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/for.kts");
}
@TestMetadata("function.kts")
public void testFunction() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/function.kts");
}
@TestMetadata("lambda.kts")
public void testLambda() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/lambda.kts");
}
@TestMetadata("lambda2.kts")
public void testLambda2() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/lambda2.kts");
}
@TestMetadata("object.kts")
public void testObject() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/object.kts");
}
@TestMetadata("parentesized.kts")
public void testParentesized() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/parentesized.kts");
}
@TestMetadata("qualified.kts")
public void testQualified() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/qualified.kts");
}
@TestMetadata("qualifiedMultiLine.kts")
public void testQualifiedMultiLine() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/qualifiedMultiLine.kts");
}
@TestMetadata("referenceExpression.kts")
public void testReferenceExpression() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/referenceExpression.kts");
}
@TestMetadata("val.kts")
public void testVal() throws Exception {
runTest("idea/scripting-support/testData/scratch/lineMarker/val.kts");
}
}
@@ -0,0 +1,42 @@
/*
* 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 org.jetbrains.kotlin.idea.scratch.ui.ModulesComboBoxAction
import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner
import org.junit.Assert
import org.junit.runner.RunWith
@RunWith(JUnit3WithIdeaConfigurationRunner::class)
class ScratchOptionsTest : AbstractScratchRunActionTest() {
fun testModuleSelectionPanelIsVisibleForScratchFile() {
val scratchFile = configureScratchByText("scratch_1.kts", testScratchText())
Assert.assertTrue("Module selector should be visible for scratches", isModuleSelectorVisible(scratchFile))
}
fun testModuleSelectionPanelIsHiddenForWorksheetFile() {
val scratchFile = configureWorksheetByText("worksheet.ws.kts", testScratchText())
Assert.assertFalse("Module selector should be hidden for worksheets", isModuleSelectorVisible(scratchFile))
}
fun testCurrentModuleIsAutomaticallySelectedForWorksheetFile() {
val scratchFile = configureWorksheetByText("worksheet.ws.kts", testScratchText())
Assert.assertEquals(
"Selected module should be equal to current project module for worksheets",
myFixture.module,
scratchFile.module
)
}
private fun isModuleSelectorVisible(scratchTopPanel: ScratchFile): Boolean {
return ModulesComboBoxAction(scratchTopPanel).isModuleSelectorVisible()
}
}
@@ -0,0 +1,307 @@
/*
* 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.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@RunWith(JUnit3RunnerWithInners.class)
public class ScratchRunActionTestGenerated extends AbstractScratchRunActionTest {
@TestMetadata("idea/scripting-support/testData/scratch")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ScratchCompiling extends AbstractScratchRunActionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doScratchCompilingTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInScratchCompiling() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/scripting-support/testData/scratch"), Pattern.compile("^(.+)\\.kts$"), TargetBackend.ANY, false);
}
@TestMetadata("for.kts")
public void testFor() throws Exception {
runTest("idea/scripting-support/testData/scratch/for.kts");
}
@TestMetadata("generics.kts")
public void testGenerics() throws Exception {
runTest("idea/scripting-support/testData/scratch/generics.kts");
}
@TestMetadata("klass.kts")
public void testKlass() throws Exception {
runTest("idea/scripting-support/testData/scratch/klass.kts");
}
@TestMetadata("libraryDepWithKotlinTest.kts")
public void testLibraryDepWithKotlinTest() throws Exception {
runTest("idea/scripting-support/testData/scratch/libraryDepWithKotlinTest.kts");
}
@TestMetadata("simple.kts")
public void testSimple() throws Exception {
runTest("idea/scripting-support/testData/scratch/simple.kts");
}
@TestMetadata("simpleFun.kts")
public void testSimpleFun() throws Exception {
runTest("idea/scripting-support/testData/scratch/simpleFun.kts");
}
@TestMetadata("simpleNoRuntime.kts")
public void testSimpleNoRuntime() throws Exception {
runTest("idea/scripting-support/testData/scratch/simpleNoRuntime.kts");
}
@TestMetadata("spacesAtLineStart.kts")
public void testSpacesAtLineStart() throws Exception {
runTest("idea/scripting-support/testData/scratch/spacesAtLineStart.kts");
}
@TestMetadata("stdlibFun.kts")
public void testStdlibFun() throws Exception {
runTest("idea/scripting-support/testData/scratch/stdlibFun.kts");
}
@TestMetadata("unresolved.kts")
public void testUnresolved() throws Exception {
runTest("idea/scripting-support/testData/scratch/unresolved.kts");
}
@TestMetadata("unresolvedMultiline.kts")
public void testUnresolvedMultiline() throws Exception {
runTest("idea/scripting-support/testData/scratch/unresolvedMultiline.kts");
}
@TestMetadata("userOutput.kts")
public void testUserOutput() throws Exception {
runTest("idea/scripting-support/testData/scratch/userOutput.kts");
}
@TestMetadata("var.kts")
public void testVar() throws Exception {
runTest("idea/scripting-support/testData/scratch/var.kts");
}
@TestMetadata("veryLongOutput.kts")
public void testVeryLongOutput() throws Exception {
runTest("idea/scripting-support/testData/scratch/veryLongOutput.kts");
}
@TestMetadata("when.kts")
public void testWhen() throws Exception {
runTest("idea/scripting-support/testData/scratch/when.kts");
}
}
@TestMetadata("idea/scripting-support/testData/scratch")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ScratchRepl extends AbstractScratchRunActionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doScratchReplTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInScratchRepl() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/scripting-support/testData/scratch"), Pattern.compile("^(.+)\\.kts$"), TargetBackend.ANY, false);
}
@TestMetadata("for.kts")
public void testFor() throws Exception {
runTest("idea/scripting-support/testData/scratch/for.kts");
}
@TestMetadata("generics.kts")
public void testGenerics() throws Exception {
runTest("idea/scripting-support/testData/scratch/generics.kts");
}
@TestMetadata("klass.kts")
public void testKlass() throws Exception {
runTest("idea/scripting-support/testData/scratch/klass.kts");
}
@TestMetadata("libraryDepWithKotlinTest.kts")
public void testLibraryDepWithKotlinTest() throws Exception {
runTest("idea/scripting-support/testData/scratch/libraryDepWithKotlinTest.kts");
}
@TestMetadata("simple.kts")
public void testSimple() throws Exception {
runTest("idea/scripting-support/testData/scratch/simple.kts");
}
@TestMetadata("simpleFun.kts")
public void testSimpleFun() throws Exception {
runTest("idea/scripting-support/testData/scratch/simpleFun.kts");
}
@TestMetadata("simpleNoRuntime.kts")
public void testSimpleNoRuntime() throws Exception {
runTest("idea/scripting-support/testData/scratch/simpleNoRuntime.kts");
}
@TestMetadata("spacesAtLineStart.kts")
public void testSpacesAtLineStart() throws Exception {
runTest("idea/scripting-support/testData/scratch/spacesAtLineStart.kts");
}
@TestMetadata("stdlibFun.kts")
public void testStdlibFun() throws Exception {
runTest("idea/scripting-support/testData/scratch/stdlibFun.kts");
}
@TestMetadata("unresolved.kts")
public void testUnresolved() throws Exception {
runTest("idea/scripting-support/testData/scratch/unresolved.kts");
}
@TestMetadata("unresolvedMultiline.kts")
public void testUnresolvedMultiline() throws Exception {
runTest("idea/scripting-support/testData/scratch/unresolvedMultiline.kts");
}
@TestMetadata("userOutput.kts")
public void testUserOutput() throws Exception {
runTest("idea/scripting-support/testData/scratch/userOutput.kts");
}
@TestMetadata("var.kts")
public void testVar() throws Exception {
runTest("idea/scripting-support/testData/scratch/var.kts");
}
@TestMetadata("veryLongOutput.kts")
public void testVeryLongOutput() throws Exception {
runTest("idea/scripting-support/testData/scratch/veryLongOutput.kts");
}
@TestMetadata("when.kts")
public void testWhen() throws Exception {
runTest("idea/scripting-support/testData/scratch/when.kts");
}
}
@TestMetadata("idea/scripting-support/testData/scratch/multiFile")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ScratchMultiFile extends AbstractScratchRunActionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doScratchMultiFileTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInScratchMultiFile() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/scripting-support/testData/scratch/multiFile"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, false);
}
@TestMetadata("inlineFun")
public void testInlineFun() throws Exception {
runTest("idea/scripting-support/testData/scratch/multiFile/inlineFun/");
}
@TestMetadata("javaDep")
public void testJavaDep() throws Exception {
runTest("idea/scripting-support/testData/scratch/multiFile/javaDep/");
}
}
@TestMetadata("idea/scripting-support/testData/worksheet")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class WorksheetCompiling extends AbstractScratchRunActionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doWorksheetCompilingTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInWorksheetCompiling() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/scripting-support/testData/worksheet"), Pattern.compile("^(.+)\\.ws.kts$"), TargetBackend.ANY, false);
}
@TestMetadata("simpleScriptRuntime.ws.kts")
public void testSimpleScriptRuntime() throws Exception {
runTest("idea/scripting-support/testData/worksheet/simpleScriptRuntime.ws.kts");
}
}
@TestMetadata("idea/scripting-support/testData/worksheet")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class WorksheetRepl extends AbstractScratchRunActionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doWorksheetReplTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInWorksheetRepl() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/scripting-support/testData/worksheet"), Pattern.compile("^(.+)\\.ws.kts$"), TargetBackend.ANY, false);
}
@TestMetadata("simpleScriptRuntime.ws.kts")
public void testSimpleScriptRuntime() throws Exception {
runTest("idea/scripting-support/testData/worksheet/simpleScriptRuntime.ws.kts");
}
}
@TestMetadata("idea/scripting-support/testData/worksheet/multiFile")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class WorksheetMultiFile extends AbstractScratchRunActionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doWorksheetMultiFileTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInWorksheetMultiFile() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/scripting-support/testData/worksheet/multiFile"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, false);
}
@TestMetadata("inlineFunScriptRuntime")
public void testInlineFunScriptRuntime() throws Exception {
runTest("idea/scripting-support/testData/worksheet/multiFile/inlineFunScriptRuntime/");
}
@TestMetadata("javaDepScriptRuntime")
public void testJavaDepScriptRuntime() throws Exception {
runTest("idea/scripting-support/testData/worksheet/multiFile/javaDepScriptRuntime/");
}
}
@TestMetadata("idea/scripting-support/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/scripting-support/testData/scratch/rightPanelOutput"), Pattern.compile("^(.+)\\.kts$"), TargetBackend.ANY, false);
}
@TestMetadata("bigSequentialOutputs.kts")
public void testBigSequentialOutputs() throws Exception {
runTest("idea/scripting-support/testData/scratch/rightPanelOutput/bigSequentialOutputs.kts");
}
@TestMetadata("shortExpression.longOutput.singleTop.kts")
public void testShortExpression_longOutput_singleTop() throws Exception {
runTest("idea/scripting-support/testData/scratch/rightPanelOutput/shortExpression.longOutput.singleTop.kts");
}
@TestMetadata("shortExpression.shortOutput.singleTop.kts")
public void testShortExpression_shortOutput_singleTop() throws Exception {
runTest("idea/scripting-support/testData/scratch/rightPanelOutput/shortExpression.shortOutput.singleTop.kts");
}
}
}
@@ -0,0 +1,70 @@
/*
* 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 org.jetbrains.kotlin.idea.scratch.actions.RunScratchFromHereAction
import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner
import org.junit.runner.RunWith
@RunWith(JUnit3WithIdeaConfigurationRunner::class)
class SequentialScratchExecutorTest : AbstractScratchRunActionTest() {
fun testSingleLine() {
doTest(
listOf(
"2 + 2\n" to "RESULT: res1: kotlin.Int = 4"
)
)
}
fun testMultipleLinesAtOnce() {
doTest(
listOf(
"2\n3\n4\n" to "RESULT: res1: kotlin.Int = 2, RESULT: res2: kotlin.Int = 3, RESULT: res3: kotlin.Int = 4"
)
)
}
fun testMultipleLinesAfterEach() {
doTest(
listOf(
"2\n" to "RESULT: res1: kotlin.Int = 2",
"3\n" to "RESULT: res2: kotlin.Int = 3",
"4\n" to "RESULT: res3: kotlin.Int = 4"
)
)
}
fun doTest(expression: List<Pair<String, String>>) {
configureScratchByText("scratch_1.kts", testScratchText().inlinePropertiesValues(isRepl = true))
myFixture.editor.caretModel.moveToOffset(myFixture.file.textLength)
try {
launchScratch()
waitUntilScratchFinishes(shouldStopRepl = false)
for ((text, expected) in expression) {
typeAndCheckOutput(text, expected)
}
} finally {
stopReplProcess()
}
}
private fun typeAndCheckOutput(text: String, expected: String) {
val inlaysBefore = getInlays()
myFixture.type(text)
launchAction(RunScratchFromHereAction())
waitUntilScratchFinishes(shouldStopRepl = false)
val inlayAfter = getInlays().filterNot { inlaysBefore.contains(it) }
assertEquals(expected, inlayAfter.joinToString { it.toString().trim() })
}
}
@@ -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)
}
@@ -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 ""}"""
}
}
@@ -0,0 +1,3 @@
// REPL_MODE: ~REPL_MODE~
// INTERACTIVE_MODE: ~INTERACTIVE_MODE~
1
@@ -0,0 +1,5 @@
// REPL_MODE: false
for (i in 0..5) { // OUTPUT: 0; 1; 2; 3; 4; 5
println(i)
}
+5
View File
@@ -0,0 +1,5 @@
// REPL_MODE: ~REPL_MODE~
for (i in 0..5) {
println(i)
}
@@ -0,0 +1,5 @@
// REPL_MODE: true
for (i in 0..5) { // OUTPUT: 0; 1; 2; 3; 4; 5
println(i)
}
@@ -0,0 +1,10 @@
// REPL_MODE: false
class GClass<T> { // RESULT: class GClass<T>
fun foo(t: T): T {
return t
}
}
val g = GClass<Int>() // RESULT: val g: Generics.GClass<Int>
g.foo(1) // RESULT: 1
+10
View File
@@ -0,0 +1,10 @@
// REPL_MODE: ~REPL_MODE~
class GClass<T> {
fun foo(t: T): T {
return t
}
}
val g = GClass<Int>()
g.foo(1)
@@ -0,0 +1,10 @@
// REPL_MODE: true
class GClass<T> {
fun foo(t: T): T {
return t
}
}
val g = GClass<Int>()
g.foo(1) // RESULT: res2: kotlin.Int = 1
@@ -0,0 +1,16 @@
// REPL_MODE: false
class MyClass { // RESULT: class MyClass
fun foo() = 1
}
MyClass().foo() // RESULT: 1
interface I { // RESULT: interface I
fun foo(): Int
}
val i = object: I { // RESULT: val i: Klass.I
override fun foo(): Int = 1
}
i.foo() // RESULT: 1
+16
View File
@@ -0,0 +1,16 @@
// REPL_MODE: ~REPL_MODE~
class MyClass {
fun foo() = 1
}
MyClass().foo()
interface I {
fun foo(): Int
}
val i = object: I {
override fun foo(): Int = 1
}
i.foo()
@@ -0,0 +1,16 @@
// REPL_MODE: true
class MyClass {
fun foo() = 1
}
MyClass().foo() // RESULT: res1: kotlin.Int = 1
interface I {
fun foo(): Int
}
val i = object: I {
override fun foo(): Int = 1
}
i.foo() // RESULT: res4: kotlin.Int = 1
@@ -0,0 +1,4 @@
// REPL_MODE: false
val a: Int? = 1 // RESULT: val a: Int?
kotlin.test.assertNotNull(1) // RESULT: 1
@@ -0,0 +1,4 @@
// REPL_MODE: ~REPL_MODE~
val a: Int? = 1
kotlin.test.assertNotNull(1)
@@ -0,0 +1,4 @@
// REPL_MODE: true
val a: Int? = 1
kotlin.test.assertNotNull(1) // RESULT: res1: kotlin.Int = 1
@@ -0,0 +1,3 @@
<lineMarker>1</lineMarker> + 1
// REPL_MODE: true
@@ -0,0 +1,3 @@
<lineMarker>1</lineMarker> + 2 + 3
// REPL_MODE: true
@@ -0,0 +1,3 @@
<lineMarker>1</lineMarker>
// REPL_MODE: true
@@ -0,0 +1,5 @@
<lineMarker>for</lineMarker> (i in 0..4) {
println(i)
}
// REPL_MODE: true
@@ -0,0 +1,5 @@
fun <lineMarker>foo</lineMarker>(): Int {
return 1
}
// REPL_MODE: true
@@ -0,0 +1,5 @@
<lineMarker>run</lineMarker> {
1
}
// REPL_MODE: true
@@ -0,0 +1,5 @@
<lineMarker>{</lineMarker>
1
}()
// REPL_MODE: true
@@ -0,0 +1,7 @@
<lineMarker>object</lineMarker>: Comparable<String> {
override fun compareTo(other: String): Int {
return 0
}
}
// REPL_MODE: true
@@ -0,0 +1,3 @@
<lineMarker>(</lineMarker>1 + 2)
// REPL_MODE: true
@@ -0,0 +1,3 @@
<lineMarker>kotlin</lineMarker>.io.println("Hi")
// REPL_MODE: true
@@ -0,0 +1,5 @@
<lineMarker>kotlin</lineMarker>
.io
.println("Hi")
// REPL_MODE: true
@@ -0,0 +1,3 @@
<lineMarker>println</lineMarker>("Hi")
// REPL_MODE: true
@@ -0,0 +1,3 @@
val <lineMarker>a</lineMarker> = 1
// REPL_MODE: true
@@ -0,0 +1,5 @@
// REPL_MODE: false
import inlineFun.*
foo { 1 + 3 } // RESULT: 4
@@ -0,0 +1,5 @@
// REPL_MODE: ~REPL_MODE~
import inlineFun.*
foo { 1 + 3 }
@@ -0,0 +1,5 @@
// REPL_MODE: true
import inlineFun.*
foo { 1 + 3 } // RESULT: res1: kotlin.Int = 4
@@ -0,0 +1,3 @@
package inlineFun
inline fun foo(f: () -> Int): Int = f()
@@ -0,0 +1,5 @@
// REPL_MODE: false
import myTest.MyJavaClass
MyJavaClass().test() // RESULT: 1
@@ -0,0 +1,5 @@
// REPL_MODE: ~REPL_MODE~
import myTest.MyJavaClass
MyJavaClass().test()
@@ -0,0 +1,5 @@
// REPL_MODE: true
import myTest.MyJavaClass
MyJavaClass().test() // RESULT: res1: kotlin.Int = 1
@@ -0,0 +1,7 @@
package myTest;
public class MyJavaClass {
public int test() {
return 1;
}
}
@@ -0,0 +1,22 @@
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
<fold text='Hello world...'>Hello world
Hello world</fold>
<fold text='Hello world...'>Hello world
Hello world
Hello world</fold>
Hello world
Hello world
Hello world
@@ -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")
)
@@ -0,0 +1,3 @@
<fold text='First string...'>First string
Second string
Third string</fold>
@@ -0,0 +1,2 @@
// PREVIEW_ENABLED: TRUE
println("First string\nSecond string\nThird string")
@@ -0,0 +1,2 @@
// PREVIEW_ENABLED: TRUE
println("Single string")
@@ -0,0 +1,4 @@
// REPL_MODE: false
val a = 1 // RESULT: val a: Int
a // RESULT: 1
+4
View File
@@ -0,0 +1,4 @@
// REPL_MODE: ~REPL_MODE~
val a = 1
a
@@ -0,0 +1,4 @@
// REPL_MODE: true
val a = 1
a // RESULT: res1: kotlin.Int = 1
@@ -0,0 +1,7 @@
// REPL_MODE: false
fun foo(): Int { // RESULT: fun foo(): Int
return 1
}
foo() // RESULT: 1
+7
View File
@@ -0,0 +1,7 @@
// REPL_MODE: ~REPL_MODE~
fun foo(): Int {
return 1
}
foo()
@@ -0,0 +1,7 @@
// REPL_MODE: true
fun foo(): Int {
return 1
}
foo() // RESULT: res1: kotlin.Int = 1
@@ -0,0 +1,4 @@
// REPL_MODE: false
// NO_MODULE
arrayListOf(1, 2).size // RESULT: 2
@@ -0,0 +1,4 @@
// REPL_MODE: ~REPL_MODE~
// NO_MODULE
arrayListOf(1, 2).size
@@ -0,0 +1,4 @@
// REPL_MODE: true
// NO_MODULE
arrayListOf(1, 2).size // RESULT: res0: kotlin.Int = 2
@@ -0,0 +1,5 @@
// REPL_MODE: false
val a = 1 // RESULT: val a: Int
a // RESULT: 1
a // RESULT: 1
@@ -0,0 +1,5 @@
// REPL_MODE: ~REPL_MODE~
val a = 1
a
a
@@ -0,0 +1,5 @@
// REPL_MODE: true
val a = 1
a // RESULT: res1: kotlin.Int = 1
a // RESULT: res2: kotlin.Int = 1
@@ -0,0 +1,5 @@
// REPL_MODE: false
arrayListOf(1, 5, 7).map { it * 2 } // RESULT: 2
.filter { it < 10 }
.find { it == 2 }
+5
View File
@@ -0,0 +1,5 @@
// REPL_MODE: ~REPL_MODE~
arrayListOf(1, 5, 7).map { it * 2 }
.filter { it < 10 }
.find { it == 2 }
@@ -0,0 +1,5 @@
// REPL_MODE: true
arrayListOf(1, 5, 7).map { it * 2 } // RESULT: res0: kotlin.Int? = 2
.filter { it < 10 }
.find { it == 2 }
@@ -0,0 +1,4 @@
// REPL_MODE: false
foo() // ERROR: Unresolved reference: foo
/** unresolved.kts:3 Unresolved reference: foo */
@@ -0,0 +1,3 @@
// REPL_MODE: ~REPL_MODE~
foo()
@@ -0,0 +1,6 @@
// REPL_MODE: true
foo() // ERROR: error: unresolved reference: foo...
/** unresolved.kts:3 error: unresolved reference: foo
foo()
^ */
@@ -0,0 +1,14 @@
// REPL_MODE: false
foo.forEach { // ERROR: Unresolved reference: foo; Overload resolution ambiguity: ...
1 + 1
}
fun goo(a: String) { // ERROR: Unresolved reference: goo
super.goo(a)
}
/** unresolvedMultiline.kts:3 Unresolved reference: foo */
/** unresolvedMultiline.kts:3 Overload resolution ambiguity:
public inline fun <T> Iterable<TypeVariable(T)>.forEach(action: (TypeVariable(T)) -> Unit): Unit defined in kotlin.collections
public inline fun <K, V> Map<out TypeVariable(K), TypeVariable(V)>.forEach(action: (Map.Entry<TypeVariable(K), TypeVariable(V)>) -> Unit): Unit defined in kotlin.collections */
/** unresolvedMultiline.kts:7 Unresolved reference: goo */
@@ -0,0 +1,9 @@
// REPL_MODE: ~REPL_MODE~
foo.forEach {
1 + 1
}
fun goo(a: String) {
super.goo(a)
}
@@ -0,0 +1,20 @@
// REPL_MODE: true
foo.forEach { // ERROR: error: unresolved reference: foo...
1 + 1
}
fun goo(a: String) { // ERROR: error: unresolved reference: goo...
super.goo(a)
}
/** unresolvedMultiline.kts:3 error: unresolved reference: foo
foo.forEach {
^
error: cannot choose among the following candidates without completing type inference:
public inline fun <T> Iterable<???>.forEach(action: (???) -> Unit): Unit defined in kotlin.collections
public inline fun <K, V> Map<out ???, ???>.forEach(action: (Map.Entry<???, ???>) -> Unit): Unit defined in kotlin.collections
foo.forEach {
^ */
/** unresolvedMultiline.kts:7 error: unresolved reference: goo
super.goo(a)
^ */
@@ -0,0 +1,3 @@
// REPL_MODE: false
println("hello") // OUTPUT: hello
@@ -0,0 +1,3 @@
// REPL_MODE: ~REPL_MODE~
println("hello")
@@ -0,0 +1,3 @@
// REPL_MODE: true
println("hello") // OUTPUT: hello
@@ -0,0 +1,5 @@
// REPL_MODE: false
var a = 1 // RESULT: var a: Int
a++ // RESULT: 1
a // RESULT: 2
+5
View File
@@ -0,0 +1,5 @@
// REPL_MODE: ~REPL_MODE~
var a = 1
a++
a
@@ -0,0 +1,5 @@
// REPL_MODE: true
var a = 1
a++ // RESULT: res1: kotlin.Int = 1
a // RESULT: res2: kotlin.Int = 2
@@ -0,0 +1,14 @@
// REPL_MODE: false
val a = "a".repeat(100) // RESULT: val a: String
a // RESULT: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
val b = "0123456789\n".repeat(10) // RESULT: val b: String
b // RESULT: 0123456789; 0123456789; 0123456789; 0123456789; 012345678...
println("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789") // OUTPUT: 01...
/** veryLongOutput.kts:4 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */
/** veryLongOutput.kts:6 0123456789 */
/** veryLongOutput.kts:6 0123456789 */
/** veryLongOutput.kts:6 0123456789 */
/** veryLongOutput.kts:6 0123456789 */
/** veryLongOutput.kts:6 0123456789 */
/** veryLongOutput.kts:7 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 */
@@ -0,0 +1,7 @@
// REPL_MODE: ~REPL_MODE~
val a = "a".repeat(100)
a
val b = "0123456789\n".repeat(10)
b
println("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789")
@@ -0,0 +1,19 @@
// REPL_MODE: true
val a = "a".repeat(100)
a // RESULT: res1: kotlin.String = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
val b = "0123456789\n".repeat(10)
b // RESULT: res3: kotlin.String = 0123456789...
println("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789") // OUTPUT: 01...
/** veryLongOutput.kts:4 res1: kotlin.String = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */
/** veryLongOutput.kts:6 res3: kotlin.String = 0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789
0123456789 */
/** veryLongOutput.kts:7 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 */
+21
View File
@@ -0,0 +1,21 @@
// REPL_MODE: false
val a = 1 // RESULT: val a: Int
when(a) { // OUTPUT: 1
1 -> println("1")
else -> println("2")
}
when(a) { // OUTPUT: 1
1 -> println("1")
}
when(a) { // OUTPUT: 1
2 -> println("2")
else -> println("1")
}
when(a) { // RESULT: 11
1 -> 11
else -> 12
}
+21
View File
@@ -0,0 +1,21 @@
// REPL_MODE: ~REPL_MODE~
val a = 1
when(a) {
1 -> println("1")
else -> println("2")
}
when(a) {
1 -> println("1")
}
when(a) {
2 -> println("2")
else -> println("1")
}
when(a) {
1 -> 11
else -> 12
}
+21
View File
@@ -0,0 +1,21 @@
// REPL_MODE: true
val a = 1
when(a) { // OUTPUT: 1
1 -> println("1")
else -> println("2")
}
when(a) { // OUTPUT: 1
1 -> println("1")
}
when(a) { // OUTPUT: 1
2 -> println("2")
else -> println("1")
}
when(a) { // RESULT: res4: kotlin.Int = 11
1 -> 11
else -> 12
}
@@ -0,0 +1,5 @@
// REPL_MODE: false
import inlineFun.*
foo { 1 + 3 } // RESULT: 4
@@ -0,0 +1,5 @@
// REPL_MODE: ~REPL_MODE~
import inlineFun.*
foo { 1 + 3 }
@@ -0,0 +1,5 @@
// REPL_MODE: true
import inlineFun.*
foo { 1 + 3 } // RESULT: res1: kotlin.Int = 4
@@ -0,0 +1,3 @@
package inlineFun
inline fun foo(f: () -> Int): Int = f()
@@ -0,0 +1,5 @@
// REPL_MODE: false
import myTest.MyJavaClass
MyJavaClass().test() // RESULT: 1
@@ -0,0 +1,5 @@
// REPL_MODE: ~REPL_MODE~
import myTest.MyJavaClass
MyJavaClass().test()
@@ -0,0 +1,5 @@
// REPL_MODE: true
import myTest.MyJavaClass
MyJavaClass().test() // RESULT: res1: kotlin.Int = 1
@@ -0,0 +1,7 @@
package myTest;
public class MyJavaClass {
public int test() {
return 1;
}
}
@@ -0,0 +1,4 @@
// REPL_MODE: false
val a = 1 // RESULT: val a: Int
a // RESULT: 1
@@ -0,0 +1,4 @@
// REPL_MODE: ~REPL_MODE~
val a = 1
a
@@ -0,0 +1,4 @@
// REPL_MODE: true
val a = 1
a // RESULT: res1: kotlin.Int = 1