Files
openide/java/java-tests/testSrc/com/intellij/execution/ui/VmOptionsEditorTest.java
Louis Vignier 4319199c41 [ui] Set caret position to 0 when opening VM options editor
#IDEA-355487 Fixed

GitOrigin-RevId: 414fc476f093c8af5dcb8ab4b8fcf0d98eba4b5e
2024-07-19 14:33:47 +00:00

46 lines
1.8 KiB
Java

// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.execution.ui;
import com.intellij.execution.application.ApplicationConfiguration;
import com.intellij.testFramework.LightPlatform4TestCase;
import com.intellij.ui.EditorTextField;
import org.junit.Test;
public class VmOptionsEditorTest extends LightPlatform4TestCase {
@Test
public void testVmOptionsEditor() {
ApplicationConfiguration configuration = new ApplicationConfiguration("Test", getProject());
VmOptionsEditor editor = new VmOptionsEditor(configuration);
String text = " -XX:Abc=\"hello world\" -XX<caret>:Def=123";
EditorTextField origField = editor.getTextField();
origField.addNotify();
assertNotNull(origField.getEditor(true));
assertTrue(origField.getEditor().isOneLineMode());
assertFalse(editor.isExpanded());
origField.setText(text.replace("<caret>", ""));
origField.getEditor().getCaretModel().moveToOffset(text.indexOf("<caret>"));
checkExpectedText(origField, text);
editor.expand();
assertTrue(editor.isExpanded());
EditorTextField expanded = editor.getTextField();
expanded.addNotify();
assertNotNull(expanded.getEditor(true));
assertFalse(expanded.getEditor().isOneLineMode());
checkExpectedText(expanded, """
<caret>-XX:Abc="hello world"
-XX:Def=123""");
editor.collapse();
expanded.removeNotify();
origField.removeNotify();
}
private static void checkExpectedText(EditorTextField expanded, String expected) {
int offset = expanded.getEditor().getCaretModel().getOffset();
String expandedText = expanded.getText();
String expandedTextWithCaret = expandedText.substring(0, offset) + "<caret>" + expandedText.substring(offset);
assertEquals(expected, expandedTextWithCaret);
}
}