diff --git a/spellchecker/src/com/intellij/spellchecker/quickfixes/ChangeTo.java b/spellchecker/src/com/intellij/spellchecker/quickfixes/ChangeTo.java index 82114b1c0fad..bb3b222b25b6 100644 --- a/spellchecker/src/com/intellij/spellchecker/quickfixes/ChangeTo.java +++ b/spellchecker/src/com/intellij/spellchecker/quickfixes/ChangeTo.java @@ -35,10 +35,16 @@ import java.util.List; public class ChangeTo extends ShowSuggestions implements SpellCheckerQuickFix { + public static final String FIX_NAME = "ChangeTo"; + public ChangeTo(String wordWithTypo) { super(wordWithTypo); } + @NotNull + public String getName() { + return FIX_NAME; + } @NotNull public String getFamilyName() { diff --git a/spellchecker/testData/inspection/quickfixes/emptyChangeTo.txt b/spellchecker/testData/inspection/quickfixes/emptyChangeTo.txt new file mode 100644 index 000000000000..81389d508410 --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/emptyChangeTo.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/joinedWordsChangeTo.after.txt b/spellchecker/testData/inspection/quickfixes/joinedWordsChangeTo.after.txt new file mode 100644 index 000000000000..97151ec9e1f8 --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/joinedWordsChangeTo.after.txt @@ -0,0 +1 @@ +someСorrectWordsAndTypo \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/joinedWordsChangeTo.txt b/spellchecker/testData/inspection/quickfixes/joinedWordsChangeTo.txt new file mode 100644 index 000000000000..76ba58645bf6 --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/joinedWordsChangeTo.txt @@ -0,0 +1 @@ +someСorrectWordsAndTyyypo \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/noTypoChangeTo.txt b/spellchecker/testData/inspection/quickfixes/noTypoChangeTo.txt new file mode 100644 index 000000000000..98e05bc5062f --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/noTypoChangeTo.txt @@ -0,0 +1 @@ +typo \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/severalJoinedTyposChangeTo.after.txt b/spellchecker/testData/inspection/quickfixes/severalJoinedTyposChangeTo.after.txt new file mode 100644 index 000000000000..891c2b1828da --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/severalJoinedTyposChangeTo.after.txt @@ -0,0 +1 @@ +SoomeTypoJooinedTogeether \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/severalJoinedTyposChangeTo.txt b/spellchecker/testData/inspection/quickfixes/severalJoinedTyposChangeTo.txt new file mode 100644 index 000000000000..13fd8f59d781 --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/severalJoinedTyposChangeTo.txt @@ -0,0 +1 @@ +SoomeTyyypoJooinedTogeether \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/severalWordsChangeTo.after.txt b/spellchecker/testData/inspection/quickfixes/severalWordsChangeTo.after.txt new file mode 100644 index 000000000000..4e8c63ecc10a --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/severalWordsChangeTo.after.txt @@ -0,0 +1 @@ +some correct words and typo \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/severalWordsChangeTo.txt b/spellchecker/testData/inspection/quickfixes/severalWordsChangeTo.txt new file mode 100644 index 000000000000..a623a3d49f02 --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/severalWordsChangeTo.txt @@ -0,0 +1 @@ +some correct words and tyyypo \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/simpleWordChangeTo.after.txt b/spellchecker/testData/inspection/quickfixes/simpleWordChangeTo.after.txt new file mode 100644 index 000000000000..8b5c0517abc8 --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/simpleWordChangeTo.after.txt @@ -0,0 +1 @@ +typo \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/simpleWordChangeTo.txt b/spellchecker/testData/inspection/quickfixes/simpleWordChangeTo.txt new file mode 100644 index 000000000000..212ad9a82783 --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/simpleWordChangeTo.txt @@ -0,0 +1 @@ +tyyypo \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/typoInsideJoinedWordsChangeTo.after.txt b/spellchecker/testData/inspection/quickfixes/typoInsideJoinedWordsChangeTo.after.txt new file mode 100644 index 000000000000..d718102a5279 --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/typoInsideJoinedWordsChangeTo.after.txt @@ -0,0 +1 @@ +someTypoAndСorrectWords \ No newline at end of file diff --git a/spellchecker/testData/inspection/quickfixes/typoInsideJoinedWordsChangeTo.txt b/spellchecker/testData/inspection/quickfixes/typoInsideJoinedWordsChangeTo.txt new file mode 100644 index 000000000000..9c9da8c1efa0 --- /dev/null +++ b/spellchecker/testData/inspection/quickfixes/typoInsideJoinedWordsChangeTo.txt @@ -0,0 +1 @@ +someTyyypoAndСorrectWords \ No newline at end of file diff --git a/spellchecker/testSrc/com/intellij/spellchecker/inspection/SpellcheckerInspectionTestCase.java b/spellchecker/testSrc/com/intellij/spellchecker/inspection/SpellcheckerInspectionTestCase.java index 0203a80ea17c..87497fb435e2 100644 --- a/spellchecker/testSrc/com/intellij/spellchecker/inspection/SpellcheckerInspectionTestCase.java +++ b/spellchecker/testSrc/com/intellij/spellchecker/inspection/SpellcheckerInspectionTestCase.java @@ -25,7 +25,7 @@ public abstract class SpellcheckerInspectionTestCase extends LightPlatformCodeIn return true; } - static String getSpellcheckerTestDataPath() { + public static String getSpellcheckerTestDataPath() { return "/spellchecker/testData/"; } diff --git a/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/AbstractSpellCheckerFixesTest.java b/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/AbstractSpellCheckerFixesTest.java new file mode 100644 index 000000000000..f8e6b433706f --- /dev/null +++ b/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/AbstractSpellCheckerFixesTest.java @@ -0,0 +1,72 @@ +/* + * 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.spellchecker.inspection.quickfixes; + +import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.codeInsight.lookup.Lookup; +import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.codeInsight.lookup.LookupManager; +import com.intellij.codeInsight.lookup.impl.LookupImpl; +import com.intellij.spellchecker.inspection.SpellcheckerInspectionTestCase; +import com.intellij.spellchecker.inspections.SpellCheckingInspection; +import com.intellij.spellchecker.quickfixes.ChangeTo; + + +import java.io.File; + +public abstract class AbstractSpellCheckerFixesTest extends SpellcheckerInspectionTestCase { + protected abstract String getExtension(); + + @Override + protected String getBasePath() { + return getSpellcheckerTestDataPath() + "inspection" + File.separator + "quickfixes"; + } + + private void doChangeToTest(int toSelect) { + myFixture.configureByFile(getBeforeFile()); + myFixture.enableInspections(SpellCheckingInspection.class); + final IntentionAction intention = myFixture.findSingleIntention(ChangeTo.FIX_NAME); + assertNotNull("cannot find quick fix", intention); + myFixture.launchAction(intention); + selectLookupElement(toSelect); + myFixture.checkResultByFile(getResultFile()); + } + + private void selectLookupElement(int i) { + final LookupElement[] elements = myFixture.getLookupElements(); + final LookupImpl lookup = (LookupImpl)LookupManager.getInstance(getProject()).getActiveLookup(); + lookup.setCurrentItem(elements[i]); + lookup.finishLookup(Lookup.NORMAL_SELECT_CHAR); + } + + protected void doNoQuickFixTest(String quickfix) { + myFixture.configureByFile(getBeforeFile()); + myFixture.enableInspections(SpellCheckingInspection.class); + assertNull(myFixture.getAvailableIntention(quickfix)); + } + + protected void doChangeToTest() { + doChangeToTest(0); + } + + private String getResultFile() { + return getTestName(true) + ".after" + getExtension(); + } + + private String getBeforeFile() { + return getTestDataPath() + File.separator + getTestName(true) + getExtension(); + } +} diff --git a/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/PlainTextSpellCheckerFixesTest.java b/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/PlainTextSpellCheckerFixesTest.java new file mode 100644 index 000000000000..ab6ba5385056 --- /dev/null +++ b/spellchecker/testSrc/com/intellij/spellchecker/inspection/quickfixes/PlainTextSpellCheckerFixesTest.java @@ -0,0 +1,52 @@ +/* + * 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.spellchecker.inspection.quickfixes; + +import com.intellij.spellchecker.quickfixes.ChangeTo; + +public class PlainTextSpellCheckerFixesTest extends AbstractSpellCheckerFixesTest { + protected String getExtension() { + return ".txt"; + } + + public void testSimpleWordChangeTo() { + doChangeToTest(); + } + + public void testSeveralWordsChangeTo() { + doChangeToTest(); + } + + public void testJoinedWordsChangeTo() { + doChangeToTest(); + } + + public void testTypoInsideJoinedWordsChangeTo() { + doChangeToTest(); + } + + public void testSeveralJoinedTyposChangeTo() { + doChangeToTest(); + } + + public void testNoTypoChangeTo() { + doNoQuickFixTest(ChangeTo.FIX_NAME); + } + + public void testEmptyChangeTo() { + doNoQuickFixTest(ChangeTo.FIX_NAME); + } +}