diff options
Diffstat (limited to 'platform/platform-tests')
10 files changed, 429 insertions, 56 deletions
diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorMultiCaretTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorMultiCaretTest.java index 26be81d2f341..fdaf7c6ed5b0 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorMultiCaretTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/EditorMultiCaretTest.java @@ -245,6 +245,38 @@ public class EditorMultiCaretTest extends AbstractEditorTest { "seven<caret>"); } + public void testCopyMultilineFromOneCaretPasteIntoTwo() throws Exception { + init("<selection>one\n" + + "two<caret></selection>\n" + + "three\n" + + "four", + TestFileType.TEXT); + executeAction("EditorCopy"); + executeAction("EditorTextStart"); + executeAction("EditorCloneCaretBelow"); + executeAction("EditorPaste"); + checkResultByText("one\n" + + "two<caret>one\n" + + "one\n" + + "two<caret>two\n" + + "three\n" + + "four"); + } + + public void testCopyPasteDoesNothingWithUnevenSelection() throws Exception { + init("<selection>one\n" + + "two<caret></selection>\n" + + "<selection>three<caret></selection>\n" + + "four", + TestFileType.TEXT); + executeAction("EditorCopy"); + executeAction("EditorPaste"); + checkResultByText("one\n" + + "two<caret>\n" + + "three<caret>\n" + + "four"); + } + public void testEscapeAfterDragDown() throws Exception { init("line1\n" + "line2", diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorActionTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorActionTest.java index deb63c13abf8..20bfdaced5e8 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorActionTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/EditorActionTest.java @@ -102,4 +102,15 @@ public class EditorActionTest extends AbstractEditorTest { deleteLine(); checkResultByText(""); } + + public void testDeleteLineHonorSelection() throws Exception { + init("xxxx\n" + + "bla <selection><caret>bla\n" + + "bla</selection> bla\n" + + "yyy", + TestFileType.TEXT); + deleteLine(); + checkResultByText("xxxx\n" + + "yyy<caret>"); + } }
\ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java index 34a08c0483bb..c1cc85768aed 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/actions/SelectUnselectOccurrenceActionsTest.java @@ -194,6 +194,63 @@ public class SelectUnselectOccurrenceActionsTest extends LightPlatformCodeInsigh "another line"); } + public void testSelectingAdjacentFragments() throws Exception { + init("fragment<selection>fragment<caret></selection>"); + executeAction(); + executeAction(); + checkResult("<selection>fragment<caret></selection><selection>fragment<caret></selection>"); + } + + public void testSkippingOccurrence() throws Exception { + init("fr<caret>uit\n" + + "fruits\n" + + "fruit\n" + + "fruits\n" + + "fruit"); + executeAction(); + executeAction(); + executeFindNext(); + checkResult("<selection>fr<caret>uit</selection>\n" + + "fruits\n" + + "fruit\n" + + "fruits\n" + + "<selection>fr<caret>uit</selection>"); + } + + public void testMovingSelectionBackAndForth() throws Exception { + init("fr<caret>uit\n" + + "fruits\n" + + "fruit\n" + + "fruits\n" + + "fruit"); + executeAction(); + executeAction(); + executeFindNext(); + executeFindPrevious(); + executeAction(); + checkResult("<selection>fr<caret>uit</selection>\n" + + "fruits\n" + + "<selection>fr<caret>uit</selection>\n" + + "fruits\n" + + "<selection>fr<caret>uit</selection>"); + } + + public void testSkipDoesNotRemovePreviousSelections() throws Exception { + init("<caret>fruit\n" + + "fruit\n" + + "fruit"); + executeAction(); + executeAction(); + executeFindNext(); + executeFindNext(); + assertEquals(1, hintCount); + executeFindNext(); + assertEquals(1, hintCount); + checkResult("<selection><caret>fruit</selection>\n" + + "fruit\n" + + "<selection><caret>fruit</selection>"); + } + private void init(String text) { myFixture.configureByText(FileTypes.PLAIN_TEXT, text); } @@ -206,6 +263,14 @@ public class SelectUnselectOccurrenceActionsTest extends LightPlatformCodeInsigh myFixture.performEditorAction(IdeActions.ACTION_SELECT_NEXT_OCCURENCE); } + private void executeFindNext() { + myFixture.performEditorAction(IdeActions.ACTION_FIND_NEXT); + } + + private void executeFindPrevious() { + myFixture.performEditorAction(IdeActions.ACTION_FIND_PREVIOUS); + } + private void executeReverseAction() { myFixture.performEditorAction(IdeActions.ACTION_UNSELECT_PREVIOUS_OCCURENCE); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/CachingSoftWrapDataMapperTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/CachingSoftWrapDataMapperTest.java index 6589fb35368b..7448c6c867f6 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/CachingSoftWrapDataMapperTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/editor/impl/softwrap/mapping/CachingSoftWrapDataMapperTest.java @@ -122,6 +122,8 @@ public class CachingSoftWrapDataMapperTest { final Project project = myMockery.mock(Project.class); final SoftWrapPainter painter = myMockery.mock(SoftWrapPainter.class); + myRepresentationHelper = new MockEditorTextRepresentationHelper(SPACE_SIZE, TAB_SIZE); + myMockery.checking(new Expectations() {{ // Document allowing(myEditor).getDocument();will(returnValue(myDocument)); @@ -165,6 +167,7 @@ public class CachingSoftWrapDataMapperTest { return getSoftWrap((Integer)invocation.getParameter(0)); } }); + allowing(mySoftWrapModel).getEditorTextRepresentationHelper(); will(returnValue(myRepresentationHelper)); // Folding. allowing(myEditor).getFoldingModel();will(returnValue(myFoldingModel)); @@ -220,9 +223,7 @@ public class CachingSoftWrapDataMapperTest { allowing(painter).getMinDrawingWidth(SoftWrapDrawingType.AFTER_SOFT_WRAP); will(returnValue(SOFT_WRAP_DRAWING_WIDTH)); }}); - myRepresentationHelper = new MockEditorTextRepresentationHelper(SPACE_SIZE, TAB_SIZE); - - myMapper = new CachingSoftWrapDataMapper(myEditor, myStorage, myRepresentationHelper); + myMapper = new CachingSoftWrapDataMapper(myEditor, myStorage); } @After @@ -699,7 +700,7 @@ public class CachingSoftWrapDataMapperTest { int foldingStartVisualColumn; TestEditorPosition() { - super(myEditor, myRepresentationHelper); + super(myEditor); lineStartPosition = clone(); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/FileEditorManagerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/FileEditorManagerTest.java index db9cebf954f6..9695bf8529fb 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/FileEditorManagerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileEditor/FileEditorManagerTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -17,6 +17,7 @@ package com.intellij.openapi.fileEditor; import com.intellij.ide.ui.UISettings; import com.intellij.mock.Mock; +import com.intellij.openapi.fileEditor.impl.EditorWindow; import com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; @@ -101,6 +102,20 @@ public class FileEditorManagerTest extends FileEditorManagerTestCase { assertEquals("mockEditor", myManager.getSelectedEditor(file).getName()); } + public void testWindowClosingRetainsOtherWindows() throws Exception { + VirtualFile file = getFile("/src/1.txt"); + assertNotNull(file); + myManager.openFile(file, false); + EditorWindow primaryWindow = myManager.getCurrentWindow(); + assertNotNull(primaryWindow); + myManager.createSplitter(SwingConstants.VERTICAL, primaryWindow); + EditorWindow secondaryWindow = myManager.getNextWindow(primaryWindow); + assertNotNull(secondaryWindow); + myManager.createSplitter(SwingConstants.VERTICAL, secondaryWindow); + myManager.closeFile(file, primaryWindow); + assertEquals(2, myManager.getWindows().length); + } + private static final String STRING = "<component name=\"FileEditorManager\">\n" + " <leaf>\n" + " <file leaf-file-name=\"1.txt\" pinned=\"false\" current=\"false\" current-in-tab=\"false\">\n" + diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/keymap/impl/ModifierKeyDoubleClickHandlerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/keymap/impl/ModifierKeyDoubleClickHandlerTest.java new file mode 100644 index 000000000000..490aa294974d --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/openapi/keymap/impl/ModifierKeyDoubleClickHandlerTest.java @@ -0,0 +1,169 @@ +/* + * Copyright 2000-2014 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.keymap.impl; + +import com.intellij.ide.IdeEventQueue; +import com.intellij.openapi.actionSystem.ActionManager; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.KeyboardShortcut; +import com.intellij.openapi.keymap.KeymapManager; +import com.intellij.openapi.util.Clock; +import com.intellij.testFramework.LightPlatformTestCase; + +import javax.swing.*; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; + +public class ModifierKeyDoubleClickHandlerTest extends LightPlatformTestCase { + private static final String MY_SHIFT_SHIFT_ACTION = "ModifierKeyDoubleClickHandlerTest.action1"; + private static final String MY_SHIFT_KEY_ACTION = "ModifierKeyDoubleClickHandlerTest.action2"; + private static final String MY_SHIFT_SHIFT_KEY_ACTION = "ModifierKeyDoubleClickHandlerTest.action3"; + + public static final KeyboardShortcut SHIFT_KEY_SHORTCUT = new KeyboardShortcut(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, + InputEvent.SHIFT_MASK), + null); + + private final JComponent myComponent = new JPanel(); + + private long myCurrentTime; + private int myShiftShiftActionInvocationCount; + private int myShiftKeyActionInvocationCount; + private int myShiftShiftKeyActionInvocationCount; + + @Override + public void setUp() throws Exception { + super.setUp(); + Clock.setTime(0); + ActionManager.getInstance().registerAction(MY_SHIFT_SHIFT_ACTION, new AnAction() { + @Override + public void actionPerformed(AnActionEvent e) { + myShiftShiftActionInvocationCount++; + } + }); + ActionManager.getInstance().registerAction(MY_SHIFT_KEY_ACTION, new AnAction() { + @Override + public void actionPerformed(AnActionEvent e) { + myShiftKeyActionInvocationCount++; + } + }); + ActionManager.getInstance().registerAction(MY_SHIFT_SHIFT_KEY_ACTION, new AnAction() { + @Override + public void actionPerformed(AnActionEvent e) { + myShiftShiftKeyActionInvocationCount++; + } + }); + KeymapManager.getInstance().getActiveKeymap().addShortcut(MY_SHIFT_KEY_ACTION, SHIFT_KEY_SHORTCUT); + ModifierKeyDoubleClickHandler.getInstance().registerAction(MY_SHIFT_SHIFT_ACTION, KeyEvent.VK_SHIFT, -1); + ModifierKeyDoubleClickHandler.getInstance().registerAction(MY_SHIFT_SHIFT_KEY_ACTION, KeyEvent.VK_SHIFT, KeyEvent.VK_BACK_SPACE); + } + + @Override + public void tearDown() throws Exception { + ModifierKeyDoubleClickHandler.getInstance().unregisterAction(MY_SHIFT_SHIFT_KEY_ACTION); + ModifierKeyDoubleClickHandler.getInstance().unregisterAction(MY_SHIFT_SHIFT_ACTION); + KeymapManager.getInstance().getActiveKeymap().removeShortcut(MY_SHIFT_KEY_ACTION, SHIFT_KEY_SHORTCUT); + ActionManager.getInstance().unregisterAction(MY_SHIFT_SHIFT_KEY_ACTION); + ActionManager.getInstance().unregisterAction(MY_SHIFT_KEY_ACTION); + ActionManager.getInstance().unregisterAction(MY_SHIFT_SHIFT_ACTION); + Clock.reset(); + super.tearDown(); + } + + public void testShiftShiftSuccessfulCase() { + press(); + release(); + press(); + assertInvocationCounts(0, 0, 0); + release(); + assertInvocationCounts(0, 1, 0); + } + + public void testLongSecondClick() { + press(); + release(); + press(); + timeStep(400); + release(); + assertInvocationCounts(0, 0, 0); + } + + public void testShiftShiftKeySuccessfulCase() { + press(); + release(); + press(); + key(); + assertInvocationCounts(0, 0, 1); + release(); + assertInvocationCounts(0, 0, 1); + } + + public void testShiftKey() { + press(); + key(); + assertInvocationCounts(1, 0, 0); + release(); + } + + public void assertInvocationCounts(int shiftKeyCount, int shiftShiftCount, int shiftShiftKeyCount) { + assertEquals(shiftKeyCount, myShiftKeyActionInvocationCount); + assertEquals(shiftShiftCount, myShiftShiftActionInvocationCount); + assertEquals(shiftShiftKeyCount, myShiftShiftKeyActionInvocationCount); + } + + private void press() { + IdeEventQueue.getInstance().dispatchEvent(new KeyEvent(myComponent, + KeyEvent.KEY_PRESSED, + Clock.getTime(), + InputEvent.SHIFT_MASK, + KeyEvent.VK_SHIFT, + KeyEvent.CHAR_UNDEFINED)); + } + + private void release() { + IdeEventQueue.getInstance().dispatchEvent(new KeyEvent(myComponent, + KeyEvent.KEY_RELEASED, + Clock.getTime(), + 0, + KeyEvent.VK_SHIFT, + KeyEvent.CHAR_UNDEFINED)); + } + + private void key() { + IdeEventQueue.getInstance().dispatchEvent(new KeyEvent(myComponent, + KeyEvent.KEY_PRESSED, + Clock.getTime(), + InputEvent.SHIFT_MASK, + KeyEvent.VK_BACK_SPACE, + '\b')); + IdeEventQueue.getInstance().dispatchEvent(new KeyEvent(myComponent, + KeyEvent.KEY_TYPED, + Clock.getTime(), + InputEvent.SHIFT_MASK, + 0, + '\b')); + IdeEventQueue.getInstance().dispatchEvent(new KeyEvent(myComponent, + KeyEvent.KEY_RELEASED, + Clock.getTime(), + InputEvent.SHIFT_MASK, + KeyEvent.VK_BACK_SPACE, + '\b')); + } + + private void timeStep(long step) { + Clock.setTime(myCurrentTime += step); + } +} diff --git a/platform/platform-tests/testSrc/com/intellij/patterns/StandardPatternsTest.java b/platform/platform-tests/testSrc/com/intellij/patterns/StandardPatternsTest.java index 1e05add24302..1db3f319b250 100644 --- a/platform/platform-tests/testSrc/com/intellij/patterns/StandardPatternsTest.java +++ b/platform/platform-tests/testSrc/com/intellij/patterns/StandardPatternsTest.java @@ -1,11 +1,23 @@ /* - * Copyright (c) 2000-2007 JetBrains s.r.o. All Rights Reserved. + * Copyright 2000-2014 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.patterns; import com.intellij.openapi.util.Key; -import com.intellij.testFramework.UsefulTestCase; import com.intellij.util.ProcessingContext; +import junit.framework.TestCase; import java.util.Arrays; @@ -14,37 +26,15 @@ import static com.intellij.patterns.StandardPatterns.*; /** * @author peter */ -public class StandardPatternsTest extends UsefulTestCase { +public class StandardPatternsTest extends TestCase { - public void testNull() throws Throwable { + public void testNull() { assertTrue(object().isNull().accepts(null)); assertFalse(object().isNull().accepts("")); assertFalse(string().isNull().accepts("")); assertTrue(string().isNull().accepts(null)); } - public void testString() throws Throwable { - final ElementPattern pattern = string(); - assertFalse(string().accepts(new Object())); - assertTrue(pattern.accepts("")); - } - - public void testStartsWith() throws Throwable { - final ElementPattern pattern = string().startsWith("abc"); - assertFalse(pattern.accepts("")); - assertTrue(pattern.accepts("abcd")); - assertTrue(pattern.accepts("abc")); - - assertFalse(string().startsWith("abc").accepts(new Object())); - } - - public void testEndsWith() throws Throwable { - final ElementPattern pattern = string().endsWith("abc"); - assertFalse(pattern.accepts("")); - assertFalse(pattern.accepts("abcd")); - assertTrue(pattern.accepts("abc")); - } - private static void checkPrefixSuffix(final ElementPattern pattern) { assertFalse(pattern.accepts("")); assertFalse(pattern.accepts("abcd")); @@ -53,23 +43,23 @@ public class StandardPatternsTest extends UsefulTestCase { assertFalse(pattern.accepts("abcdab")); } - public void testPrefixSuffix() throws Throwable { + public void testPrefixSuffix() { checkPrefixSuffix(string().endsWith("abc").startsWith("abc")); } - public void testAnd1() throws Throwable { + public void testAnd1() { checkPrefixSuffix(and(string().endsWith("abc"), string().startsWith("abc"))); } - public void testAnd2() throws Throwable { + public void testAnd2() { checkPrefixSuffix(string().endsWith("abc").and(string().startsWith("abc"))); } - public void testOr1() throws Throwable { + public void testOr1() { checkOr(or(string().endsWith("abc"), string().startsWith("abc"))); } - public void testNot1() throws Throwable { + public void testNot1() { final ElementPattern pattern = not(or(string().endsWith("abc"), string().startsWith("abc"))); assertTrue(pattern.accepts("")); assertTrue(pattern.accepts("xxx")); @@ -90,7 +80,7 @@ public class StandardPatternsTest extends UsefulTestCase { assertTrue(filterFactory.accepts("abcdab")); } - public void testEquals() throws Throwable { + public void testEquals() { final Object foo = new Object(); final Object bar = new Object(); ElementPattern objectPattern = object().equalTo(foo); @@ -103,15 +93,14 @@ public class StandardPatternsTest extends UsefulTestCase { } - - public void testAll() throws Throwable { + public void testAll() { ElementPattern pattern = collection(String.class).all(string().startsWith("abc")); assertTrue(pattern.accepts(Arrays.asList("abc"))); assertTrue(pattern.accepts(Arrays.asList("abc", "abcd"))); assertFalse(pattern.accepts(Arrays.asList("abc", "bcd"))); } - public void testAtLeastOne() throws Throwable { + public void testAtLeastOne() { ElementPattern pattern = collection(String.class).atLeastOne(string().startsWith("abc")); assertTrue(pattern.accepts(Arrays.asList("abc"))); assertTrue(pattern.accepts(Arrays.asList("abc", "abcd"))); @@ -120,15 +109,16 @@ public class StandardPatternsTest extends UsefulTestCase { assertTrue(pattern.accepts(Arrays.asList("bc", "abc"))); } - public void testFilter() throws Throwable { - ElementPattern pattern = collection(String.class).filter(string().endsWith("x"), collection(String.class).all(string().startsWith("abc"))); + public void testFilter() { + ElementPattern pattern = + collection(String.class).filter(string().endsWith("x"), collection(String.class).all(string().startsWith("abc"))); assertTrue(pattern.accepts(Arrays.asList("abc"))); assertTrue(pattern.accepts(Arrays.asList("abc", "abcd"))); assertFalse(pattern.accepts(Arrays.asList("bcx", "bcd"))); assertTrue(pattern.accepts(Arrays.asList("abcx", "abc"))); } - public void testFirst() throws Throwable { + public void testFirst() { ElementPattern pattern = collection(String.class).first(string().startsWith("abc")); assertFalse(pattern.accepts(Arrays.<String>asList())); assertTrue(pattern.accepts(Arrays.asList("abc"))); @@ -138,7 +128,7 @@ public class StandardPatternsTest extends UsefulTestCase { assertFalse(pattern.accepts(Arrays.asList("bc", "abc"))); } - public void testLast() throws Throwable { + public void testLast() { //collection(String.class) ElementPattern pattern = collection(String.class).last(string().startsWith("abc")); @@ -150,7 +140,7 @@ public class StandardPatternsTest extends UsefulTestCase { assertTrue(pattern.accepts(Arrays.asList("bc", "abc"))); } - public void testSize() throws Throwable { + public void testSize() { final CollectionPattern<String> filter = collection(String.class); assertTrue(filter.size(0).accepts(Arrays.<String>asList())); assertFalse(filter.size(0).accepts(Arrays.asList("abc"))); @@ -165,7 +155,7 @@ public class StandardPatternsTest extends UsefulTestCase { assertTrue(filter.size(2).accepts(Arrays.asList("abc", "abc"))); } - public void testEmpty() throws Throwable { + public void testEmpty() { final CollectionPattern<String> filter = collection(String.class); assertTrue(filter.empty().accepts(Arrays.<String>asList())); assertFalse(filter.empty().accepts(Arrays.asList("abc"))); @@ -176,7 +166,7 @@ public class StandardPatternsTest extends UsefulTestCase { assertTrue(not(filter.empty()).accepts(Arrays.asList("abc", "abc"))); } - public void testSave() throws Throwable { + public void testSave() { Key<String> key = Key.create("abc"); final ProcessingContext context = new ProcessingContext(); assertFalse(string().contains("abc").save(key).accepts(null)); @@ -189,6 +179,4 @@ public class StandardPatternsTest extends UsefulTestCase { assertTrue(string().contains("abc").save(key).accepts(s, context)); assertSame(s, context.get(key)); } - - } diff --git a/platform/platform-tests/testSrc/com/intellij/patterns/StringPatternTest.java b/platform/platform-tests/testSrc/com/intellij/patterns/StringPatternTest.java new file mode 100644 index 000000000000..11a6eac867df --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/patterns/StringPatternTest.java @@ -0,0 +1,92 @@ +/* + * Copyright 2000-2014 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.patterns; + +import junit.framework.TestCase; + +import static com.intellij.patterns.StandardPatterns.string; + +public class StringPatternTest extends TestCase { + + public void testString() { + final ElementPattern pattern = string(); + assertFalse(string().accepts(new Object())); + assertTrue(pattern.accepts("")); + } + + public void testStartsWith() { + final ElementPattern pattern = string().startsWith("abc"); + assertFalse(pattern.accepts("")); + assertTrue(pattern.accepts("abcd")); + assertTrue(pattern.accepts("abc")); + + assertFalse(string().startsWith("abc").accepts(new Object())); + } + + public void testEndsWith() { + final ElementPattern pattern = string().endsWith("abc"); + assertFalse(pattern.accepts("")); + assertFalse(pattern.accepts("abcd")); + assertTrue(pattern.accepts("abc")); + } + + public void testLongerThan() { + final ElementPattern pattern = string().longerThan(2); + assertFalse(pattern.accepts("")); + assertFalse(pattern.accepts("01")); + assertTrue(pattern.accepts("012")); + } + + public void testShorterThan() { + final ElementPattern pattern = string().shorterThan(2); + assertTrue(pattern.accepts("")); + assertTrue(pattern.accepts("1")); + assertFalse(pattern.accepts("12")); + } + + public void testWithLength() { + final ElementPattern pattern = string().withLength(2); + assertFalse(pattern.accepts("")); + assertFalse(pattern.accepts("1")); + assertTrue(pattern.accepts("12")); + } + + public void testContains() { + final ElementPattern pattern = string().contains("abc"); + assertFalse(pattern.accepts("")); + assertFalse(pattern.accepts("acb")); + assertFalse(pattern.accepts("ABC")); + assertTrue(pattern.accepts("01abcd")); + } + + public void testContainsChars() { + final ElementPattern pattern = string().containsChars("abc"); + assertFalse(pattern.accepts("")); + assertFalse(pattern.accepts("ABC")); + assertTrue(pattern.accepts("01a")); + assertTrue(pattern.accepts("01c")); + assertTrue(pattern.accepts("01b")); + } + + public void testOneOfIgnoreCase() { + final ElementPattern pattern = string().oneOfIgnoreCase("a", "B"); + assertFalse(pattern.accepts("")); + assertFalse(pattern.accepts("ab")); + assertFalse(pattern.accepts("d01x")); + assertTrue(pattern.accepts("A")); + assertTrue(pattern.accepts("b")); + } +} diff --git a/platform/platform-tests/testSrc/com/intellij/psi/PsiDocumentManagerImplTest.java b/platform/platform-tests/testSrc/com/intellij/psi/PsiDocumentManagerImplTest.java index 718ee8ebe5f7..2ab0446e86a4 100644 --- a/platform/platform-tests/testSrc/com/intellij/psi/PsiDocumentManagerImplTest.java +++ b/platform/platform-tests/testSrc/com/intellij/psi/PsiDocumentManagerImplTest.java @@ -75,7 +75,7 @@ public class PsiDocumentManagerImplTest extends PlatformLangTestCase { } public void testDocumentGced() throws Exception { - VirtualFile vFile = createFile(); + VirtualFile vFile = getVirtualFile(createTempFile("txt", "abc")); PsiDocumentManagerImpl documentManager = getPsiDocumentManager(); long id = System.identityHashCode(documentManager.getDocument(getPsiManager().findFile(vFile))); @@ -93,7 +93,7 @@ public class PsiDocumentManagerImplTest extends PlatformLangTestCase { }); //Class.forName("com.intellij.util.ProfilingUtil").getDeclaredMethod("forceCaptureMemorySnapshot").invoke(null); - for (int i=0;i<1000;i++) { + for (int i = 0; i < 1000; i++) { PlatformTestUtil.tryGcSoftlyReachableObjects(); UIUtil.dispatchAllInvocationEvents(); if (documentManager.getCachedDocument(getPsiManager().findFile(vFile)) == null) break; diff --git a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java index 085afbf5c126..3fcc42baa645 100644 --- a/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java +++ b/platform/platform-tests/testSrc/com/intellij/usages/impl/UsageViewTest.java @@ -26,7 +26,7 @@ import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.impl.source.PsiFileImpl; import com.intellij.testFramework.LeakHunter; -import com.intellij.testFramework.LightPlatformCodeInsightTestCase; +import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; import com.intellij.usageView.UsageInfo; import com.intellij.usages.*; import com.intellij.util.ui.UIUtil; @@ -34,9 +34,9 @@ import com.intellij.util.ui.UIUtil; /** * User: cdr */ -public class UsageViewTest extends LightPlatformCodeInsightTestCase{ +public class UsageViewTest extends LightPlatformCodeInsightFixtureTestCase { public void testUsageViewDoesNotHoldPsiFilesOrDocuments() throws Exception { - PsiFile psiFile = createFile("X.java", "public class X{} //iuggjhfg"); + PsiFile psiFile = myFixture.addFileToProject("X.java", "public class X{} //iuggjhfg"); Usage[] usages = new Usage[100]; for (int i = 0; i < usages.length; i++) { usages[i] = createUsage(psiFile,i); @@ -55,7 +55,7 @@ public class UsageViewTest extends LightPlatformCodeInsightTestCase{ } public void testUsageViewHandlesDocumentChange() throws Exception { - PsiFile psiFile = createFile("X.java", "public class X{ int xxx; } //comment"); + PsiFile psiFile = myFixture.addFileToProject("X.java", "public class X{ int xxx; } //comment"); Usage usage = createUsage(psiFile, psiFile.getText().indexOf("xxx")); UsageView usageView = UsageViewManager.getInstance(getProject()).createUsageView(UsageTarget.EMPTY_ARRAY, new Usage[]{usage}, new UsageViewPresentation(), null); @@ -69,7 +69,7 @@ public class UsageViewTest extends LightPlatformCodeInsightTestCase{ assertEquals(psiFile.getText().indexOf("xxx"), navigationOffset); } public void testTextUsageInfoHandlesDocumentChange() throws Exception { - PsiFile psiFile = createFile("X.java", "public class X{ int xxx; } //comment"); + PsiFile psiFile = myFixture.addFileToProject("X.java", "public class X{ int xxx; } //comment"); Usage usage = new UsageInfo2UsageAdapter(new UsageInfo(psiFile, psiFile.getText().indexOf("xxx"), StringUtil.indexOfSubstringEnd(psiFile.getText(),"xxx"))); UsageView usageView = UsageViewManager.getInstance(getProject()).createUsageView(UsageTarget.EMPTY_ARRAY, new Usage[]{usage}, new UsageViewPresentation(), null); |