move several test cases to corresponding modules to have access to the appropriate file type to be tested; use explicit file type for that to avoid nonobvious implicit dependencies

GitOrigin-RevId: b574567672b8880795ff58e8351791c9d227ed07
This commit is contained in:
Alexey Kudravtsev
2021-10-13 11:17:54 +00:00
committed by intellij-monorepo-bot
parent 828468402f
commit 2f5354d87e
27 changed files with 326 additions and 1121 deletions
@@ -1,13 +1,15 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.navigation;
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight;
import com.intellij.codeInsight.navigation.CtrlMouseHandler;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.testFramework.TestFileType;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.testFramework.fixtures.EditorMouseFixture;
import com.intellij.util.TestTimeOut;
import com.intellij.util.ui.UIUtil;
@@ -20,7 +22,7 @@ import java.util.stream.Stream;
public class CtrlMouseHandlerTest extends AbstractEditorTest {
public void testHighlighterDisappearsOnMouseMovingAway() {
init("class A {}", TestFileType.JAVA);
init("class A {}", JavaFileType.INSTANCE);
EditorMouseFixture mouse = mouse();
mouse.ctrl().moveTo(0, 6);
assertHighlighted(6, 7);
@@ -51,6 +53,9 @@ public class CtrlMouseHandlerTest extends AbstractEditorTest {
}
private void waitForHighlighting() {
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
UIUtil.dispatchAllInvocationEvents();
CtrlMouseHandler handler = getProject().getService(CtrlMouseHandler.class);
TestTimeOut t = TestTimeOut.setTimeout(1, TimeUnit.MINUTES);
while (handler.isCalculationInProgress()) {
@@ -3,6 +3,7 @@ package com.intellij.codeInsight.documentation.render;
import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.codeInsight.folding.CodeFoldingSettings;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.application.impl.NonBlockingReadActionImpl;
import com.intellij.openapi.editor.CustomFoldRegion;
@@ -15,7 +16,6 @@ import com.intellij.openapi.editor.impl.Interval;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.testFramework.TestFileType;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -252,7 +252,7 @@ public class JavaDocRenderTest extends AbstractEditorTest {
private void configure(@NotNull String text, boolean enableRendering) {
EditorSettingsExternalizable.getInstance().setDocCommentRenderingEnabled(enableRendering);
init(text, TestFileType.JAVA);
init(text, JavaFileType.INSTANCE);
updateRenderedItems(enableRendering);
}
@@ -1,16 +1,16 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.codeInsight.editorActions;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.testFramework.TestFileType;
public class JavaEditingTest extends AbstractEditorTest {
public void testSmartHomeInJavadoc() {
init("/**\n" +
" * some text<caret>\n" +
" */\n" +
"class C {}",
TestFileType.JAVA);
"class C {}",
JavaFileType.INSTANCE);
home();
checkResultByText("/**\n" +
" * <caret>some text\n" +
@@ -23,7 +23,7 @@ public class JavaEditingTest extends AbstractEditorTest {
" * some text<caret>\n" +
" */\n" +
"class C {}",
TestFileType.JAVA);
JavaFileType.INSTANCE);
homeWithSelection();
checkResultByText("/**\n" +
" * <selection><caret>some text</selection>\n" +
@@ -16,7 +16,7 @@
package com.intellij.java.codeInsight.editorActions;
import com.intellij.codeInsight.editorActions.AbstractMoveElementLeftRightTest;
import com.intellij.testFramework.TestFileType;
import com.intellij.ide.highlighter.JavaFileType;
public class MoveElementLeftRightTest extends AbstractMoveElementLeftRightTest {
public void testMoveLiteralMethodParameter() throws Exception {
@@ -134,6 +134,6 @@ public class MoveElementLeftRightTest extends AbstractMoveElementLeftRightTest {
@Override
protected void configureEditor(String contents) {
init(contents, TestFileType.JAVA);
init(contents, JavaFileType.INSTANCE);
}
}
@@ -1,59 +0,0 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* 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 com.intellij.java.codeInsight.editorActions
import com.intellij.codeInsight.CodeInsightSettings
import com.intellij.openapi.editor.impl.AbstractEditorTest
import com.intellij.testFramework.TestFileType
import groovy.transform.CompileStatic
/**
* @author Denis Zhdanov
*/
@CompileStatic
class SelectionQuotingTest extends AbstractEditorTest {
void testBuggySelection() {
def initial = '''\
var a = "a test";
var b = <selection>[a]</selection><caret>;
var c = "test test test";\
'''
def action = { type('"abc')}
def expected = '''\
var a = "a test";
var b = "abc<caret>";
var c = "test test test";\
'''
doTest(initial, expected, action, TestFileType.JS)
}
void doTest(String initial, String expected, Closure action, TestFileType fileType = TestFileType.JAVA) {
configureFromFileText("${getTestName(false)}.$fileType.extension", initial)
def settings = CodeInsightSettings.getInstance()
def old = settings.SURROUND_SELECTION_ON_QUOTE_TYPED
settings.SURROUND_SELECTION_ON_QUOTE_TYPED = true
try {
action()
}
finally {
settings.SURROUND_SELECTION_ON_QUOTE_TYPED = old
}
checkResultByText(expected)
}
}
@@ -16,6 +16,7 @@
package com.intellij.java.openapi.editor.impl;
import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.lang.ASTNode;
import com.intellij.lang.folding.FoldingBuilder;
import com.intellij.lang.folding.FoldingDescriptor;
@@ -26,11 +27,12 @@ import com.intellij.openapi.editor.CaretModel;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.openapi.fileTypes.PlainTextLanguage;
import com.intellij.openapi.util.ModificationTracker;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.testFramework.TestFileType;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
@@ -51,7 +53,7 @@ public class FoldingProcessingOnDocumentModificationTest extends AbstractEditorT
" */\n" +
"public <caret>class Test {\n" +
"}";
init(text, TestFileType.JAVA);
init(text, JavaFileType.INSTANCE);
CaretModel caretModel = getEditor().getCaretModel();
int caretOffset = caretModel.getOffset();
@@ -75,7 +77,7 @@ public class FoldingProcessingOnDocumentModificationTest extends AbstractEditorT
" System.out.println();\n" +
" System.out.println();\n" +
" }\n" +
"}", TestFileType.JAVA);
"}", JavaFileType.INSTANCE);
buildInitialFoldRegions();
executeAction(IdeActions.ACTION_COLLAPSE_ALL_REGIONS);
@@ -144,7 +146,7 @@ public class FoldingProcessingOnDocumentModificationTest extends AbstractEditorT
return true;
}
}, () -> {
openEditor("<caret>\nvalue", TestFileType.TEXT);
openEditor("<caret>\nvalue", PlainTextFileType.INSTANCE);
checkFoldingState("[FoldRegion +(1:6), placeholder='0']");
valuePlaceholder[0] = 1;
runFoldingPass();
@@ -166,7 +168,7 @@ public class FoldingProcessingOnDocumentModificationTest extends AbstractEditorT
return setting.get();
}
}, () -> {
openEditor("<caret>\nvalue", TestFileType.TEXT);
openEditor("<caret>\nvalue", PlainTextFileType.INSTANCE);
checkFoldingState("[FoldRegion +(1:6), placeholder='foo']");
setting.set(false);
runFoldingPass();
@@ -185,10 +187,10 @@ public class FoldingProcessingOnDocumentModificationTest extends AbstractEditorT
}
private void openJavaEditor(String text) {
openEditor(text, TestFileType.JAVA);
openEditor(text, JavaFileType.INSTANCE);
}
private void openEditor(String text, TestFileType fileType) {
private void openEditor(String text, FileType fileType) {
init(text, fileType);
buildInitialFoldRegions();
runFoldingPass(true);
@@ -15,16 +15,16 @@
*/
package com.intellij.java.psi.formatter.java;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.testFramework.TestFileType;
public class JavaAutoIndentLinesTest extends AbstractEditorTest {
public void testSelection() {
init("class C {\n" +
"int <selection>a<caret></selection> = 1;\n" +
"}",
TestFileType.JAVA);
JavaFileType.INSTANCE);
executeAction(IdeActions.ACTION_EDITOR_AUTO_INDENT_LINES);
checkResultByText("class C {\n" +
" int <selection>a<caret></selection> = 1;\n" +
@@ -1,37 +1,37 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.editor.actions;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.testFramework.TestFileType;
public class JavaEditorActionTest extends AbstractEditorTest {
public void testDeleteToWordStartWithEscapeChars() {
init("class Foo { String s = \"a\\nb<caret>\"; }", TestFileType.JAVA);
init("class Foo { String s = \"a\\nb<caret>\"; }", JavaFileType.INSTANCE);
executeAction(IdeActions.ACTION_EDITOR_DELETE_TO_WORD_START);
checkResultByText("class Foo { String s = \"a\\n<caret>\"; }");
}
public void testDeleteToWordEndWithEscapeChars() {
init("class Foo { String s = \"a\\<caret>nb\"; }", TestFileType.JAVA);
init("class Foo { String s = \"a\\<caret>nb\"; }", JavaFileType.INSTANCE);
executeAction(IdeActions.ACTION_EDITOR_DELETE_TO_WORD_END);
checkResultByText("class Foo { String s = \"a\\<caret>b\"; }");
}
public void testToggleCaseForTextAfterEscapedSlash() {
init("class C { String s = \"<selection>ab\\\\cd<caret></selection>\"; }", TestFileType.JAVA);
init("class C { String s = \"<selection>ab\\\\cd<caret></selection>\"; }", JavaFileType.INSTANCE);
executeAction(IdeActions.ACTION_EDITOR_TOGGLE_CASE);
checkResultByText("class C { String s = \"<selection>AB\\\\CD<caret></selection>\"; }");
}
public void testToggleCaseForEscapedChar() {
init("class C { String s = \"<selection>ab\\ncd<caret></selection>\"; }", TestFileType.JAVA);
init("class C { String s = \"<selection>ab\\ncd<caret></selection>\"; }", JavaFileType.INSTANCE);
executeAction(IdeActions.ACTION_EDITOR_TOGGLE_CASE);
checkResultByText("class C { String s = \"<selection>AB\\nCD<caret></selection>\"; }");
}
public void testDeleteToWordStartWithEscapedQuote() {
init("class Foo { String s = \"\\\"a<caret>\"; }", TestFileType.JAVA);
init("class Foo { String s = \"\\\"a<caret>\"; }", JavaFileType.INSTANCE);
executeAction(IdeActions.ACTION_EDITOR_DELETE_TO_WORD_START);
checkResultByText("class Foo { String s = \"\\\"<caret>\"; }");
}
@@ -1,20 +1,20 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.editor.impl.softwrap.mapping;
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.editor.impl;
import com.intellij.codeInsight.folding.CodeFoldingManager;
import com.intellij.codeInsight.generation.actions.CommentByLineCommentAction;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.ex.DocumentEx;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.editor.impl.SoftWrapModelImpl;
import com.intellij.openapi.editor.impl.softwrap.mapping.IncrementalCacheUpdateEvent;
import com.intellij.openapi.editor.impl.softwrap.mapping.SoftWrapAwareDocumentParsingListenerAdapter;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.TestFileType;
import gnu.trove.TIntHashSet;
import org.jetbrains.annotations.NotNull;
@@ -844,7 +844,7 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorT
" }\n" +
"\n" +
"}";
init(511, text, TestFileType.JAVA, 10);
init(511, text, JavaFileType.INSTANCE, 10);
addCollapsedFoldRegion(text.indexOf("new Runnable"), text.indexOf("System"), "Runnable() { ");
@@ -975,7 +975,7 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorT
}
public void testOnlyMinimalRangeIsRecalculatedOnDocumentChange() {
init("aa bb cc dd ee ff<caret> gg hh ii jj", TestFileType.TEXT);
init("aa bb cc dd ee ff<caret> gg hh ii jj", PlainTextFileType.INSTANCE);
EditorTestUtil.configureSoftWraps(getEditor(), 8);
verifySoftWrapPositions(8, 15, 21);
@@ -1056,7 +1056,7 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorT
}
private void init(final int visibleWidthInColumns, @NotNull String fileText, boolean useCustomSoftWrapIndent) {
init(visibleWidthInColumns * DEFAULT_SYMBOL_WIDTH_PX, fileText, TestFileType.TEXT, DEFAULT_SYMBOL_WIDTH_PX, useCustomSoftWrapIndent);
init(visibleWidthInColumns * DEFAULT_SYMBOL_WIDTH_PX, fileText, PlainTextFileType.INSTANCE, DEFAULT_SYMBOL_WIDTH_PX, useCustomSoftWrapIndent);
}
private void init(final int visibleWidthInColumns, final int symbolWidthInPixels, @NotNull String fileText) {
@@ -1064,14 +1064,14 @@ public class SoftWrapApplianceOnDocumentModificationTest extends AbstractEditorT
}
private void init(final int visibleWidth, @NotNull String fileText, int symbolWidth) {
init(visibleWidth, fileText, TestFileType.TEXT, symbolWidth);
init(visibleWidth, fileText, PlainTextFileType.INSTANCE, symbolWidth);
}
private void init(final int visibleWidth, @NotNull String fileText, @NotNull TestFileType fileType, final int symbolWidth) {
private void init(final int visibleWidth, @NotNull String fileText, @NotNull FileType fileType, final int symbolWidth) {
init(visibleWidth, fileText, fileType, symbolWidth, true);
}
private void init(final int visibleWidth, @NotNull String fileText, @NotNull TestFileType fileType, final int symbolWidth, boolean useCustomSoftWrapIndent) {
private void init(final int visibleWidth, @NotNull String fileText, @NotNull FileType fileType, final int symbolWidth, boolean useCustomSoftWrapIndent) {
init(fileText, fileType);
EditorTestUtil.configureSoftWraps(getEditor(), visibleWidth, 1000, symbolWidth, useCustomSoftWrapIndent);
}
@@ -1,12 +1,12 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util
import com.intellij.ide.highlighter.JavaFileType
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.openapi.editor.impl.AbstractEditorTest
import com.intellij.testFramework.MapDataContext
import com.intellij.testFramework.TestFileType
import org.junit.Test
import java.awt.Dimension
import java.awt.Point
@@ -15,13 +15,13 @@ import java.awt.Point
class PopupUtilTest : AbstractEditorTest() {
@Test
fun `test popups positions inside editor`() {
fun testPopupPositionsInsideEditor() {
init("""
import org.junit.Test
class TestCase {
@Test fun tes<caret>t() {}
}
""".trimIndent(), TestFileType.TEXT)
""".trimIndent(), JavaFileType.INSTANCE)
val editor = editor as EditorEx
editor.scrollPane.viewport.apply {
viewPosition = Point(0, 0)
@@ -1,102 +0,0 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* 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 com.intellij.codeInsight;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.testFramework.TestFileType;
import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
public class BlockSelectionEditingTest extends AbstractEditorTest {
public void testBlockRemovalAndCollapsedFoldRegionsBefore() {
// Inspired by IDEA-69371
String initialText =
"fold line #1\n" +
"fold line #2\n" +
"initialText line 1\n" +
"initialText line 2\n" +
"initialText line 3";
init(initialText, TestFileType.TEXT);
final int foldEndOffset = initialText.indexOf("initialText");
addCollapsedFoldRegion(0, foldEndOffset, "...");
int column = "initialText".length();
final LogicalPosition blockStart = new LogicalPosition(3, column);
final LogicalPosition blockEnd = new LogicalPosition(4, column);
final SelectionModel selectionModel = getEditor().getSelectionModel();
selectionModel.setBlockSelection(blockStart, blockEnd);
delete();
delete();
String expectedText =
"fold line #1\n" +
"fold line #2\n" +
"initialText line 1\n" +
"initialText line 2\n" +
"initialText line 3";
assertEquals(expectedText, getEditor().getDocument().getText());
assertSelectionRanges(new int[][]{{59, 59}, {79, 79}});
final FoldRegion foldRegion = getFoldRegion(0);
assertNotNull(foldRegion);
assertEquals(0, foldRegion.getStartOffset());
assertEquals(foldEndOffset, foldRegion.getEndOffset());
}
public void testBlockSelectionAndCollapsedFolding() {
String text =
"class Test {\n" +
" private class Inner1 {\n" +
" int i;\n" +
" }\n" +
"\n" +
" private class Inner2 {\n" +
" int i;\n" +
" }\n" +
"}";
init(text, TestFileType.JAVA);
int foldStart1 = text.indexOf("Inner1");
foldStart1 = text.indexOf('{', foldStart1);
int foldEnd1 = text.indexOf('}', foldStart1) + 1;
addCollapsedFoldRegion(foldStart1, foldEnd1, "...");
int foldStart2 = text.indexOf('{', foldEnd1);
int foldEnd2 = text.indexOf('}', foldStart2) + 1;
addCollapsedFoldRegion(foldStart2, foldEnd2, "...");
LogicalPosition blockStart = new LogicalPosition(1, 4);
LogicalPosition blockEnd = new LogicalPosition(5, 5 + "private".length());
getEditor().getSelectionModel().setBlockSelection(blockStart, blockEnd);
assertTrue(getFoldRegion(foldStart1).isExpanded());
assertFalse(getFoldRegion(foldStart2).isExpanded());
}
public void testBlockSelectionOnEmptyFile() {
initText("");
getEditor().getSelectionModel().setBlockSelection(new LogicalPosition(0, 0), new LogicalPosition(0, 0));
assertArrayEquals(getEditor().getSelectionModel().getBlockSelectionStarts(), new int[]{0});
assertArrayEquals(getEditor().getSelectionModel().getBlockSelectionEnds(), new int[]{0});
}
}
@@ -16,14 +16,17 @@
package com.intellij.codeInsight.folding.impl;
import com.intellij.lang.ASTNode;
import com.intellij.lang.folding.*;
import com.intellij.lang.folding.CustomFoldingBuilder;
import com.intellij.lang.folding.FoldingBuilder;
import com.intellij.lang.folding.FoldingDescriptor;
import com.intellij.lang.folding.LanguageFolding;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.openapi.fileTypes.PlainTextLanguage;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.TestFileType;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -36,7 +39,7 @@ public class CompositeFoldingBuilderTest extends AbstractEditorTest {
@Override
protected void setUp() throws Exception {
super.setUp();
init("Some plain text to fold", TestFileType.TEXT);
init("Some plain text to fold", PlainTextFileType.INSTANCE);
}
public void testAllowOnlyOneDescriptorPerTextRange() {
@@ -12,12 +12,12 @@ import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.openapi.vfs.VfsUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentListener;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.testFramework.LeakHunter;
import com.intellij.testFramework.TestFileType;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -68,7 +68,7 @@ public class BookmarkManagerTest extends AbstractEditorTest {
" int i = 1;\n" +
" }\n" +
"}";
init(text, TestFileType.TEXT);
init(text, PlainTextFileType.INSTANCE);
addBookmark(2);
List<Bookmark> bookmarksBefore = getManager().getBookmarks();
@@ -92,7 +92,7 @@ public class BookmarkManagerTest extends AbstractEditorTest {
" int i = 1;\n" +
" }\n" +
"}";
init(text, TestFileType.TEXT);
init(text, PlainTextFileType.INSTANCE);
addBookmark(2);
Document document = getEditor().getDocument();
@@ -110,7 +110,7 @@ public class BookmarkManagerTest extends AbstractEditorTest {
" int j = 1;\n" +
" }\n" +
"}";
init(text, TestFileType.TEXT);
init(text, PlainTextFileType.INSTANCE);
addBookmark(2);
addBookmark(3);
@@ -136,7 +136,7 @@ public class BookmarkManagerTest extends AbstractEditorTest {
" int j = 1;\n" +
" }\n" +
"}";
init(text, TestFileType.TEXT);
init(text, PlainTextFileType.INSTANCE);
addBookmark(2);
addBookmark(3);
@@ -153,7 +153,7 @@ public class BookmarkManagerTest extends AbstractEditorTest {
for (Bookmark bookmark : bookmarksAfter) {
checkBookmarkNavigation(bookmark);
}
init(text, TestFileType.TEXT);
init(text, PlainTextFileType.INSTANCE);
getEditor().getCaretModel().setCaretsAndSelections(
Collections.singletonList(
new CaretState(getEditor().visualToLogicalPosition(new VisualPosition(2, getEditor().getDocument().getLineEndOffset(2))), null, null)));
@@ -168,7 +168,7 @@ public class BookmarkManagerTest extends AbstractEditorTest {
" int i = 1;\n" +
" }\n" +
"}";
init(text, TestFileType.TEXT);
init(text, PlainTextFileType.INSTANCE);
addBookmark(2);
assertEquals(1, getManager().getBookmarks().size());
@@ -16,9 +16,9 @@
package com.intellij.openapi.editor;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.TestFileType;
public class EditorMultiCaretPerformanceTest extends AbstractEditorTest {
public void testTyping() {
@@ -56,7 +56,7 @@ public class EditorMultiCaretPerformanceTest extends AbstractEditorTest {
int caretCount = 1000;
int charactersToType = 100;
String initialText = "<root>\n" + StringUtil.repeat(" <node><caret></node>\n", caretCount) + "</root>";
init(initialText, TestFileType.XML);
init(initialText, StdFileTypes.XML);
PlatformTestUtil.startPerformanceTest("Typing in XML with large number of carets", 100_000, () -> {
for (int i = 0; i < charactersToType; i++) {
type('a');
@@ -24,7 +24,7 @@ import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.fileEditor.impl.CurrentEditorProvider;
import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider;
import com.intellij.testFramework.TestFileType;
import com.intellij.openapi.fileTypes.PlainTextFileType;
public class EditorMultiCaretUndoRedoTest extends AbstractEditorTest {
private CurrentEditorProvider mySavedCurrentEditorProvider;
@@ -130,7 +130,7 @@ public class EditorMultiCaretUndoRedoTest extends AbstractEditorTest {
}
private void init(String text) {
init(text, TestFileType.TEXT);
init(text, PlainTextFileType.INSTANCE);
setEditorVisibleSize(1000, 1000);
getUndoManager().setEditorProvider(new CurrentEditorProvider() {
@Override
@@ -8,16 +8,16 @@ import com.intellij.openapi.editor.EditorSettings;
import com.intellij.openapi.editor.VisualPosition;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.openapi.ide.CopyPasteManager;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.TestFileType;
import java.awt.datatransfer.StringSelection;
public class EditorActionTest extends AbstractEditorTest {
public void testDownWithSelectionWhenCaretsAreAllowedInsideTabs() {
init("<caret>text",
TestFileType.TEXT);
PlainTextFileType.INSTANCE);
final EditorSettings editorSettings = getEditor().getSettings();
final boolean old = editorSettings.isCaretInsideTabs();
@@ -33,7 +33,7 @@ public class EditorActionTest extends AbstractEditorTest {
public void testPageDownWithSelectionWhenCaretsAreAllowedInsideTabs() {
init("<caret>line 1\n" +
"line 2",
TestFileType.TEXT);
PlainTextFileType.INSTANCE);
setEditorVisibleSize(100, 100);
final EditorSettings editorSettings = getEditor().getSettings();
@@ -50,7 +50,7 @@ public class EditorActionTest extends AbstractEditorTest {
}
public void testDuplicateFirstLineWhenSoftWrapsAreOn() {
init("long long t<caret>ext", TestFileType.TEXT);
init("long long t<caret>ext", PlainTextFileType.INSTANCE);
EditorTestUtil.configureSoftWraps(getEditor(), 10);
executeAction("EditorDuplicate");
@@ -59,7 +59,7 @@ public class EditorActionTest extends AbstractEditorTest {
}
public void testTabWithSelection() {
init("some<selection> <caret></selection>text", TestFileType.TEXT);
init("some<selection> <caret></selection>text", PlainTextFileType.INSTANCE);
executeAction("EditorTab");
checkResultByText("some <caret>text");
}
@@ -69,7 +69,7 @@ public class EditorActionTest extends AbstractEditorTest {
"line 1\n" +
"<selection>line 2\n" +
"</selection>line 3";
init(text, TestFileType.TEXT);
init(text, PlainTextFileType.INSTANCE);
deleteLine();
checkResultByText(
"line 1\n" +
@@ -82,7 +82,7 @@ public class EditorActionTest extends AbstractEditorTest {
"1\n" +
"2<caret>\n" +
"3";
init(text, TestFileType.TEXT);
init(text, PlainTextFileType.INSTANCE);
deleteLine();
deleteLine();
@@ -90,7 +90,7 @@ public class EditorActionTest extends AbstractEditorTest {
}
public void testDeleteLastNonEmptyLine() {
init("<caret>1\n", TestFileType.TEXT);
init("<caret>1\n", PlainTextFileType.INSTANCE);
deleteLine();
checkResultByText("");
}
@@ -98,7 +98,7 @@ public class EditorActionTest extends AbstractEditorTest {
public void testDeleteLineBeforeGuardedBlock() {
init("\n" +
"<caret>text\n" +
"#", TestFileType.TEXT);
"#", PlainTextFileType.INSTANCE);
getEditor().getDocument().createGuardedBlock(5, 7); // "\n#"
deleteLine();
checkResultByText("\n" +
@@ -110,20 +110,20 @@ public class EditorActionTest extends AbstractEditorTest {
"bla <selection><caret>bla\n" +
"bla</selection> bla\n" +
"yyy",
TestFileType.TEXT);
PlainTextFileType.INSTANCE);
deleteLine();
checkResultByText("xxxx\n" +
"yyy<caret>");
}
public void testIndentWhitespaceLineWithCaretAtLineStart() {
init("<caret> ", TestFileType.TEXT);
init("<caret> ", PlainTextFileType.INSTANCE);
executeAction("EditorIndentLineOrSelection");
checkResultByText(" <caret> ");
}
public void testBackspaceWithStickySelection() {
init("te<caret>xt", TestFileType.TEXT);
init("te<caret>xt", PlainTextFileType.INSTANCE);
executeAction(IdeActions.ACTION_EDITOR_TOGGLE_STICKY_SELECTION);
executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT);
executeAction(IdeActions.ACTION_EDITOR_BACKSPACE);
@@ -132,21 +132,21 @@ public class EditorActionTest extends AbstractEditorTest {
}
public void testMoveRightAtFoldedLineEnd() {
init("line1<caret>\nline2\nline3", TestFileType.TEXT);
init("line1<caret>\nline2\nline3", PlainTextFileType.INSTANCE);
addCollapsedFoldRegion(5, 7, "...");
executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT);
assertEquals(new VisualPosition(0, 6), getEditor().getCaretModel().getVisualPosition());
}
public void testEnterOnLastLineInOverwriteMode() {
init("text<caret>", TestFileType.TEXT);
init("text<caret>", PlainTextFileType.INSTANCE);
executeAction(IdeActions.ACTION_EDITOR_TOGGLE_OVERWRITE_MODE);
executeAction(IdeActions.ACTION_EDITOR_ENTER);
checkResultByText("text\n<caret>");
}
public void testPasteInOneLineMode() {
init("", TestFileType.TEXT);
init("", PlainTextFileType.INSTANCE);
((EditorEx)getEditor()).setOneLineMode(true);
CopyPasteManager.getInstance().setContents(new StringSelection("a\rb"));
executeAction(IdeActions.ACTION_EDITOR_PASTE);
@@ -270,7 +270,7 @@ public class EditorActionTest extends AbstractEditorTest {
}
public void testToggleCaseForEszett() {
init("<selection>\u00df</selection>", TestFileType.TEXT);
init("<selection>\u00df</selection>", PlainTextFileType.INSTANCE);
executeAction(IdeActions.ACTION_EDITOR_TOGGLE_CASE);
checkResultByText("<selection>SS</selection>");
}
@@ -20,11 +20,12 @@ import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.impl.view.FontLayoutService;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
import com.intellij.testFramework.MockFontLayoutService;
import com.intellij.testFramework.TestFileType;
import com.intellij.testFramework.fixtures.EditorMouseFixture;
import com.intellij.util.PathUtil;
import com.intellij.util.ThrowableRunnable;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -77,18 +78,24 @@ public abstract class AbstractEditorTest extends LightPlatformCodeInsightTestCas
}
protected void initText(@NotNull @NonNls String fileText) {
init(fileText, TestFileType.TEXT);
init(fileText, PlainTextFileType.INSTANCE);
}
protected void init(@NotNull @NonNls String fileText, @NotNull TestFileType type) {
configureFromFileText(getFileName(type), fileText);
protected void init(@NotNull @NonNls String fileText, @NotNull FileType type) {
String name = getFileName(type);
assertFileTypeResolved(type, name);
configureFromFileText(name, fileText);
}
private String getFileName(TestFileType type) {
String name = getTestName(false) + type.getExtension();
private String getFileName(@NotNull FileType type) {
return getTestName(false) + "."+type.getDefaultExtension();
}
protected static void assertFileTypeResolved(@NotNull FileType type, @NotNull String path) {
String name = PathUtil.getFileName(path);
FileType fileType = FileTypeManager.getInstance().getFileTypeByFileName(name);
assertEquals(type + " file type must be in this test classpath", "."+fileType.getDefaultExtension(), type.getExtension());
return name;
assertEquals(type + " file type must be in this test classpath, but only " + fileType + " was found by '" +
name + "' file name (with default extension '" + fileType.getDefaultExtension() + "')", type, fileType);
}
protected FoldRegion addFoldRegion(final int startOffset, final int endOffset, final String placeholder) {
@@ -5,7 +5,8 @@ import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.LogicalPosition;
import com.intellij.openapi.editor.VisualPosition;
import com.intellij.openapi.editor.colors.FontPreferences;
import com.intellij.testFramework.TestFileType;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import java.awt.*;
import java.util.ArrayList;
@@ -19,10 +20,10 @@ public abstract class AbstractRtlTest extends AbstractEditorTest {
private static final char BIDI_BOUNDARY_MARKER = '|';
protected void prepareText(String text) {
prepare(text, TestFileType.TEXT);
prepare(text, PlainTextFileType.INSTANCE);
}
protected void prepare(String text, TestFileType fileType) {
protected void prepare(String text, FileType fileType) {
init(text.replace(RTL_CHAR_REPRESENTATION, RTL_CHAR), fileType);
}
@@ -27,7 +27,7 @@ import com.intellij.openapi.editor.colors.impl.DelegateColorScheme;
import com.intellij.openapi.editor.colors.impl.EditorColorsManagerImpl;
import com.intellij.openapi.editor.colors.impl.FontPreferencesImpl;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.testFramework.TestFileType;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import org.jetbrains.annotations.NotNull;
import java.util.function.Consumer;
@@ -71,7 +71,7 @@ public class EditorColorsSchemeDelegateTest extends AbstractEditorTest {
FontPreferences tempCopy = new FontPreferencesImpl();
globalPrefs.copyTo(tempCopy);
try {
init("blah", TestFileType.TEXT);
init("blah", PlainTextFileType.INSTANCE);
assertInstanceOf(globalPrefs, ModifiableFontPreferences.class);
((ModifiableFontPreferences)globalPrefs).register(secondaryFont, globalPrefs.getSize(globalPrefs.getFontFamily()));
@@ -1,588 +0,0 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.editor.impl;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.editor.ex.BidiTextDirection;
import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
import com.intellij.testFramework.TestFileType;
public class EditorRtlTest extends AbstractRtlTest {
public void testPositionCalculations() {
prepareText("LLRR");
checkOffsetConversions(0, lB(0), vL(0), vR(0), xy(0));
checkOffsetConversions(1, lB(1), vL(1), vR(1), xy(10));
checkOffsetConversions(2, lB(2), vL(2), vL(4), xy(20), xy(40));
checkOffsetConversions(3, lB(3), vR(3), vL(3), xy(30));
checkOffsetConversions(4, lB(4), vR(2), vR(4), xy(20), xy(40));
checkLPConversions(0, 0, vL(0), vR(0));
checkLPConversions(1, 1, vL(1), vR(1));
checkLPConversions(2, 2, vL(2), vL(4));
checkLPConversions(3, 3, vR(3), vL(3));
checkLPConversions(4, 4, vR(2), vR(4));
checkLPConversions(5, 4, vL(5), vR(5));
checkLPConversions(lB(1, 0), 4, vL(1, 0));
checkLPConversions(lF(1, 0), 4, vR(1, 0));
checkVPConversions(vL(0), lB(0), xy(0));
checkVPConversions(vR(0), lF(0), xy(0));
checkVPConversions(vL(1), lB(1), xy(10));
checkVPConversions(vR(1), lF(1), xy(10));
checkVPConversions(vL(2), lB(2), xy(20));
checkVPConversions(vR(2), lB(4), xy(20));
checkVPConversions(vL(3), lF(3), xy(30));
checkVPConversions(vR(3), lB(3), xy(30));
checkVPConversions(vL(4), lF(2), xy(40));
checkVPConversions(vR(4), lF(4), xy(40));
checkVPConversions(vL(5), lB(5), xy(50));
checkVPConversions(vR(5), lF(5), xy(50));
checkVPConversions(vL(1, 0), lB(1, 0), xy(0, ls(10)));
checkVPConversions(vR(1, 0), lF(1, 0), xy(0, ls(10)));
checkXYConversion(xy(0), vL(0));
checkXYConversion(xy(12), vR(1));
checkXYConversion(xy(19), vL(2));
checkXYConversion(xy(21), vR(2));
checkXYConversion(xy(27), vL(3));
checkXYConversion(xy(39), vL(4));
checkXYConversion(xy(41), vR(4));
checkXYConversion(xy(51), vR(5));
}
public void testNumberInsideRtlText() {
prepareText("RR12RR");
checkOffsetConversions(0, lB(0), vL(0), vL(6), xy(0), xy(60));
checkOffsetConversions(1, lB(1), vR(5), vL(5), xy(50));
checkOffsetConversions(2, lB(2), vR(4), vR(2), xy(40), xy(20));
checkOffsetConversions(3, lB(3), vL(3), vR(3), xy(30));
checkOffsetConversions(4, lB(4), vL(4), vL(2), xy(40), xy(20));
checkOffsetConversions(5, lB(5), vR(1), vL(1), xy(10));
checkOffsetConversions(6, lB(6), vR(0), vR(6), xy(0), xy(60));
checkLPConversions(0, 0, vL(0), vL(6));
checkLPConversions(1, 1, vR(5), vL(5));
checkLPConversions(2, 2, vR(4), vR(2));
checkLPConversions(3, 3, vL(3), vR(3));
checkLPConversions(4, 4, vL(4), vL(2));
checkLPConversions(5, 5, vR(1), vL(1));
checkLPConversions(6, 6, vR(0), vR(6));
checkVPConversions(vL(0), lB(0), xy(0));
checkVPConversions(vR(0), lB(6), xy(0));
checkVPConversions(vL(1), lF(5), xy(10));
checkVPConversions(vR(1), lB(5), xy(10));
checkVPConversions(vL(2), lF(4), xy(20));
checkVPConversions(vR(2), lF(2), xy(20));
checkVPConversions(vL(3), lB(3), xy(30));
checkVPConversions(vR(3), lF(3), xy(30));
checkVPConversions(vL(4), lB(4), xy(40));
checkVPConversions(vR(4), lB(2), xy(40));
checkVPConversions(vL(5), lF(1), xy(50));
checkVPConversions(vR(5), lB(1), xy(50));
checkVPConversions(vL(6), lF(0), xy(60));
checkVPConversions(vR(6), lF(6), xy(60));
checkXYConversion(xy(1), vR(0));
checkXYConversion(xy(9), vL(1));
checkXYConversion(xy(19), vL(2));
checkXYConversion(xy(21), vR(2));
checkXYConversion(xy(30), vL(3));
checkXYConversion(xy(39), vL(4));
checkXYConversion(xy(41), vR(4));
checkXYConversion(xy(50), vL(5));
checkXYConversion(xy(59), vL(6));
checkXYConversion(xy(61), vR(6));
}
public void testFolding() {
prepareText("RRRRRR");
addCollapsedFoldRegion(2, 4, "...");
checkOffsetConversions(0, lB(0), vL(0), vL(2), xy(0), xy(20));
checkOffsetConversions(1, lB(1), vR(1), vL(1), xy(10));
checkOffsetConversions(2, lB(2), vR(0), vR(2), xy(0), xy(20));
checkOffsetConversions(3, lB(3), vR(2), vR(2), xy(20));
checkOffsetConversions(4, lB(4), vL(5), vL(7), xy(50), xy(70));
checkOffsetConversions(5, lB(5), vR(6), vL(6), xy(60));
checkOffsetConversions(6, lB(6), vR(5), vR(7), xy(50), xy(70));
checkLPConversions(0, 0, vL(0), vL(2));
checkLPConversions(1, 1, vR(1), vL(1));
checkLPConversions(2, 2, vR(0), vR(2));
checkLPConversions(3, 3, vR(2), vR(2));
checkLPConversions(4, 4, vL(5), vL(7));
checkLPConversions(5, 5, vR(6), vL(6));
checkLPConversions(6, 6, vR(5), vR(7));
checkLPConversions(7, 6, vL(8), vR(8));
checkVPConversions(vL(0), lB(0), xy(0));
checkVPConversions(vR(0), lB(2), xy(0));
checkVPConversions(vL(1), lF(1), xy(10));
checkVPConversions(vR(1), lB(1), xy(10));
checkVPConversions(vL(2), lF(0), xy(20));
checkVPConversions(vR(2), lF(2), xy(20));
checkVPConversions(vL(3), lF(2), xy(30));
checkVPConversions(vR(3), lF(2), xy(30));
checkVPConversions(vL(4), lF(2), xy(40));
checkVPConversions(vR(4), lF(2), xy(40));
checkVPConversions(vL(5), lB(4), xy(50));
checkVPConversions(vR(5), lB(6), xy(50));
checkVPConversions(vL(6), lF(5), xy(60));
checkVPConversions(vR(6), lB(5), xy(60));
checkVPConversions(vL(7), lF(4), xy(70));
checkVPConversions(vR(7), lF(6), xy(70));
checkVPConversions(vL(8), lB(7), xy(80));
checkVPConversions(vR(8), lF(7), xy(80));
checkXYConversion(xy(1), vR(0));
checkXYConversion(xy(9), vL(1));
checkXYConversion(xy(19), vL(2));
checkXYConversion(xy(21), vR(2));
checkXYConversion(xy(30), vL(3));
checkXYConversion(xy(39), vL(4));
checkXYConversion(xy(41), vR(4));
checkXYConversion(xy(50), vL(5));
checkXYConversion(xy(59), vL(6));
checkXYConversion(xy(69), vL(7));
checkXYConversion(xy(71), vR(7));
checkXYConversion(xy(81), vR(8));
}
public void testFoldingWhenLineContainsSeveralFragments() {
prepareText("R R");
addCollapsedFoldRegion(1, 2, "...");
checkOffsetConversions(0, lB(0), vL(0), vL(1), xy(0), xy(10));
checkOffsetConversions(1, lB(1), vR(0), vR(1), xy(0), xy(10));
checkOffsetConversions(2, lB(2), vL(4), vL(5), xy(40), xy(50));
checkOffsetConversions(3, lB(3), vR(4), vR(5), xy(40), xy(50));
}
public void testFoldingInInnerBidiRun() {
prepareText("LRRL");
addCollapsedFoldRegion(1, 2, "...");
checkLPConversions(0, 0, vL(0), vR(0));
checkLPConversions(1, 1, vL(1), vR(1));
checkLPConversions(2, 2, vL(4), vL(5));
checkLPConversions(3, 3, vR(4), vR(5));
checkLPConversions(4, 4, vL(6), vR(6));
}
public void testPositionCalculationsWithSoftWraps() {
prepareText("RR RR");
configureSoftWraps(3);
checkOffsetConversions(0, lB(0), vL(0), vL(3), xy(0), xy(30));
checkOffsetConversions(1, lB(1), vR(2), vL(2), xy(20));
checkOffsetConversions(2, lB(2), vR(1), vL(1), xy(10));
checkOffsetConversions(3, lB(3), vL(1, 1), vL(1, 3), xy(10, ls(10)), xy(30, ls(10)));
checkOffsetConversions(4, lB(4), vR(1, 2), vL(1, 2), xy(20, ls(10)));
checkOffsetConversions(5, lB(5), vR(1, 1), vR(1, 3), xy(10, ls(10)), xy(30, ls(10)));
checkOffsetConversions(6, lB(5), vR(1, 1), vR(1, 3), xy(10, ls(10)), xy(30, ls(10)));
checkLPConversions(0, 0, vL(0), vL(3));
checkLPConversions(1, 1, vR(2), vL(2));
checkLPConversions(2, 2, vR(1), vL(1));
checkLPConversions(3, 3, vL(1, 1), vL(1, 3));
checkLPConversions(4, 4, vR(1, 2), vL(1, 2));
checkLPConversions(5, 5, vR(1, 1), vR(1, 3));
checkLPConversions(6, 5, vL(1, 4), vR(1, 4));
checkLPConversions(lB(1, 0), 5, vL(2, 0));
checkLPConversions(lF(1, 0), 5, vR(2, 0));
checkLPConversions(lB(1, 1), 5, vL(2, 1));
checkLPConversions(lF(1, 1), 5, vR(2, 1));
checkVPConversions(0, lB(0), lB(3), xy(0));
checkVPConversions(1, lF(2), lB(2), xy(10));
checkVPConversions(2, lF(1), lB(1), xy(20));
checkVPConversions(3, lF(0), lF(3), xy(30));
checkVPConversions(4, lF(3), lF(3), xy(40));
checkVPConversions(5, lF(3), lF(3), xy(50));
checkVPConversions(vL(1, 0), lB(3), xy(0, ls(10)));
checkVPConversions(vR(1, 0), lB(3), xy(0, ls(10)));
checkVPConversions(vL(1, 1), lB(3), xy(10, ls(10)));
checkVPConversions(vR(1, 1), lB(5), xy(10, ls(10)));
checkVPConversions(vL(1, 2), lF(4), xy(20, ls(10)));
checkVPConversions(vR(1, 2), lB(4), xy(20, ls(10)));
checkVPConversions(vL(1, 3), lF(3), xy(30, ls(10)));
checkVPConversions(vR(1, 3), lF(5), xy(30, ls(10)));
checkVPConversions(vL(1, 4), lB(6), xy(40, ls(10)));
checkVPConversions(vR(1, 4), lF(6), xy(40, ls(10)));
checkXYConversion(xy(0), vL(0));
checkXYConversion(xy(2), vR(0));
checkXYConversion(xy(9), vL(1));
checkXYConversion(xy(13), vR(1));
checkXYConversion(xy(18), vL(2));
checkXYConversion(xy(24), vR(2));
checkXYConversion(xy(30), vL(3));
checkXYConversion(xy(31), vR(3));
checkXYConversion(xy(39), vL(4));
checkXYConversion(xy(42), vR(4));
checkXYConversion(xy(47), vL(5));
checkXYConversion(xy(54), vR(5));
checkXYConversion(xy(0, ls(10)), vL(1, 0));
checkXYConversion(xy(2, ls(10)), vR(1, 0));
checkXYConversion(xy(9, ls(10)), vL(1, 1));
checkXYConversion(xy(11, ls(10)), vR(1, 1));
checkXYConversion(xy(18, ls(10)), vL(1, 2));
checkXYConversion(xy(23, ls(10)), vR(1, 2));
checkXYConversion(xy(30, ls(10)), vL(1, 3));
checkXYConversion(xy(34, ls(10)), vR(1, 3));
checkXYConversion(xy(37, ls(10)), vL(1, 4));
checkXYConversion(xy(41, ls(10)), vR(1, 4));
}
public void testSelectingRtlLineByDraggingMouseFromLeftToRight() {
prepareText("R");
setEditorVisibleSize(1000, 1000);
mouse().pressAtXY(0, 5).dragToXY(15, 5).release();
checkResult("<selection>R</selection>");
}
public void testSelectingRtlLineByDraggingMouseFromRightToLeft() {
prepareText("R");
setEditorVisibleSize(1000, 1000);
mouse().pressAtXY(15, 5).dragToXY(0, 5).release();
checkResult("<selection>R</selection>");
}
public void testMovingCaretToLogicalLineEnd() {
prepareText("R");
getEditor().getCaretModel().moveToLogicalPosition(lF(1));
assertVisualPositionsEqual("Wrong visual position", vR(1), getEditor().getCaretModel().getVisualPosition());
}
public void testMovingCaretToVisualLineEnd() {
prepareText("R");
getEditor().getCaretModel().moveToVisualPosition(vR(1));
assertLogicalPositionsEqual("Wrong logical position", lF(1), getEditor().getCaretModel().getLogicalPosition());
}
public void testNavigationWithArrowKeys() {
prepareText("LLRRLL\nLLRRLL");
assertCaretPosition(vL(0));
right();
assertCaretPosition(vL(1));
right();
assertCaretPosition(vL(2));
right();
assertCaretPosition(vR(2));
right();
assertCaretPosition(vL(3));
right();
assertCaretPosition(vL(4));
down();
assertCaretPosition(vL(1, 4));
left();
assertCaretPosition(vR(1, 3));
left();
assertCaretPosition(vR(1, 2));
up();
assertCaretPosition(vR(2));
}
public void testMovingIntoVirtualSpace() {
prepareText("R");
getEditor().getSettings().setVirtualSpace(true);
assertVisualCaretLocation(0, false);
right();
assertVisualCaretLocation(0, true);
right();
assertVisualCaretLocation(1, true);
right();
assertVisualCaretLocation(1, false);
right();
assertVisualCaretLocation(2, false);
right();
assertVisualCaretLocation(3, false);
}
public void testMovingThroughFoldedRegion() {
prepareText("RRR");
addCollapsedFoldRegion(1, 2, "..");
assertVisualCaretLocation(0, false);
right();
assertVisualCaretLocation(0, true);
right();
assertVisualCaretLocation(1, true);
right();
assertVisualCaretLocation(1, true);
right();
assertVisualCaretLocation(2, true);
right();
assertVisualCaretLocation(3, true);
right();
assertVisualCaretLocation(3, true);
right();
assertVisualCaretLocation(4, true);
}
public void testMovingCaretWhenSelectionExists() {
prepareText("RRR");
right();
right();
executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT_WITH_SELECTION);
checkResult("R<selection>R</selection>R");
right();
assertVisualCaretLocation(2, true);
}
public void testMovingCaretWhenSelectionStartsOnDirectionBoundary() {
prepareText("LR");
right();
right();
executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT_WITH_SELECTION);
right();
assertVisualCaretLocation(2, true);
}
public void testMoveCaretWithSelection() {
prepareText("LR");
executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT_WITH_SELECTION);
executeAction(IdeActions.ACTION_EDITOR_MOVE_CARET_RIGHT_WITH_SELECTION);
checkResult("<selection>LR</selection>");
}
public void testNextPrevWord() {
prepareText("LL RR RR LL");
nextWord();
assertVisualCaretLocation(2, false);
nextWord();
assertVisualCaretLocation(3, false);
nextWord();
assertVisualCaretLocation(3, true);
nextWord();
assertVisualCaretLocation(5, true);
nextWord();
assertVisualCaretLocation(8, true);
nextWord();
assertVisualCaretLocation(8, false);
nextWord();
assertVisualCaretLocation(11, false);
previousWord();
assertVisualCaretLocation(9, false);
previousWord();
assertVisualCaretLocation(8, false);
previousWord();
assertVisualCaretLocation(8, true);
previousWord();
assertVisualCaretLocation(6, true);
previousWord();
assertVisualCaretLocation(3, true);
previousWord();
assertVisualCaretLocation(3, false);
previousWord();
assertVisualCaretLocation(0, false);
}
public void testNextPrevWordWithSelection() {
prepareText("LL RR RR LL");
moveCaretToNextWordWithSelection();
checkResult("<selection>LL</selection> RR RR LL");
moveCaretToNextWordWithSelection();
checkResult("<selection>LL </selection>RR RR LL");
moveCaretToNextWordWithSelection();
checkResult("<selection>LL RR RR</selection> LL");
moveCaretToNextWordWithSelection();
checkResult("<selection>LL RR </selection>RR LL");
moveCaretToNextWordWithSelection();
checkResult("<selection>LL </selection>RR RR LL");
moveCaretToNextWordWithSelection();
checkResult("<selection>LL RR RR</selection> LL");
moveCaretToNextWordWithSelection();
checkResult("<selection>LL RR RR LL</selection>");
moveCaretToPreviousWordWithSelection();
checkResult("<selection>LL RR RR </selection>LL");
moveCaretToPreviousWordWithSelection();
checkResult("<selection>LL RR RR</selection> LL");
moveCaretToPreviousWordWithSelection();
checkResult("<selection>LL </selection>RR RR LL");
moveCaretToPreviousWordWithSelection();
checkResult("<selection>LL RR</selection> RR LL");
moveCaretToPreviousWordWithSelection();
checkResult("<selection>LL RR RR</selection> LL");
moveCaretToPreviousWordWithSelection();
checkResult("<selection>LL </selection>RR RR LL");
moveCaretToPreviousWordWithSelection();
checkResult("<caret>LL RR RR LL");
}
public void testHomeEnd() {
prepareText("RR");
getEditor().getCaretModel().moveToOffset(1);
home();
assertVisualCaretLocation(0, false);
end();
assertVisualCaretLocation(2, false);
}
public void testHomeEndWithSelection() {
prepareText("RR");
getEditor().getCaretModel().moveToOffset(1);
homeWithSelection();
assertVisualCaretLocation(0, false);
checkResult("<selection>R</selection>R");
endWithSelection();
assertVisualCaretLocation(2, false);
checkResult("R<selection>R</selection>");
}
public void testTextStartEnd() {
prepareText("RR");
getEditor().getCaretModel().moveToOffset(1);
executeAction(IdeActions.ACTION_EDITOR_TEXT_START);
assertVisualCaretLocation(0, false);
executeAction(IdeActions.ACTION_EDITOR_TEXT_END);
assertVisualCaretLocation(2, false);
}
public void testTextStartEndWithSelection() {
prepareText("RR");
getEditor().getCaretModel().moveToOffset(1);
executeAction(IdeActions.ACTION_EDITOR_TEXT_START_WITH_SELECTION);
assertVisualCaretLocation(0, false);
checkResult("<selection>R</selection>R");
executeAction(IdeActions.ACTION_EDITOR_TEXT_END_WITH_SELECTION);
assertVisualCaretLocation(2, false);
checkResult("R<selection>R</selection>");
}
public void testUsingLexerForBidiLayout() {
prepare("class Foo {\n int<caret> R = 1;\n}", TestFileType.JAVA);
right();
right();
checkResult("class Foo {\n int R<caret> = 1;\n}");
}
public void testJavadocTokensAreMergedForBidiLayoutPurposes() {
prepare("<caret>/**R R*/ class Foo {}", TestFileType.JAVA);
for (int i = 0; i < 4; i++) {
right();
}
checkResult("/**R R<caret>*/ class Foo {}");
}
public void testXmlTextIsLaidOutCorrectly() {
prepare("<caret><L>R R</L>", TestFileType.XML);
for (int i = 0; i < 4; i++) {
right();
}
checkResult("<L>R R<caret></L>");
}
public void testMovingThroughBoundaryBetweenRunsWithNonadjacentLevels() {
prepareText("R=1");
right();
assertVisualCaretLocation(0, false);
assertEquals(2, getEditor().getCaretModel().getOffset());
right();
assertVisualCaretLocation(1, false);
assertEquals(3, getEditor().getCaretModel().getOffset());
right();
assertVisualCaretLocation(1, true);
assertEquals(2, getEditor().getCaretModel().getOffset());
}
public void testMovingCaretThroughSoftWrap() {
prepareText("RR RR");
configureSoftWraps(3);
right();
assertVisualCaretLocation(0, true);
right();
assertVisualCaretLocation(1, true);
right();
assertVisualCaretLocation(2, true);
right();
assertVisualCaretLocation(3, true);
right();
assertVisualCaretLocation(3, false);
right();
assertVisualCaretLocation(1, 1, false);
right();
assertVisualCaretLocation(1, 1, true);
right();
assertVisualCaretLocation(1, 2, true);
right();
assertVisualCaretLocation(1, 3, true);
}
public void testLineGeneralDirectionAutodetection() {
prepareText("<caret>RLR");
right();
checkResult("RLR<caret>");
}
public void testTabInsideRtlText() {
prepareText("<caret>R\tRR");
right();
checkResult("R<caret>\tRR");
right();
checkResult("<caret>R\tRR");
right();
checkResult("R<caret>\tRR");
right();
checkResult("R\t<caret>RR");
right();
checkResult("R\tRR<caret>");
right();
checkResult("R\tR<caret>R");
right();
checkResult("R\t<caret>RR");
right();
checkResult("R\tRR<caret>");
}
public void testEscapedBackslashInStringLiteral() {
prepare("class C {\n String s = \"R\\<caret>\\R\";\n}", TestFileType.JAVA);
right();
right();
checkResult("class C {\n String s = \"<caret>R\\\\R\";\n}");
}
public void testRtlLayoutPersistsAfterEditing() {
prepare("<caret>\nRR", TestFileType.TEXT);
delete();
checkResult("<caret>RR");
assertTrue(getEditor().getCaretModel().getPrimaryCaret().isAtBidiRunBoundary());
}
public void testTokenOrderIsAlwaysLtr() {
BidiTextDirection savedValue = EditorSettingsExternalizable.getInstance().getBidiTextDirection();
try {
EditorSettingsExternalizable.getInstance().setBidiTextDirection(BidiTextDirection.RTL);
prepare("<a>R</a>", TestFileType.XML);
right();
checkResult("<<caret>a>R</a>");
}
finally {
EditorSettingsExternalizable.getInstance().setBidiTextDirection(savedValue);
}
}
public void testLineCommentLayout() {
prepare("<caret>// R", TestFileType.JAVA);
right();
checkResult("/<caret>/ R");
}
public void testIndentIsTreatedSeparately() {
checkBidiRunBoundaries(" |R", "txt");
}
public void testCaretMovementAroundTab() {
prepareText("R<caret>R\t");
left();
checkResult("RR<caret>\t");
assertVisualCaretLocation(0, true);
}
}
@@ -7,9 +7,9 @@ import com.intellij.openapi.diagnostic.DefaultLogger;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.ex.FoldingListener;
import com.intellij.openapi.editor.ex.FoldingModelEx;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.TextRange;
import com.intellij.testFramework.TestFileType;
import com.intellij.util.DocumentUtil;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
@@ -33,7 +33,7 @@ public class FoldingTest extends AbstractEditorTest {
"When I use a word,\" Humpty Dumpty said, in a rather scornful tone, \"it means just what I choose it to mean -- neither more nor less." +
"The question is,\" said Alice, \"whether you can make words mean so many different things." +
"The question is,\" said Humpty Dumpty, \"which is to be master -- that's all.",
TestFileType.TEXT);
PlainTextFileType.INSTANCE);
myModel = (FoldingModelEx)getEditor().getFoldingModel();
}
@@ -1,82 +1,15 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.editor.impl;
import com.intellij.ide.ui.AntialiasingType;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.EditorColorsUtil;
import com.intellij.openapi.editor.impl.view.FontLayoutService;
import com.intellij.openapi.editor.markup.HighlighterLayer;
import com.intellij.openapi.editor.markup.HighlighterTargetArea;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.rt.execution.junit.FileComparisonFailure;
import com.intellij.testFramework.TestFileType;
import com.intellij.ui.JBColor;
import com.intellij.util.ui.ImageUtil;
import org.jetbrains.annotations.NotNull;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
/**
* @author Pavel Fatin
*/
public class ImmediatePainterTest extends AbstractEditorTest {
private String myDefaultFontName;
private int myDefaultFontSize;
private float myDefaultLineSpacing;
private Color myDefaultCaretColor;
private KeyboardFocusManager myDefaultFocusManager;
private AntialiasingType myDefaultAntiAliasing;
@Override
protected void setUp() throws Exception {
super.setUp();
EditorColorsScheme defaultColorScheme = getDefaultColorScheme();
myDefaultFontName = defaultColorScheme.getEditorFontName();
myDefaultFontSize = defaultColorScheme.getEditorFontSize();
myDefaultLineSpacing = defaultColorScheme.getLineSpacing();
myDefaultCaretColor = defaultColorScheme.getColor(EditorColors.CARET_COLOR);
myDefaultFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
myDefaultAntiAliasing = UISettings.getInstance().getEditorAAType();
FontLayoutService.setInstance(null);
setZeroLatencyRenderingEnabled(true);
setDoubleBufferingEnabled(true);
setFont(Font.MONOSPACED, 14);
setLineSpacing(1.3F);
UISettings.getInstance().setEditorAAType(AntialiasingType.GREYSCALE);
}
@Override
protected void tearDown() throws Exception {
try {
getDefaultColorScheme().setEditorFontName(myDefaultFontName);
getDefaultColorScheme().setEditorFontSize(myDefaultFontSize);
getDefaultColorScheme().setLineSpacing(myDefaultLineSpacing);
getDefaultColorScheme().setColor(EditorColors.CARET_COLOR, myDefaultCaretColor);
KeyboardFocusManager.setCurrentKeyboardFocusManager(myDefaultFocusManager);
UISettings.getInstance().setEditorAAType(myDefaultAntiAliasing);
}
catch (Throwable e) {
addSuppressedException(e);
}
finally {
super.tearDown();
}
}
public class ImmediatePainterTest extends ImmediatePainterTestCase {
public void testEmptyFile() throws Exception {
init("");
assertRenderedCorrectly(0, 'c');
@@ -107,39 +40,12 @@ public class ImmediatePainterTest extends AbstractEditorTest {
assertRenderedCorrectly(1, ' ');
}
public void testRestoringCharBeyondLineCaret() throws Exception {
init("//w", TestFileType.JS);
assertRenderedCorrectly(3, ' ');
}
public void testRestoringCharWithinBlockCaret() throws Exception {
init("//w", TestFileType.JS);
setBlockCursor(true);
assertRenderedCorrectly(3, ' ');
}
public void testEarlierCharPreservation() throws Exception {
init("//ww", TestFileType.JS);
setBlockCursor(true);
assertRenderedCorrectly(4, ' ');
}
public void testCaretRow() throws Exception {
init("a");
setCaretRowVisible(true);
assertRenderedCorrectly(1, 'b');
}
public void testCharSyntax() throws Exception {
init("+", TestFileType.JS);
assertRenderedCorrectly(1, '1');
}
public void testPreviousCharSyntax() throws Exception {
init("1", TestFileType.JS);
assertRenderedCorrectly(1, '+');
}
public void testHighlighterBackground() throws Exception {
init("a");
addLineHighlighter(0, 1, HighlighterLayer.ERROR, background(JBColor.GREEN));
@@ -204,138 +110,4 @@ public class ImmediatePainterTest extends AbstractEditorTest {
// assertTypedCorrectly(1, '+');
//}
protected void init(String text) {
init(text, TestFileType.TEXT);
getEditor().getSettings().setAdditionalLinesCount(0);
getEditor().getSettings().setAdditionalColumnsCount(3);
getEditor().getSettings().setCaretRowShown(false);
}
private void assertRenderedCorrectly(int offset, char c) throws IOException {
getEditor().getCaretModel().getPrimaryCaret().moveToOffset(offset);
JComponent editorComponent = getEditor().getContentComponent();
Dimension size = editorComponent.getPreferredSize();
editorComponent.setSize(size);
KeyboardFocusManager.setCurrentKeyboardFocusManager(new MockFocusManager(editorComponent));
BufferedImage image = ImageUtil.createImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = image.createGraphics();
BufferedImage immediateImage;
DataContext dataContext = ((EditorImpl)getEditor()).getDataContext();
try {
editorComponent.paint(graphics);
((EditorImpl)getEditor()).processKeyTypedImmediately(c, graphics, dataContext);
immediateImage = copy(image);
((EditorImpl)getEditor()).processKeyTypedNormally(c, dataContext);
editorComponent.paint(graphics);
}
finally {
graphics.dispose();
}
assertEqual(immediateImage, image);
}
private static BufferedImage copy(BufferedImage image) {
//noinspection UndesirableClassUsage
return new BufferedImage(image.getColorModel(),
image.copyData(null),
image.getColorModel().isAlphaPremultiplied(),
null);
}
private void assertEqual(BufferedImage actualImage, BufferedImage expectedImage) throws IOException {
if (expectedImage.getWidth() != actualImage.getWidth()) {
fail("Unexpected image width", expectedImage, actualImage);
}
if (expectedImage.getHeight() != actualImage.getHeight()) {
fail("Unexpected image height", expectedImage, actualImage);
}
for (int i = 0; i < expectedImage.getWidth(); i++) {
for (int j = 0; j < expectedImage.getHeight(); j++) {
if (expectedImage.getRGB(i, j) != actualImage.getRGB(i, j)) {
fail("Unexpected image contents", expectedImage, actualImage);
}
}
}
}
private void fail(@NotNull String message,
@NotNull BufferedImage expectedImage,
@NotNull BufferedImage actualImage) throws IOException {
File expectedImageFile = FileUtil.createTempFile(getName() + "-expected", ".png", false);
addTmpFileToKeep(expectedImageFile.toPath());
ImageIO.write(expectedImage, "png", expectedImageFile);
File actualImageFile = FileUtil.createTempFile(getName() + "-actual", ".png", false);
addTmpFileToKeep(actualImageFile.toPath());
ImageIO.write(actualImage, "png", actualImageFile);
throw new FileComparisonFailure(message,
expectedImageFile.getAbsolutePath(), actualImageFile.getAbsolutePath(),
expectedImageFile.getAbsolutePath(), actualImageFile.getAbsolutePath());
}
private RangeHighlighter addLineHighlighter(int startOffset, int endOffset, int layer, TextAttributes attributes) {
return getEditor().getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, attributes, HighlighterTargetArea.LINES_IN_RANGE);
}
private RangeHighlighter addRangeHighlighter(int startOffset, int endOffset, int layer, TextAttributes attributes) {
return getEditor().getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, attributes, HighlighterTargetArea.EXACT_RANGE);
}
private void setCaretRowVisible(boolean visible) {
getEditor().getSettings().setCaretRowShown(visible);
}
private void setLineCursorWidth(int width) {
getEditor().getSettings().setLineCursorWidth(width);
}
private static void setCaretColor(Color color) {
getDefaultColorScheme().setColor(EditorColors.CARET_COLOR, color);
}
private static void setFont(String name, int size) {
getDefaultColorScheme().setEditorFontName(name);
getDefaultColorScheme().setEditorFontSize(size);
}
private static void setLineSpacing(float lineSpacing) {
getDefaultColorScheme().setLineSpacing(lineSpacing);
}
private static EditorColorsScheme getDefaultColorScheme() {
return EditorColorsUtil.getGlobalOrDefaultColorScheme();
}
private static void setZeroLatencyRenderingEnabled(boolean enabled) {
ImmediatePainter.ENABLED.setValue(enabled);
}
private static void setDoubleBufferingEnabled(boolean enabled) {
ImmediatePainter.DOUBLE_BUFFERING.setValue(enabled);
}
private void setBlockCursor(boolean blockCursor) {
getEditor().getSettings().setBlockCursor(blockCursor);
}
@NotNull
private static TextAttributes background(Color color) {
return new TextAttributes(null, color, null, null, Font.PLAIN);
}
@NotNull
private static TextAttributes foreground(Color color) {
return new TextAttributes(color, null, null, null, Font.PLAIN);
}
}
@@ -0,0 +1,210 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.editor.impl;
import com.intellij.ide.ui.AntialiasingType;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.EditorColorsUtil;
import com.intellij.openapi.editor.impl.view.FontLayoutService;
import com.intellij.openapi.editor.markup.HighlighterTargetArea;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.rt.execution.junit.FileComparisonFailure;
import com.intellij.util.ui.ImageUtil;
import org.jetbrains.annotations.NotNull;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public abstract class ImmediatePainterTestCase extends AbstractEditorTest {
private String myDefaultFontName;
private int myDefaultFontSize;
private float myDefaultLineSpacing;
private Color myDefaultCaretColor;
private KeyboardFocusManager myDefaultFocusManager;
private AntialiasingType myDefaultAntiAliasing;
@Override
protected void setUp() throws Exception {
super.setUp();
EditorColorsScheme defaultColorScheme = getDefaultColorScheme();
myDefaultFontName = defaultColorScheme.getEditorFontName();
myDefaultFontSize = defaultColorScheme.getEditorFontSize();
myDefaultLineSpacing = defaultColorScheme.getLineSpacing();
myDefaultCaretColor = defaultColorScheme.getColor(EditorColors.CARET_COLOR);
myDefaultFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
myDefaultAntiAliasing = UISettings.getInstance().getEditorAAType();
FontLayoutService.setInstance(null);
setZeroLatencyRenderingEnabled(true);
setDoubleBufferingEnabled(true);
setFont(Font.MONOSPACED, 14);
setLineSpacing(1.3F);
UISettings.getInstance().setEditorAAType(AntialiasingType.GREYSCALE);
}
@Override
protected void tearDown() throws Exception {
try {
getDefaultColorScheme().setEditorFontName(myDefaultFontName);
getDefaultColorScheme().setEditorFontSize(myDefaultFontSize);
getDefaultColorScheme().setLineSpacing(myDefaultLineSpacing);
getDefaultColorScheme().setColor(EditorColors.CARET_COLOR, myDefaultCaretColor);
KeyboardFocusManager.setCurrentKeyboardFocusManager(myDefaultFocusManager);
UISettings.getInstance().setEditorAAType(myDefaultAntiAliasing);
}
catch (Throwable e) {
addSuppressedException(e);
}
finally {
super.tearDown();
}
}
protected void assertRenderedCorrectly(int offset, char c) throws IOException {
Editor editor = getEditor();
editor.getCaretModel().getPrimaryCaret().moveToOffset(offset);
JComponent editorComponent = editor.getContentComponent();
Dimension size = editorComponent.getPreferredSize();
editorComponent.setSize(size);
KeyboardFocusManager.setCurrentKeyboardFocusManager(new MockFocusManager(editorComponent));
BufferedImage image = ImageUtil.createImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics = image.createGraphics();
BufferedImage immediateImage;
DataContext dataContext = ((EditorImpl)editor).getDataContext();
try {
editorComponent.paint(graphics);
((EditorImpl)editor).processKeyTypedImmediately(c, graphics, dataContext);
immediateImage = copy(image);
((EditorImpl)editor).processKeyTypedNormally(c, dataContext);
editorComponent.paint(graphics);
}
finally {
graphics.dispose();
}
assertEqual(immediateImage, image);
}
protected void assertEqual(BufferedImage actualImage, BufferedImage expectedImage) throws IOException {
if (expectedImage.getWidth() != actualImage.getWidth()) {
fail("Unexpected image width", expectedImage, actualImage);
}
if (expectedImage.getHeight() != actualImage.getHeight()) {
fail("Unexpected image height", expectedImage, actualImage);
}
for (int i = 0; i < expectedImage.getWidth(); i++) {
for (int j = 0; j < expectedImage.getHeight(); j++) {
if (expectedImage.getRGB(i, j) != actualImage.getRGB(i, j)) {
fail("Unexpected image contents", expectedImage, actualImage);
}
}
}
}
private void fail(@NotNull String message,
@NotNull BufferedImage expectedImage,
@NotNull BufferedImage actualImage) throws IOException {
File expectedImageFile = FileUtil.createTempFile(getName() + "-expected", ".png", false);
addTmpFileToKeep(expectedImageFile.toPath());
ImageIO.write(expectedImage, "png", expectedImageFile);
File actualImageFile = FileUtil.createTempFile(getName() + "-actual", ".png", false);
addTmpFileToKeep(actualImageFile.toPath());
ImageIO.write(actualImage, "png", actualImageFile);
throw new FileComparisonFailure(message,
expectedImageFile.getAbsolutePath(), actualImageFile.getAbsolutePath(),
expectedImageFile.getAbsolutePath(), actualImageFile.getAbsolutePath());
}
private static BufferedImage copy(BufferedImage image) {
//noinspection UndesirableClassUsage
return new BufferedImage(image.getColorModel(),
image.copyData(null),
image.getColorModel().isAlphaPremultiplied(),
null);
}
protected void init(String text) {
init(text, PlainTextFileType.INSTANCE);
getEditor().getSettings().setAdditionalLinesCount(0);
getEditor().getSettings().setAdditionalColumnsCount(3);
getEditor().getSettings().setCaretRowShown(false);
}
protected RangeHighlighter addLineHighlighter(int startOffset, int endOffset, int layer, TextAttributes attributes) {
return getEditor().getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, attributes, HighlighterTargetArea.LINES_IN_RANGE);
}
protected RangeHighlighter addRangeHighlighter(int startOffset, int endOffset, int layer, TextAttributes attributes) {
return getEditor().getMarkupModel().addRangeHighlighter(startOffset, endOffset, layer, attributes, HighlighterTargetArea.EXACT_RANGE);
}
protected void setCaretRowVisible(boolean visible) {
getEditor().getSettings().setCaretRowShown(visible);
}
protected void setLineCursorWidth(int width) {
getEditor().getSettings().setLineCursorWidth(width);
}
protected static void setCaretColor(Color color) {
getDefaultColorScheme().setColor(EditorColors.CARET_COLOR, color);
}
protected static void setFont(String name, int size) {
getDefaultColorScheme().setEditorFontName(name);
getDefaultColorScheme().setEditorFontSize(size);
}
protected static void setLineSpacing(float lineSpacing) {
getDefaultColorScheme().setLineSpacing(lineSpacing);
}
protected static EditorColorsScheme getDefaultColorScheme() {
return EditorColorsUtil.getGlobalOrDefaultColorScheme();
}
protected static void setZeroLatencyRenderingEnabled(boolean enabled) {
ImmediatePainter.ENABLED.setValue(enabled);
}
protected static void setDoubleBufferingEnabled(boolean enabled) {
ImmediatePainter.DOUBLE_BUFFERING.setValue(enabled);
}
protected void setBlockCursor(boolean blockCursor) {
getEditor().getSettings().setBlockCursor(blockCursor);
}
@NotNull
protected static TextAttributes background(Color color) {
return new TextAttributes(null, color, null, null, Font.PLAIN);
}
@NotNull
protected static TextAttributes foreground(Color color) {
return new TextAttributes(color, null, null, null, Font.PLAIN);
}
}
@@ -4,8 +4,8 @@ package com.intellij.openapi.editor.impl.softwrap;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.SoftWrap;
import com.intellij.openapi.editor.impl.AbstractEditorTest;
import com.intellij.openapi.fileTypes.PlainTextFileType;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.TestFileType;
import java.util.ArrayList;
import java.util.List;
@@ -58,7 +58,7 @@ public class SoftWrapTest extends AbstractEditorTest {
assertTrue("Missing closing fold marker tag: " + text, foldInsertPosition == 0);
cleanedText.append(text.substring(pos));
init(cleanedText.toString(), TestFileType.TEXT);
init(cleanedText.toString(), PlainTextFileType.INSTANCE);
for (MyFoldRegion region : foldRegions) {
FoldRegion r = addFoldRegion(region.startPos, region.endPos, region.placeholder);
@@ -1104,21 +1104,16 @@ public class FileEncodingTest extends HeavyPlatformTestCase implements TestDialo
public void testForcedCharsetOverridesFileEncodingProvider() throws IOException {
final String ext = "yyy";
class TestFileType extends LanguageFileType {
protected TestFileType() { super(new Language("test") {}); }
class MyForcedFileType extends LanguageFileType {
protected MyForcedFileType() { super(new Language("test") {}); }
@Override public @NotNull String getName() { return "Test"; }
@Override public @NotNull String getDescription() { return "Test"; }
@Override public @NotNull String getDefaultExtension() { return ext; }
@Override public @Nullable Icon getIcon() { return null; }
@Override public String getCharset(@NotNull VirtualFile file, byte @NotNull [] content) { return StandardCharsets.ISO_8859_1.name(); }
}
TestFileType fileType = new TestFileType();
FileEncodingProvider encodingProvider = new FileEncodingProvider() {
@Override
public Charset getEncoding(@NotNull VirtualFile virtualFile) {
return StandardCharsets.UTF_16;
}
};
MyForcedFileType fileType = new MyForcedFileType();
FileEncodingProvider encodingProvider = __ -> StandardCharsets.UTF_16;
FileEncodingProvider.EP_NAME.getPoint().registerExtension(encodingProvider, getTestRootDisposable());
FileTypeManagerImpl fileTypeManager = (FileTypeManagerImpl)FileTypeManagerEx.getInstanceEx();
fileTypeManager.registerFileType(fileType, List.of(new ExtensionFileNameMatcher(ext)), getTestRootDisposable());
@@ -1128,12 +1123,7 @@ public class FileEncodingTest extends HeavyPlatformTestCase implements TestDialo
}
public void testDetectedCharsetOverridesFileEncodingProvider() throws IOException {
FileEncodingProvider encodingProvider = new FileEncodingProvider() {
@Override
public Charset getEncoding(@NotNull VirtualFile virtualFile) {
return WINDOWS_1251;
}
};
FileEncodingProvider encodingProvider = __ -> WINDOWS_1251;
FileEncodingProvider.EP_NAME.getPoint().registerExtension(encodingProvider, getTestRootDisposable());
VirtualFile file = createTempFile("yyy", NO_BOM, "Some text" + THREE_RUSSIAN_LETTERS, StandardCharsets.UTF_8);
assertEquals(StandardCharsets.UTF_8, file.getCharset());
@@ -1,36 +0,0 @@
/*
* Copyright 2000-2010 JetBrains s.r.o.
*
* 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 com.intellij.testFramework;
/**
* Encapsulates information about target test file type in order to reduce possibility of mis-typing.
*
* @author Denis Zhdanov
*/
public enum TestFileType {
JAVA("java"), SQL("sql"), TEXT("txt"), XML("xml"), HTML("html"), XHTML("xhtml"), JS("js");
private final String myExtension;
TestFileType(String extension) {
myExtension = "." + extension;
}
public String getExtension() {
return myExtension;
}
}
@@ -16,7 +16,7 @@
package com.intellij.codeInsight.editorActions.moveLeftRight;
import com.intellij.codeInsight.editorActions.AbstractMoveElementLeftRightTest;
import com.intellij.testFramework.TestFileType;
import com.intellij.ide.highlighter.XmlFileType;
public class XmlMoveLeftRightTest extends AbstractMoveElementLeftRightTest {
public void testMoveAttributes() throws Exception {
@@ -26,6 +26,6 @@ public class XmlMoveLeftRightTest extends AbstractMoveElementLeftRightTest {
@Override
protected void configureEditor(String contents) {
init(contents, TestFileType.XML);
init(contents, XmlFileType.INSTANCE);
}
}