Commit c18d9d10 authored by Dmitry Batrak's avatar Dmitry Batrak
Browse files

added some inlays-related tests

parent 0b62cd12
Showing with 136 additions and 0 deletions
+136 -0
/*
* Copyright 2000-2016 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.openapi.editor.impl;
import com.intellij.testFramework.EditorTestUtil;
public class EditorInlayTest extends AbstractEditorTest {
public void testCaretMovement() throws Exception {
initText("ab");
addInlay(1);
right();
checkCaretPosition(1, 1, 1);
right();
checkCaretPosition(1, 1, 2);
right();
checkCaretPosition(2, 2, 3);
left();
checkCaretPosition(1, 1, 2);
left();
checkCaretPosition(1, 1, 1);
left();
checkCaretPosition(0, 0, 0);
}
public void testFoldedInlay() throws Exception {
initText("abc");
addInlay(1);
addCollapsedFoldRegion(1, 2, ".");
right();
checkCaretPosition(1, 1, 1);
right();
checkCaretPosition(2, 2, 2);
}
public void testCaretMovementWithSelection() throws Exception {
initText("ab");
addInlay(1);
rightWithSelection();
checkCaretPositionAndSelection(1, 1, 1, 0, 1);
rightWithSelection();
checkCaretPositionAndSelection(2, 2, 3, 0, 2);
leftWithSelection();
checkCaretPositionAndSelection(1, 1, 1, 0, 1);
leftWithSelection();
checkCaretPositionAndSelection(0, 0, 0, 0, 0);
myEditor.getCaretModel().moveToOffset(2);
leftWithSelection();
checkCaretPositionAndSelection(1, 1, 2, 1, 2);
leftWithSelection();
checkCaretPositionAndSelection(0, 0, 0, 0, 2);
rightWithSelection();
checkCaretPositionAndSelection(1, 1, 2, 1, 2);
rightWithSelection();
checkCaretPositionAndSelection(2, 2, 3, 2, 2);
}
public void testBackspace() throws Exception {
initText("ab<caret>c");
addInlay(1);
backspace();
checkResultByText("ac");
checkCaretPosition(1, 1, 2);
backspace();
checkResultByText("ac");
checkCaretPosition(1, 1, 1);
backspace();
checkResultByText("c");
checkCaretPosition(0, 0, 0);
}
public void testDelete() throws Exception {
initText("a<caret>bc");
addInlay(2);
delete();
checkResultByText("ac");
checkCaretPosition(1, 1, 1);
delete();
checkResultByText("ac");
checkCaretPosition(1, 1, 2);
delete();
checkResultByText("a");
checkCaretPosition(1, 1, 2);
}
private static void checkCaretPositionAndSelection(int offset, int logicalColumn, int visualColumn,
int selectionStartOffset, int selectionEndOffset) {
checkCaretPosition(offset, logicalColumn, visualColumn);
assertEquals(selectionStartOffset, myEditor.getSelectionModel().getSelectionStart());
assertEquals(selectionEndOffset, myEditor.getSelectionModel().getSelectionEnd());
}
private static void checkCaretPosition(int offset, int logicalColumn, int visualColumn) {
assertEquals(offset, myEditor.getCaretModel().getOffset());
assertEquals(0, myEditor.getCaretModel().getLogicalPosition().line);
assertEquals(logicalColumn, myEditor.getCaretModel().getLogicalPosition().column);
assertEquals(0, myEditor.getCaretModel().getVisualPosition().line);
assertEquals(visualColumn, myEditor.getCaretModel().getVisualPosition().column);
}
private static void addInlay(int offset) {
EditorTestUtil.addInlay(myEditor, offset);
}
}
......@@ -455,6 +455,17 @@ public class EditorTestUtil {
return ref.get();
}
public static void addInlay(@NotNull Editor editor, int offset) {
editor.getInlayModel().addInlineElement(offset, new EditorCustomElementRenderer() {
@Override
public int calcWidthInPixels(@NotNull Editor editor) { return 1; }
@Override
public void paint(@NotNull Editor editor, @NotNull Graphics g, @NotNull Rectangle r) {}
});
}
public static class CaretAndSelectionState {
public final List<CaretInfo> carets;
public final TextRange blockSelection;
......
......@@ -604,6 +604,14 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
executeAction("EditorRight");
}
protected static void leftWithSelection() {
executeAction("EditorLeftWithSelection");
}
protected static void rightWithSelection() {
executeAction("EditorRightWithSelection");
}
protected static void up() {
executeAction("EditorUp");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment