Search in sources :

Example 1 with LineSet

use of com.intellij.openapi.editor.impl.LineSet in project intellij-community by JetBrains.

the class TabPostFormatProcessorTest method doDocumentTest.

private void doDocumentTest(@NotNull String initial, @NotNull String expected, boolean useTabs, boolean smartTabs, int tabWidth) {
    Pair<String, TextRange> pair = parse(initial);
    final StringBuilder text = new StringBuilder(pair.first);
    final TextRange range = pair.second;
    myMockery.checking(new Expectations() {

        {
            allowing(myDocument).getCharsSequence();
            will(returnValue(text.toString()));
            allowing(myDocument).getTextLength();
            will(returnValue(text.length()));
        }
    });
    final LineSet lines = LineSet.createLineSet(myDocument.getCharsSequence());
    myMockery.checking(new Expectations() {

        {
            allowing(myDocument).getLineNumber(with(any(int.class)));
            will(new CustomAction("getLineNumber()") {

                @Override
                public Object invoke(Invocation invocation) throws Throwable {
                    return lines.findLineIndex((Integer) invocation.getParameter(0));
                }
            });
            allowing(myDocument).getLineStartOffset(with(any(int.class)));
            will(new CustomAction("getLineStartOffset()") {

                @Override
                public Object invoke(Invocation invocation) throws Throwable {
                    return lines.getLineStart((Integer) invocation.getParameter(0));
                }
            });
            allowing(myDocument).getLineEndOffset(with(any(int.class)));
            will(new CustomAction("getLineEndOffset()") {

                @Override
                public Object invoke(Invocation invocation) throws Throwable {
                    return lines.getLineEnd((Integer) invocation.getParameter(0));
                }
            });
            allowing(myDocument).replaceString(with(any(int.class)), with(any(int.class)), with(any(String.class)));
            will(new CustomAction("replaceString") {

                @Nullable
                @Override
                public Object invoke(Invocation invocation) throws Throwable {
                    int start = (Integer) invocation.getParameter(0);
                    int end = (Integer) invocation.getParameter(1);
                    String newText = (String) invocation.getParameter(2);
                    text.replace(start, end, newText);
                    return null;
                }
            });
        }
    });
    TabPostFormatProcessor.processViaDocument(myDocument, range, useTabs, smartTabs, tabWidth);
    assertEquals(expected, text.toString());
}
Also used : Expectations(org.jmock.Expectations) Invocation(org.jmock.api.Invocation) CustomAction(org.jmock.lib.action.CustomAction) TextRange(com.intellij.openapi.util.TextRange) LineSet(com.intellij.openapi.editor.impl.LineSet)

Aggregations

LineSet (com.intellij.openapi.editor.impl.LineSet)1 TextRange (com.intellij.openapi.util.TextRange)1 Expectations (org.jmock.Expectations)1 Invocation (org.jmock.api.Invocation)1 CustomAction (org.jmock.lib.action.CustomAction)1