Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
c18d9d10
Commit
c18d9d10
authored
8 years ago
by
Dmitry Batrak
Browse files
Options
Download
Email Patches
Plain Diff
added some inlays-related tests
parent
0b62cd12
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorInlayTest.java
+117
-0
...Src/com/intellij/openapi/editor/impl/EditorInlayTest.java
platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java
+11
-0
...mework/src/com/intellij/testFramework/EditorTestUtil.java
platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java
+8
-0
...ellij/testFramework/LightPlatformCodeInsightTestCase.java
with
136 additions
and
0 deletions
+136
-0
platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/EditorInlayTest.java
0 → 100644
+
117
-
0
View file @
c18d9d10
/*
* 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
);
}
}
This diff is collapsed.
Click to expand it.
platform/testFramework/src/com/intellij/testFramework/EditorTestUtil.java
+
11
-
0
View file @
c18d9d10
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
platform/testFramework/src/com/intellij/testFramework/LightPlatformCodeInsightTestCase.java
+
8
-
0
View file @
c18d9d10
...
...
@@ -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"
);
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help