Convert line endings when creating ReplCodeLine, fixes KT-15861
(cherry picked from commit 894ee4c)
This commit is contained in:
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.cli.jvm.repl
|
||||
|
||||
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.vfs.CharsetToolkit
|
||||
import com.intellij.psi.PsiFileFactory
|
||||
import com.intellij.psi.impl.PsiFileFactoryImpl
|
||||
@@ -85,7 +86,7 @@ open class GenericReplChecker(
|
||||
stateLock.write {
|
||||
val scriptFileName = makeScriptBaseName(codeLine, generation)
|
||||
val virtualFile =
|
||||
LightVirtualFile("$scriptFileName${KotlinParserDefinition.STD_SCRIPT_EXT}", KotlinLanguage.INSTANCE, codeLine.code).apply {
|
||||
LightVirtualFile("$scriptFileName${KotlinParserDefinition.STD_SCRIPT_EXT}", KotlinLanguage.INSTANCE, StringUtil.convertLineSeparators(codeLine.code)).apply {
|
||||
charset = CharsetToolkit.UTF8_CHARSET
|
||||
}
|
||||
val psiFile: KtFile = psiFileFactory.trySetupPsiForFile(virtualFile, KotlinLanguage.INSTANCE, true, false) as KtFile?
|
||||
|
||||
@@ -82,6 +82,23 @@ class GenericReplTest : TestCase() {
|
||||
Disposer.dispose(disposable)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReplCodeFormat() {
|
||||
|
||||
val disposable = Disposer.newDisposable()
|
||||
|
||||
val repl = TestRepl(disposable,
|
||||
listOf(File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-runtime.jar")),
|
||||
"kotlin.script.templates.standard.ScriptTemplateWithArgs")
|
||||
|
||||
val codeLine0 = ReplCodeLine(0, "val l1 = 1\r\nl1\r\n")
|
||||
val res0 = repl.replCompiler?.check(codeLine0)
|
||||
val res0c = res0 as? ReplCheckResult.Ok
|
||||
TestCase.assertNotNull("Unexpected compile result: $res0", res0c)
|
||||
|
||||
Disposer.dispose(disposable)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRepPackage() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user