From 5c45aa7782b344aa0f6e5af291b4d167c82236a8 Mon Sep 17 00:00:00 2001 From: Alexandr Evstigneev Date: Sat, 14 Sep 2024 16:26:43 +0400 Subject: [PATCH] #2894 Added test illustrating incorrect behavior Editor is not closed but updated text is wrong --- .../java/intellilang/PerlQuickEditTest.kt | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 plugin/src/test/java/intellilang/PerlQuickEditTest.kt diff --git a/plugin/src/test/java/intellilang/PerlQuickEditTest.kt b/plugin/src/test/java/intellilang/PerlQuickEditTest.kt new file mode 100644 index 0000000000..0b62c8bec1 --- /dev/null +++ b/plugin/src/test/java/intellilang/PerlQuickEditTest.kt @@ -0,0 +1,91 @@ +/* + * Copyright 2015-2024 Alexandr Evstigneev + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package intellilang + +import base.PerlLightTestCase +import com.intellij.codeInsight.intention.impl.QuickEditAction +import com.intellij.testFramework.fixtures.InjectionTestFixture +import org.jetbrains.annotations.NonNls +import org.junit.Test + +class PerlQuickEditTest : PerlLightTestCase() { + override fun getBaseDataPath(): @NonNls String? = "intellilang/perl/quickedit" + private val injectionTestFixture: InjectionTestFixture get() = InjectionTestFixture(myFixture) + + @Test + fun testEditHeredoc() { + initWithTextSmart( + """ + use v5.36; + + sub foo{ + say <<~HTML; +
+ + +
+ HTML + }""".trimIndent() + ) + val originalEditor = injectionTestFixture.topLevelEditor + val quickEditHandler = QuickEditAction().invokeImpl(project, injectionTestFixture.topLevelEditor, injectionTestFixture.topLevelFile) + val fragmentFile = quickEditHandler.newFile + assertEquals( + """ +
+ + +
+ """.trimIndent(), fragmentFile.text.trim() + ) + + myFixture.openFileInEditor(fragmentFile.virtualFile) + + myFixture.editor.caretModel.moveToOffset(fragmentFile.text.indexAfter("")) + myFixture.type("\nhello there") + assertFalse(myFixture.editor.isDisposed) + assertEquals( + """ +
+ + hello there + +
""".trimIndent(), myFixture.editor.document.text.trim().replace(Regex("[ \t]+\n"), "\n") + ) + + assertEquals( + """ + use v5.36; + + sub foo{ + say <<~HTML; +
+ + hello there + +
+ HTML + }""".trimIndent(), originalEditor.document.text + ) + } + + private fun String.indexAfter(string: String): Int { + val r = indexOf(string) + return if (r == -1) -1 else r + string.length + } + +} \ No newline at end of file