Minor: extract classes
This commit is contained in:
+41
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.script
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.highlighting.HighlightUsagesHandler
|
||||||
|
import com.intellij.testFramework.exceptionCases.AbstractExceptionCase
|
||||||
|
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
|
||||||
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
|
import org.junit.ComparisonFailure
|
||||||
|
|
||||||
|
abstract class AbstractScriptConfigurationHighlightingTest : AbstractScriptConfigurationTest() {
|
||||||
|
fun doTest(path: String) {
|
||||||
|
configureScriptFile(path)
|
||||||
|
|
||||||
|
// Highlight references at caret
|
||||||
|
HighlightUsagesHandler.invoke(project, editor, myFile)
|
||||||
|
|
||||||
|
checkHighlighting(
|
||||||
|
editor,
|
||||||
|
InTextDirectivesUtils.isDirectiveDefined(file.text, "// CHECK_WARNINGS"),
|
||||||
|
InTextDirectivesUtils.isDirectiveDefined(file.text, "// CHECK_INFOS")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun doComplexTest(path: String) {
|
||||||
|
configureScriptFile(path)
|
||||||
|
assertException(object : AbstractExceptionCase<ComparisonFailure>() {
|
||||||
|
override fun getExpectedExceptionClass(): Class<ComparisonFailure> = ComparisonFailure::class.java
|
||||||
|
|
||||||
|
override fun tryClosure() {
|
||||||
|
checkHighlighting(editor, false, false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
ScriptConfigurationManager.updateScriptDependenciesSynchronously(myFile, project)
|
||||||
|
checkHighlighting(editor, false, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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.script
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.idea.navigation.GotoCheck
|
||||||
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
|
import org.jetbrains.kotlin.test.util.renderAsGotoImplementation
|
||||||
|
import org.junit.Assert
|
||||||
|
|
||||||
|
abstract class AbstractScriptConfigurationNavigationTest : AbstractScriptConfigurationTest() {
|
||||||
|
|
||||||
|
fun doTest(path: String) {
|
||||||
|
configureScriptFile(path)
|
||||||
|
val reference = file!!.findReferenceAt(myEditor.caretModel.offset)!!
|
||||||
|
|
||||||
|
val resolved = reference.resolve()!!.navigationElement!!
|
||||||
|
|
||||||
|
val expectedReference = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// REF:")
|
||||||
|
val actualReference = resolved.renderAsGotoImplementation()
|
||||||
|
|
||||||
|
Assert.assertEquals(expectedReference, actualReference)
|
||||||
|
|
||||||
|
val expectedFile = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// FILE:")
|
||||||
|
val actualFile = GotoCheck.getFileWithDir(resolved)
|
||||||
|
|
||||||
|
Assert.assertEquals(expectedFile, actualFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -54,93 +54,6 @@ import java.util.regex.Pattern
|
|||||||
import kotlin.script.dependencies.Environment
|
import kotlin.script.dependencies.Environment
|
||||||
import kotlin.script.experimental.api.ScriptDiagnostic
|
import kotlin.script.experimental.api.ScriptDiagnostic
|
||||||
|
|
||||||
|
|
||||||
abstract class AbstractScriptConfigurationHighlightingTest : AbstractScriptConfigurationTest() {
|
|
||||||
fun doTest(path: String) {
|
|
||||||
configureScriptFile(path)
|
|
||||||
|
|
||||||
// Highlight references at caret
|
|
||||||
HighlightUsagesHandler.invoke(project, editor, myFile)
|
|
||||||
|
|
||||||
checkHighlighting(
|
|
||||||
editor,
|
|
||||||
InTextDirectivesUtils.isDirectiveDefined(file.text, "// CHECK_WARNINGS"),
|
|
||||||
InTextDirectivesUtils.isDirectiveDefined(file.text, "// CHECK_INFOS")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun doComplexTest(path: String) {
|
|
||||||
configureScriptFile(path)
|
|
||||||
assertException(object : AbstractExceptionCase<ComparisonFailure>() {
|
|
||||||
override fun getExpectedExceptionClass(): Class<ComparisonFailure> = ComparisonFailure::class.java
|
|
||||||
|
|
||||||
override fun tryClosure() {
|
|
||||||
checkHighlighting(editor, false, false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
updateScriptDependenciesSynchronously(myFile, project)
|
|
||||||
checkHighlighting(editor, false, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AbstractScriptConfigurationNavigationTest : AbstractScriptConfigurationTest() {
|
|
||||||
|
|
||||||
fun doTest(path: String) {
|
|
||||||
configureScriptFile(path)
|
|
||||||
val reference = file!!.findReferenceAt(myEditor.caretModel.offset)!!
|
|
||||||
|
|
||||||
val resolved = reference.resolve()!!.navigationElement!!
|
|
||||||
|
|
||||||
val expectedReference = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// REF:")
|
|
||||||
val actualReference = resolved.renderAsGotoImplementation()
|
|
||||||
|
|
||||||
Assert.assertEquals(expectedReference, actualReference)
|
|
||||||
|
|
||||||
val expectedFile = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// FILE:")
|
|
||||||
val actualFile = GotoCheck.getFileWithDir(resolved)
|
|
||||||
|
|
||||||
Assert.assertEquals(expectedFile, actualFile)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
abstract class AbstractScriptDefinitionsOrderTest : AbstractScriptConfigurationTest() {
|
|
||||||
fun doTest(path: String) {
|
|
||||||
configureScriptFile(path)
|
|
||||||
|
|
||||||
assertException(object : AbstractExceptionCase<ComparisonFailure>() {
|
|
||||||
override fun getExpectedExceptionClass(): Class<ComparisonFailure> = ComparisonFailure::class.java
|
|
||||||
|
|
||||||
override fun tryClosure() {
|
|
||||||
checkHighlighting(editor, false, false)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
val definitions = InTextDirectivesUtils
|
|
||||||
.findStringWithPrefixes(myFile.text, "// SCRIPT DEFINITIONS: ")
|
|
||||||
?.split(";")
|
|
||||||
?.map { it.substringBefore(":").trim() to it.substringAfter(":").trim() }
|
|
||||||
?: error("SCRIPT DEFINITIONS directive should be defined")
|
|
||||||
|
|
||||||
val allDefinitions = ScriptDefinitionsManager.getInstance(project).getAllDefinitions()
|
|
||||||
for ((definitionName, action) in definitions) {
|
|
||||||
val scriptDefinition = allDefinitions
|
|
||||||
.find { it.name == definitionName }
|
|
||||||
?: error("Unknown script definition name in SCRIPT DEFINITIONS directive: name=$definitionName, all={${allDefinitions.joinToString { it.name }}}")
|
|
||||||
when (action) {
|
|
||||||
"off" -> KotlinScriptingSettings.getInstance(project).setEnabled(scriptDefinition, false)
|
|
||||||
else -> KotlinScriptingSettings.getInstance(project).setOrder(scriptDefinition, action.toInt())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ScriptDefinitionsManager.getInstance(project).reorderScriptDefinitions()
|
|
||||||
updateScriptDependenciesSynchronously(myFile, project)
|
|
||||||
|
|
||||||
checkHighlighting(editor, false, false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private val validKeys = setOf("javaHome", "sources", "classpath", "imports", "template-classes-names")
|
private val validKeys = setOf("javaHome", "sources", "classpath", "imports", "template-classes-names")
|
||||||
private const val useDefaultTemplate = "// DEPENDENCIES:"
|
private const val useDefaultTemplate = "// DEPENDENCIES:"
|
||||||
private const val templatesSettings = "// TEMPLATES: "
|
private const val templatesSettings = "// TEMPLATES: "
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* 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.script
|
||||||
|
|
||||||
|
import com.intellij.testFramework.exceptionCases.AbstractExceptionCase
|
||||||
|
import org.jetbrains.kotlin.idea.core.script.ScriptConfigurationManager
|
||||||
|
import org.jetbrains.kotlin.idea.core.script.ScriptDefinitionsManager
|
||||||
|
import org.jetbrains.kotlin.idea.core.script.settings.KotlinScriptingSettings
|
||||||
|
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||||
|
import org.junit.ComparisonFailure
|
||||||
|
|
||||||
|
abstract class AbstractScriptDefinitionsOrderTest : AbstractScriptConfigurationTest() {
|
||||||
|
fun doTest(path: String) {
|
||||||
|
configureScriptFile(path)
|
||||||
|
|
||||||
|
assertException(object : AbstractExceptionCase<ComparisonFailure>() {
|
||||||
|
override fun getExpectedExceptionClass(): Class<ComparisonFailure> = ComparisonFailure::class.java
|
||||||
|
|
||||||
|
override fun tryClosure() {
|
||||||
|
checkHighlighting(editor, false, false)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
val definitions = InTextDirectivesUtils.findStringWithPrefixes(myFile.text, "// SCRIPT DEFINITIONS: ")
|
||||||
|
?.split(";")
|
||||||
|
?.map { it.substringBefore(":").trim() to it.substringAfter(":").trim() }
|
||||||
|
?: error("SCRIPT DEFINITIONS directive should be defined")
|
||||||
|
|
||||||
|
val allDefinitions = ScriptDefinitionsManager.getInstance(project).getAllDefinitions()
|
||||||
|
for ((definitionName, action) in definitions) {
|
||||||
|
val scriptDefinition = allDefinitions
|
||||||
|
.find { it.name == definitionName }
|
||||||
|
?: error("Unknown script definition name in SCRIPT DEFINITIONS directive: name=$definitionName, all={${allDefinitions.joinToString { it.name }}}")
|
||||||
|
when (action) {
|
||||||
|
"off" -> KotlinScriptingSettings.getInstance(project).setEnabled(scriptDefinition, false)
|
||||||
|
else -> KotlinScriptingSettings.getInstance(project).setOrder(scriptDefinition, action.toInt())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptDefinitionsManager.getInstance(project).reorderScriptDefinitions()
|
||||||
|
ScriptConfigurationManager.updateScriptDependenciesSynchronously(myFile, project)
|
||||||
|
|
||||||
|
checkHighlighting(editor, false, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user