Refactor scratch tests: add ability to set scratch options in test file
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
// INTERACTIVE_MODE: ~INTERACTIVE_MODE~
|
||||
1
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
for (i in 0..5) { // OUTPUT: 0; 1; 2; 3; 4; 5
|
||||
println(i)
|
||||
}
|
||||
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
for (i in 0..5) {
|
||||
println(i)
|
||||
}
|
||||
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
for (i in 0..5) { // OUTPUT: 0; 1; 2; 3; 4; 5
|
||||
println(i)
|
||||
}
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
class GClass<T> { // RESULT: class GClass<T>
|
||||
fun foo(t: T): T {
|
||||
return t
|
||||
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
class GClass<T> {
|
||||
fun foo(t: T): T {
|
||||
return t
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
class GClass<T> {
|
||||
fun foo(t: T): T {
|
||||
return t
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
class MyClass { // RESULT: class MyClass
|
||||
fun foo() = 1
|
||||
}
|
||||
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
class MyClass {
|
||||
fun foo() = 1
|
||||
}
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
class MyClass {
|
||||
fun foo() = 1
|
||||
}
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
val a: Int? = 1 // RESULT: val a: Int?
|
||||
kotlin.test.assertNotNull(1) // RESULT: 1
|
||||
@@ -1,2 +1,4 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
val a: Int? = 1
|
||||
kotlin.test.assertNotNull(1)
|
||||
@@ -1,2 +1,4 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
val a: Int? = 1
|
||||
kotlin.test.assertNotNull(1) // RESULT: res1: kotlin.Int = 1
|
||||
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
import inlineFun.*
|
||||
|
||||
foo { 1 + 3 } // RESULT: 4
|
||||
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
import inlineFun.*
|
||||
|
||||
foo { 1 + 3 }
|
||||
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
import inlineFun.*
|
||||
|
||||
foo { 1 + 3 } // RESULT: res1: kotlin.Int = 4
|
||||
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
import myTest.MyJavaClass
|
||||
|
||||
MyJavaClass().test() // RESULT: 1
|
||||
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
import myTest.MyJavaClass
|
||||
|
||||
MyJavaClass().test()
|
||||
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
import myTest.MyJavaClass
|
||||
|
||||
MyJavaClass().test() // RESULT: res1: kotlin.Int = 1
|
||||
+2
@@ -1,2 +1,4 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
val a = 1 // RESULT: val a: Int
|
||||
a // RESULT: 1
|
||||
Vendored
+2
@@ -1,2 +1,4 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
val a = 1
|
||||
a
|
||||
+2
@@ -1,2 +1,4 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
val a = 1
|
||||
a // RESULT: res1: kotlin.Int = 1
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
fun foo(): Int { // RESULT: fun foo(): Int
|
||||
return 1
|
||||
}
|
||||
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
fun foo(): Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
fun foo(): Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,3 +1,4 @@
|
||||
arrayListOf(1, 2).size // RESULT: 2
|
||||
// REPL_MODE: false
|
||||
// NO_MODULE
|
||||
|
||||
//NO_MODULE
|
||||
arrayListOf(1, 2).size // RESULT: 2
|
||||
+3
-2
@@ -1,3 +1,4 @@
|
||||
arrayListOf(1, 2).size
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
// NO_MODULE
|
||||
|
||||
//NO_MODULE
|
||||
arrayListOf(1, 2).size
|
||||
+3
-2
@@ -1,3 +1,4 @@
|
||||
arrayListOf(1, 2).size // RESULT: res0: kotlin.Int = 2
|
||||
// REPL_MODE: true
|
||||
// NO_MODULE
|
||||
|
||||
//NO_MODULE
|
||||
arrayListOf(1, 2).size // RESULT: res0: kotlin.Int = 2
|
||||
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
val a = 1 // RESULT: val a: Int
|
||||
a // RESULT: 1
|
||||
a // RESULT: 1
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
val a = 1
|
||||
a
|
||||
a
|
||||
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
val a = 1
|
||||
a // RESULT: res1: kotlin.Int = 1
|
||||
a // RESULT: res2: kotlin.Int = 1
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
arrayListOf(1, 5, 7).map { it * 2 } // RESULT: 2
|
||||
.filter { it < 10 }
|
||||
.find { it == 2 }
|
||||
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
arrayListOf(1, 5, 7).map { it * 2 }
|
||||
.filter { it < 10 }
|
||||
.find { it == 2 }
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
arrayListOf(1, 5, 7).map { it * 2 } // RESULT: res0: kotlin.Int? = 2
|
||||
.filter { it < 10 }
|
||||
.find { it == 2 }
|
||||
|
||||
+3
-1
@@ -1,2 +1,4 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
foo() // ERROR: Unresolved reference: foo
|
||||
/** unresolved.kts:1 Unresolved reference: foo */
|
||||
/** unresolved.kts:3 Unresolved reference: foo */
|
||||
Vendored
+2
@@ -1 +1,3 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
foo()
|
||||
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
foo() // ERROR: error: unresolved reference: foo...
|
||||
/** unresolved.kts:1 error: unresolved reference: foo
|
||||
/** unresolved.kts:3 error: unresolved reference: foo
|
||||
foo()
|
||||
^ */
|
||||
+5
-3
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
foo.forEach { // ERROR: Unresolved reference: foo; Cannot choose among the following candidates without completing ty...
|
||||
1 + 1
|
||||
}
|
||||
@@ -5,8 +7,8 @@ foo.forEach { // ERROR: Unresolved reference: foo; Cannot choose among
|
||||
fun goo(a: String) { // ERROR: Unresolved reference: goo
|
||||
super.goo(a)
|
||||
}
|
||||
/** unresolvedMultiline.kts:1 Unresolved reference: foo */
|
||||
/** unresolvedMultiline.kts:1 Cannot choose among the following candidates without completing type inference:
|
||||
/** unresolvedMultiline.kts:3 Unresolved reference: foo */
|
||||
/** unresolvedMultiline.kts:3 Cannot choose among the following candidates without completing type inference:
|
||||
@HidesMembers public inline fun <T> Iterable<???>.forEach(action: (???) -> Unit): Unit defined in kotlin.collections
|
||||
@HidesMembers public inline fun <K, V> Map<out ???, ???>.forEach(action: (Map.Entry<???, ???>) -> Unit): Unit defined in kotlin.collections */
|
||||
/** unresolvedMultiline.kts:5 Unresolved reference: goo */
|
||||
/** unresolvedMultiline.kts:7 Unresolved reference: goo */
|
||||
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
foo.forEach {
|
||||
1 + 1
|
||||
}
|
||||
|
||||
+4
-2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
foo.forEach { // ERROR: error: unresolved reference: foo...
|
||||
1 + 1
|
||||
}
|
||||
@@ -5,7 +7,7 @@ foo.forEach { // ERROR: error: unresolved reference: foo...
|
||||
fun goo(a: String) { // ERROR: error: unresolved reference: goo...
|
||||
super.goo(a)
|
||||
}
|
||||
/** unresolvedMultiline.kts:1 error: unresolved reference: foo
|
||||
/** unresolvedMultiline.kts:3 error: unresolved reference: foo
|
||||
foo.forEach {
|
||||
^
|
||||
error: cannot choose among the following candidates without completing type inference:
|
||||
@@ -13,6 +15,6 @@ error: cannot choose among the following candidates without completing type infe
|
||||
@HidesMembers public inline fun <K, V> Map<out ???, ???>.forEach(action: (Map.Entry<???, ???>) -> Unit): Unit defined in kotlin.collections
|
||||
foo.forEach {
|
||||
^ */
|
||||
/** unresolvedMultiline.kts:5 error: unresolved reference: goo
|
||||
/** unresolvedMultiline.kts:7 error: unresolved reference: goo
|
||||
super.goo(a)
|
||||
^ */
|
||||
+2
@@ -1 +1,3 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
println("hello") // OUTPUT: hello
|
||||
Vendored
+2
@@ -1 +1,3 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
println("hello")
|
||||
+2
@@ -1 +1,3 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
println("hello") // OUTPUT: hello
|
||||
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
var a = 1 // RESULT: var a: Int
|
||||
a++ // RESULT: 1
|
||||
a // RESULT: 2
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
var a = 1
|
||||
a++
|
||||
a
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
var a = 1
|
||||
a++ // RESULT: res1: kotlin.Int = 1
|
||||
a // RESULT: res2: kotlin.Int = 2
|
||||
+9
-7
@@ -1,12 +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:2 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */
|
||||
/** veryLongOutput.kts:4 0123456789 */
|
||||
/** veryLongOutput.kts:4 0123456789 */
|
||||
/** veryLongOutput.kts:4 0123456789 */
|
||||
/** veryLongOutput.kts:4 0123456789 */
|
||||
/** veryLongOutput.kts:4 0123456789 */
|
||||
/** veryLongOutput.kts:5 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 */
|
||||
/** 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 */
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
val a = "a".repeat(100)
|
||||
a
|
||||
val b = "0123456789\n".repeat(10)
|
||||
|
||||
+5
-3
@@ -1,10 +1,12 @@
|
||||
// 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:2 res1: kotlin.String = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */
|
||||
/** veryLongOutput.kts:4 res3: kotlin.String = 0123456789
|
||||
/** veryLongOutput.kts:4 res1: kotlin.String = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */
|
||||
/** veryLongOutput.kts:6 res3: kotlin.String = 0123456789
|
||||
0123456789
|
||||
0123456789
|
||||
0123456789
|
||||
@@ -14,4 +16,4 @@ println("01234567890123456789012345678901234567890123456789012345678901234567890
|
||||
0123456789
|
||||
0123456789
|
||||
0123456789 */
|
||||
/** veryLongOutput.kts:5 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 */
|
||||
/** veryLongOutput.kts:7 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 */
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: false
|
||||
|
||||
val a = 1 // RESULT: val a: Int
|
||||
when(a) { // OUTPUT: 1
|
||||
1 -> println("1")
|
||||
|
||||
Vendored
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: ~REPL_MODE~
|
||||
|
||||
val a = 1
|
||||
when(a) {
|
||||
1 -> println("1")
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
// REPL_MODE: true
|
||||
|
||||
val a = 1
|
||||
when(a) { // OUTPUT: 1
|
||||
1 -> println("1")
|
||||
|
||||
@@ -15,8 +15,6 @@ 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.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiManager
|
||||
import com.intellij.testFramework.FileEditorManagerTestCase
|
||||
import com.intellij.testFramework.MapDataContext
|
||||
import com.intellij.testFramework.PsiTestUtil
|
||||
@@ -26,9 +24,11 @@ import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.idea.core.script.ScriptDependenciesManager
|
||||
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.ui.ScratchTopPanel
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
@@ -78,6 +78,9 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() {
|
||||
|
||||
val mainFileName = "$dirName/${getTestName(true)}.kts"
|
||||
doCompilingTest(mainFileName)
|
||||
|
||||
launchAction(ClearScratchAction())
|
||||
|
||||
doReplTest(mainFileName)
|
||||
|
||||
ModuleRootModificationUtil.updateModel(module) { model ->
|
||||
@@ -87,44 +90,16 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() {
|
||||
|
||||
fun doTest(fileName: String, isRepl: Boolean) {
|
||||
val sourceFile = File(testDataPath, fileName)
|
||||
val fileText = sourceFile.readText()
|
||||
val fileText = sourceFile.readText().inlinePropertiesValues(isRepl)
|
||||
|
||||
val scratchFile = createScratchFile(sourceFile.name, fileText)
|
||||
configureScratchByText(sourceFile.name, fileText)
|
||||
|
||||
ScriptDependenciesManager.updateScriptDependenciesSynchronously(scratchFile, project)
|
||||
if (!KotlinHighlightingUtil.shouldHighlight(myFixture.file)) error("Highlighting for scratch file is switched off")
|
||||
|
||||
val psiFile = PsiManager.getInstance(project).findFile(scratchFile) ?: error("Couldn't find psi file ${sourceFile.path}")
|
||||
launchScratch()
|
||||
waitUntilScratchFinishes()
|
||||
|
||||
if (!KotlinHighlightingUtil.shouldHighlight(psiFile)) error("Highlighting for scratch file is switched off")
|
||||
|
||||
val (editor, scratchPanel) = getEditorWithScratchPanel(myManager, scratchFile) ?: error("Couldn't find scratch panel")
|
||||
scratchPanel.scratchFile.saveOptions {
|
||||
copy(isRepl = isRepl, isInteractiveMode = false)
|
||||
}
|
||||
|
||||
if (!InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_MODULE")) {
|
||||
scratchPanel.setModule(myFixture.module)
|
||||
}
|
||||
|
||||
launchScratch(scratchFile)
|
||||
|
||||
val doc = PsiDocumentManager.getInstance(project).getDocument(psiFile) ?: error("Document for ${psiFile.name} is null")
|
||||
|
||||
val actualOutput = StringBuilder(psiFile.text)
|
||||
for (line in doc.lineCount - 1 downTo 0) {
|
||||
editor.editor.inlayModel.getInlineElementsInRange(
|
||||
doc.getLineStartOffset(line),
|
||||
doc.getLineEndOffset(line)
|
||||
).map { it.renderer }
|
||||
.filterIsInstance<InlayScratchFileRenderer>()
|
||||
.forEach {
|
||||
val str = it.toString()
|
||||
val offset = doc.getLineEndOffset(line); actualOutput.insert(
|
||||
offset,
|
||||
"${str.takeWhile { it.isWhitespace() }}// ${str.trim()}"
|
||||
)
|
||||
}
|
||||
}
|
||||
val actualOutput = getFileTextWithInlays()
|
||||
|
||||
val expectedFileName = if (isRepl) {
|
||||
fileName.replace(".kts", ".repl.after")
|
||||
@@ -135,7 +110,59 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() {
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile, actualOutput.toString())
|
||||
}
|
||||
|
||||
protected fun createScratchFile(name: String, text: String): VirtualFile {
|
||||
protected fun String.inlinePropertiesValues(
|
||||
isRepl: Boolean = false,
|
||||
isInteractiveMode: Boolean = false
|
||||
): String {
|
||||
return replace("~REPL_MODE~", isRepl.toString()).replace("~INTERACTIVE_MODE~", isInteractiveMode.toString())
|
||||
}
|
||||
|
||||
private fun getFileTextWithInlays(): StringBuilder {
|
||||
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
|
||||
}
|
||||
|
||||
protected fun getInlays(start: Int = 0, end: Int = myFixture.file.textLength): List<InlayScratchFileRenderer> {
|
||||
val inlineElementsInRange = myFixture.editor.inlayModel.getInlineElementsInRange(start, end)
|
||||
return inlineElementsInRange
|
||||
.map { it.renderer }
|
||||
.filterIsInstance<InlayScratchFileRenderer>()
|
||||
}
|
||||
|
||||
private fun configureOptions(
|
||||
scratchPanel: ScratchTopPanel,
|
||||
fileText: String
|
||||
) {
|
||||
if (InTextDirectivesUtils.getPrefixedBoolean(fileText, "// INTERACTIVE_MODE: ") != true) {
|
||||
scratchPanel.scratchFile.saveOptions {
|
||||
copy(isInteractiveMode = false)
|
||||
}
|
||||
}
|
||||
|
||||
if (InTextDirectivesUtils.getPrefixedBoolean(fileText, "// REPL_MODE: ") == true) {
|
||||
scratchPanel.scratchFile.saveOptions {
|
||||
copy(isRepl = true)
|
||||
}
|
||||
}
|
||||
|
||||
if (!InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_MODULE")) {
|
||||
scratchPanel.setModule(myFixture.module)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun configureScratchByText(name: String, text: String): ScratchTopPanel {
|
||||
val scratchFile = ScratchRootType.getInstance().createScratchFile(
|
||||
project,
|
||||
name,
|
||||
@@ -145,17 +172,30 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() {
|
||||
) ?: error("Couldn't create scratch file")
|
||||
|
||||
myFixture.openFileInEditor(scratchFile)
|
||||
return scratchFile
|
||||
|
||||
ScriptDependenciesManager.updateScriptDependenciesSynchronously(scratchFile, project)
|
||||
|
||||
val (_, scratchPanel) = getEditorWithScratchPanel(myManager, myFixture.file.virtualFile)
|
||||
?: error("Couldn't find scratch panel")
|
||||
|
||||
configureOptions(scratchPanel, text)
|
||||
|
||||
return scratchPanel
|
||||
}
|
||||
|
||||
protected fun launchScratch(scratchFile: VirtualFile) {
|
||||
protected fun launchScratch() {
|
||||
val action = RunScratchAction()
|
||||
val e = getActionEvent(scratchFile, action)
|
||||
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() {
|
||||
UIUtil.dispatchAllInvocationEvents()
|
||||
|
||||
val start = System.currentTimeMillis()
|
||||
@@ -175,6 +215,10 @@ abstract class AbstractScratchRunActionTest : FileEditorManagerTestCase() {
|
||||
return TestActionEvent(context, action)
|
||||
}
|
||||
|
||||
protected fun testScratchText(): String {
|
||||
return File(testDataPath, "idea/testData/scratch/custom/test_scratch.kts").readText()
|
||||
}
|
||||
|
||||
override fun getTestDataPath() = KotlinTestUtils.getHomeDirectory()
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ 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.scratch.output.InlayScratchFileRenderer
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner
|
||||
import org.junit.runner.RunWith
|
||||
@@ -26,22 +25,13 @@ class CustomScratchRunActionTest : AbstractScratchRunActionTest() {
|
||||
}
|
||||
|
||||
private fun getOutput(isRepl: Boolean): String {
|
||||
val fileText = "1"
|
||||
val scratchFile = createScratchFile("scratch_1.kts", fileText)
|
||||
val fileText = testScratchText().inlinePropertiesValues(isRepl)
|
||||
configureScratchByText("scratch_1.kts", fileText)
|
||||
|
||||
val (editor, scratchPanel) = getEditorWithScratchPanel(myManager, scratchFile) ?: error("Couldn't find scratch panel")
|
||||
scratchPanel.scratchFile.saveOptions {
|
||||
copy(isRepl = isRepl, isInteractiveMode = false)
|
||||
}
|
||||
launchScratch()
|
||||
waitUntilScratchFinishes()
|
||||
|
||||
scratchPanel.setModule(myFixture.module)
|
||||
|
||||
launchScratch(scratchFile)
|
||||
|
||||
return editor.editor.inlayModel.getInlineElementsInRange(0, fileText.length)
|
||||
.map { it.renderer }
|
||||
.filterIsInstance<InlayScratchFileRenderer>()
|
||||
.joinToString().trim()
|
||||
return getInlays().joinToString().trim()
|
||||
}
|
||||
|
||||
private val library: Library by lazy {
|
||||
|
||||
@@ -17,8 +17,7 @@ import kotlin.reflect.full.declaredMemberProperties
|
||||
class ScratchOptionsSaveTest : AbstractScratchRunActionTest() {
|
||||
|
||||
fun testOptionsSaveOnClosingFile() {
|
||||
val scratchFile = createScratchFile("scratch_1.kts", "val a = 1")
|
||||
val (_, scratchPanelBeforeClosingFile) = getEditorWithScratchPanel(myManager, scratchFile) ?: error("Couldn't find scratch panel")
|
||||
val scratchPanelBeforeClosingFile = configureScratchByText("scratch_1.kts", testScratchText())
|
||||
|
||||
Assert.assertEquals(
|
||||
"This test checks that checkbox options are restored after file closing. Not all checkboxes are checked in this test",
|
||||
@@ -34,10 +33,10 @@ class ScratchOptionsSaveTest : AbstractScratchRunActionTest() {
|
||||
scratchPanelBeforeClosingFile.setMakeBeforeRun(newIsMakeBeforeRunValue)
|
||||
scratchPanelBeforeClosingFile.setInteractiveMode(newIsInteractiveModeValue)
|
||||
|
||||
myManager.closeFile(scratchFile)
|
||||
myManager.openFile(scratchFile, true)
|
||||
myManager.closeFile(myFixture.file.virtualFile)
|
||||
myManager.openFile(myFixture.file.virtualFile, true)
|
||||
|
||||
val (_, scratchPanelAfterClosingFile) = getEditorWithScratchPanel(myManager, scratchFile) ?: error("Couldn't find scratch panel")
|
||||
val (_, scratchPanelAfterClosingFile) = getEditorWithScratchPanel(myManager, myFixture.file.virtualFile) ?: error("Couldn't find scratch panel")
|
||||
|
||||
Assert.assertEquals("Wrong value for isRepl checkbox", newIsReplValue, scratchPanelAfterClosingFile.scratchFile.options.isRepl)
|
||||
Assert.assertEquals(
|
||||
|
||||
Reference in New Issue
Block a user